title: Flutter: PlatformException(error, Failed to find configured root that contains <path>, null)
body: <p>Quite new to Flutter so this question might sound obvious but hey… I am trying to use flutter_email_sender (<a href="https://pub.dartlang.org/packages/flutter_email_sender" rel="nofollow noreferrer">https://pub.dartlang.org/packages/flutter_email_sender</a>) package to attach a .csv file to an email. Here is my code:</p>
  <pre><code>    Future&lt;String&gt; get _localPath async {
          final directory = await getApplicationDocumentsDirectory();
  
          return directory.absolute.path;
      }
  
      Future&lt;int&gt; export(String csv) {
          final String path = await _localPath + &quot;/&quot; + file_name;
          File file = File(path);
          file.writeAsString(csv);
  
          File readFile = File(path);
          print(&quot;content: ${await readFile.readAsString()}&quot;);
          // the two lines above print the content of the file, as expected
  
          final Email email = Email(
              body: 'blah blah',
              subject: 'blah blaaaah',
              recipients: [&quot;a@a.com&quot;],
              attachmentPaths: [file.path],
          );
  
          String platformResponse;
  
          try {
              print(&quot;Trying to send email.&quot;);
              await FlutterEmailSender.send(email);
              platformResponse = 'success';
          } catch (error) {
              print(&quot;Error&quot;);
              print(error);
              platformResponse = error.toString();
          }
  
          return platformResponse;
      }
  </code></pre>
  <p>And the stack trace:</p>
  <pre><code>E/MethodChannel#flutter_email_sender( 3433): Failed to handle method call
  E/MethodChannel#flutter_email_sender( 3433): java.lang.IllegalArgumentException: Failed to find configured root that contains /data/package.name/app_flutter/fileName.csv
  E/MethodChannel#flutter_email_sender( 3433):    at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744)
  E/MethodChannel#flutter_email_sender( 3433):    at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
  E/MethodChannel#flutter_email_sender( 3433):    at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin.sendEmail(FlutterEmailSenderPlugin.kt:102)
  E/MethodChannel#flutter_email_sender( 3433):    at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin.onMethodCall(FlutterEmailSenderPlugin.kt:41)
  E/MethodChannel#flutter_email_sender( 3433):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
  E/MethodChannel#flutter_email_sender( 3433):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
  E/MethodChannel#flutter_email_sender( 3433):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:683)
  E/MethodChannel#flutter_email_sender( 3433):    at android.os.MessageQueue.nativePollOnce(Native Method)
  E/MethodChannel#flutter_email_sender( 3433):    at android.os.MessageQueue.next(MessageQueue.java:326)
  E/MethodChannel#flutter_email_sender( 3433):    at android.os.Looper.loop(Looper.java:160)
  E/MethodChannel#flutter_email_sender( 3433):    at android.app.ActivityThread.main(ActivityThread.java:6863)
  E/MethodChannel#flutter_email_sender( 3433):    at java.lang.reflect.Method.invoke(Native Method)
  E/MethodChannel#flutter_email_sender( 3433):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
  E/MethodChannel#flutter_email_sender( 3433):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  I/flutter ( 3433): Error
  I/flutter ( 3433): PlatformException(error, Failed to find configured root that contains /data/data/package.name/app_flutter/fileName.csv, null)
  </code></pre>
  <p>Note that &quot;/data&quot; appears twice in the path in the error message shown above. I have also tried to set the path manually to remove the additional one, to no avail.</p>
  <p>Thank you in advance for your help :)</p>