Home>
Flutter uses a real Android device to create a CSV file and attach it by email.
At that time, the csv file will be spit out to the current directory of the Android device.
It looks like this is n’t working.
When the following function is executed on Windows 10, a CSV file is generated properly.
If it is an Android device, it will not work.
E/MethodChannel # flutter_mailer (17274): Failed to handle method call
E/MethodChannel # flutter_mailer (17274): java.lang.IllegalArgumentException: Failed to find configured root that contains /sample.csv
E/MethodChannel # flutter_mailer (17274): at androidx.core.content.FileProvider $SimplePathStrategy.getUriForFile (FileProvider.java:739)
E/MethodChannel # flutter_mailer (17274): at androidx.core.content.FileProvider.getUriForFile (FileProvider.java:418)
E/MethodChannel # flutter_mailer (17274): at com.dataxad.fluttermailer.FlutterMailerPlugin.mail (FlutterMailerPlugin.java:116)
E/MethodChannel # flutter_mailer (17274): at com.dataxad.fluttermailer.FlutterMailerPlugin.onMethodCall (FlutterMailerPlugin.java:50)
E/MethodChannel # flutter_mailer (17274): at io.flutter.plugin.common.MethodChannel $IncomingMethodCallHandler.onMessage (MethodChannel.java:222)
E/MethodChannel # flutter_mailer (17274): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart (DartMessenger.java:96)
…</Code></pre>
<strong>Applicable source code</strong>
<pre><code>// Function to create a file
import 'dart: async';
import 'dart: io';
import 'package: flutter/material.dart';
import 'package: flutter_mailer/flutter_mailer.dart';
void main () =>runApp (new MyApp ());
class MyApp extends StatefulWidget {
@override
_MyAppState createState () =>new _MyAppState ();
}
class _MyAppState extends State<MyApp>{
final GlobalKey<ScaffoldState>_scafoldKey = GlobalKey<ScaffoldState>();
// Platform messages are asynchronous, so we initialize in an async method.
Future<void>send () async {
// Platform messages may fail, so we use a try/catch PlatformException.
final MailOptions mailOptions = MailOptions (
body: null,
subject: 'attach file',
recipients: [''],isHTML: true,
// bccRecipients: ['[email protected]'],
ccRecipients: [''],
attachments: [_createFile (). path],
);
String platformResponse;
try {
await FlutterMailer.send (mailOptions);
platformResponse = 'success';
} catch (error) {
platformResponse = error.toString ();
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (! mounted) return;
_scafoldKey.currentState.showSnackBar (SnackBar (
content: Text (platformResponse),
));
}
@override
Widget build (BuildContext context) {
return new MaterialApp (
theme: ThemeData (primaryColor: Colors.red),
home: new Scaffold (
key: _scafoldKey,
appBar: new AppBar (
title: const Text ('Plugin example app'),
actions:<Widget>[
IconButton (
onPressed: send,
icon: const Icon (Icons.send),)
],
),
body: SingleChildScrollView (
child: new Center (
child: Padding (
padding: const EdgeInsets.all (8.0),
child: Column (
mainAxisSize: MainAxisSize.max,
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
),
),
),
),
),
);
}
// Function to create a file
File _createFile () {
Directory current = Directory.current;
String fileName = current.path + "\ sample.csv";
print (fileName);
File file = new File (fileName);
file.writeAsString ("Hello World !!");
return file;
}
}
When you execute and press the mail button to call send, I want the attachment to have an attached file.
If i print in the function, it will be "\ sample.csv" and it is unknown whether Directory current is returned properly.
Windows10, Android version 5.1
-
Answer # 1
Related articles
- flutter platformview android error: conflicting import, imported name'flutterplugin' is ambiguous
- i want to specify the current directory when java is executed
- android - what is (context, index)? [flutter]
- android studio - how to get flutter package via github
- android studio - cannot use pagestore with flutter
- delete flutter inspector bar [android studio]
- android - mediaquery, "/ 2:what is "60"? [flutter]
- android - is it customary to make maindart? [flutter]
- android - "///"about [flutter]
- android - about "staggeredtilecount" [flutter]
- android studio - flutter can't keep state of screen transition destination
- android - [flutter] how to implement chat user specified reply function
- android emulator - when developing flutter with android studio, the problem that the disk capacity of mac runs out
- android - [unity] error "field current activity or type signature not found" occurs
- android - i want to display the values in a bar graph with flutter
- android - [flutter] i want to display admob banner ad under appbar
- android - flutter app badge implementation
- android studio - i want to integrate firebase with flutter
- python - how to make current directory the same as ipynb file location in jupyter lab
- android - [flutter] when uploading the apk, it is said that the signing key is different, and the buildgradle is not reflected e
Related questions
- android - what is servicesdart? [flutter]
- android - 'dart:ui/paintingdart': what is? [flutter]
- android - "! 】 boolean value [flutter]
- android - flutter, expanded (can create unintentional padding in gridview
- android - i want to display an application on the home screen [flutter]
- android - app does not start [flutter]
- about flag management of native apps (android, ios)
- android - automatic display of this [flutter]
- android - i can't make mathpi [angle]
- android - i want to erase the margin of material button [flutter]
Self-solved. I think that this code probably disappeared because of the scope, because the file was created in another class and the call was insufficient.
I was able to use a library called path_provider.