I want to get all file in listview with flutter project but how to access the external folder.
I have created a folder with name ‘MyFile’ and it is created at “/storage/emulated/0/MyFile”,
but below code pointing at “/storage/emulated/0/Android/data/com.example.demo/MyFile”.
I don’t know why below code is not working
Directory externalDirectory = await getExternalStorageDirectory(); print('External Storage:$externalDirectory'); // External storage: /storage/emulated/0/Android/data/com.example.demo/MyFile
Answer
When using Flutter Official path_provider package, getExternalStorageDirectory() will always return path to /storage/emulated/0/your-package-name/files.
To get /storage/emulated/0/, you can used a Third-party package ext_storage. Below code will return your desired Directory path
var externalDirectoryPath = await ExtStorage.getExternalStorageDirectory(); print(path); // /storage/emulated/0
Now to create a Folder, you can use the below function:
//this will create a Folder in the storage/emulated/0 new Directory(externalDirectoryPath +'/YourfolderName') .create() .then((Directory directory) { print(directory.path); });;
‘