Reputation: 559
I'm trying to create a text file in a folder where the user can see for the file explorer apps of the mobile device, preferably in Documents folder.
Here is what I've till now (consider that we have all required permissions)
final directory = Platform.isAndroid
? await getExternalStorageDirectory()
: await getApplicationDocumentsDirectory();
final filePath = '${directory!.path}/example.txt';
File file = File(filePath);
await file.create();
await file.writeAsString('Some random text content');
After that I try to find this new file on my file explorer apps, but it seems to not exists and no error logs can been seen.
If you want see an example code I wrote this PoC -> https://github.com/felipeemidio/save-local-file-poc
What I've tried so far?
file.exists()
command it'll return true
.image_gallery_saver
lib to "download" my file results on an error for trying to save a plain/text
file where should only be image/*
files.getExternalStorageDirectory(type: StorageDirectory.documents)
instead of getExternalStorageDirectory()
changes nothing.downloads_path_provider
lib does not support null-safety.'/storage/emulated/0/Documents/example.txt'
, is possible to see the file through Archives app, but will not show when you select the option to see all Documents files.Upvotes: 0
Views: 1555
Reputation: 17732
Try file path as
String filePath = '/storage/emulated/0/Downloads/example.text';
and don't forget to add permissions in manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Upvotes: 2