Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find the path provided by getApplicationDocumentsDirectory()

Tags:

flutter

dart

I tested this flutter app example: https://github.com/tensor-programming/flutter_read_write_file_and_path

But, browsing my device with a file-manager (Solid Explorer), I cannot find the file "db.txt" created by this example.

final path = await localPath;

I checked in many folders including:

  • /storage/emulated/0 (= sdcard)
  • sdcard/Android/data
  • sdcard/data

Where is this file? Should I root my device to find/see it?

What string to add after the "path" variable to reach the Download folder? Or, how to get the absolute path to the Download folder?

Device: GALAXY S8+ SM-G955F. Android 8.0. Not Rooted. Flutter beta v0.5.1. Dart 2.0.0-dev.58.0. Windows 10. Thanks and regards

like image 536
user2192870 Avatar asked Jul 19 '18 12:07

user2192870


People also ask

Where is getApplicationDocumentsDirectory?

For iOS it is NSDocumentDirectory . On Android, which is what you asked for, the directory can be found as /data/data/<package_name> and not as /data/<package_name> .

What is getApplicationDocumentsDirectory flutter?

getApplicationDocumentsDirectory function Null safety On Android, this uses the getDataDirectory API on the context. Consider using getExternalStorageDirectory instead if data is intended to be visible to the user. Throws a MissingPlatformDirectoryException if the system is unable to provide the directory.

How do you save in flutter?

Directory generalDownloadDir = Directory('/storage/emulated/0/Download'); if you write whatever file you are trying to save to that directory, it will show up in the Downloads folder in any standard file manager application, rather than just the application-specific directory that the path_provider pkg provides.


1 Answers

You can do this

final Directory extDir = await getExternalStorageDirectory();
final String dirPath = extDir.path.toString().substring(0,20);
await Directory(dirPath).create(recursive: true);
final String filePath = '$dirPath/';

You might need to edit the parameters on the second line according to your platform for Android. This will create your file, and make it accessible to your users.

like image 198
Sambit Majhi Avatar answered Sep 16 '22 18:09

Sambit Majhi