How to get files from external storage in Flutter?


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


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')
  .then((Directory directory) 

Answered By – Umair Mustafa

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published