How to access Internal Storage of Android in Flutter

10,011

Solution 1

From Flutter sources:

  /// Examples:
  ///
  ///  * iOS: `NSDocumentsDirectory`
  ///  * Android: The AppData directory.
  static Future<Directory> getApplicationDocumentsDirectory() async {
    return new Directory((await _pathProviderProxy.ptr.applicationDocumentsDirectory()).path);

Solution 2

To get internal storage directory path: For Legacy Use these flutter plugin that provides external storage path and external public storage path, ext_storage: ^latest_ver

String path = await ExtStorage.getExternalStoragePublicDirectory(
        ExtStorage.DIRECTORY_DOWNLOADS);

Details:https://pub.dev/packages/ext_storage

external_path:^latest_ver, For NullSafety external_path is a flutter plugin that provides internal, external storage path and external public storage path,

String path=await ExternalPath.getExternalStoragePublicDirectory(
        ExternalPath.DIRECTORY_DOWNLOADS);

Details:https://pub.dev/packages/external_path

Share:
10,011
Shubhamhackz
Author by

Shubhamhackz

šŸ”­ Iā€™m currently working on few flutter projects šŸ‘Æ Iā€™m looking to collaborate on open source projects šŸ“ I regulary write articles on https://medium.com/@shubhamhackzz šŸ’¬ Ask me about flutter, dart and open source šŸŒ± Iā€™m currently learning Node.js and Express šŸ“« Through me a mail at [email protected] āš” Fun fact Google India Scholar 2018 (Android)

Updated on June 04, 2022

Comments

  • Shubhamhackz
    Shubhamhackz almost 2 years

    In android we use getFileDir() and getCacheDir() for accessing the Internal Storage. I can see that there's a path_provider plugin that I can use but I can only figure out getTemporaryDirectory() which is analogous to getCacheDir() of android. So is there any alternative way of doing what getFileDir() does in Android.

    Is there any other way to do this that I'm aware of, or I'm missing something.

  • Pete Houston
    Pete Houston over 5 years
    ah ha nice spot :D
  • Shubhamhackz
    Shubhamhackz over 5 years
    @Mosbah It isn't really same as getFileDir because it returns path data/data/your_app_package/files whereas getApplicationDocumentDirectory returns path data/data/your_app_package/flutter/app_flutter, though we can use app_flutter directory instead of files without any issue
  • uyhaW
    uyhaW over 3 years
    @Mosbah can you provide full example of your code? cause I tried your code but I neet to define _pathProviderProxy