flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.02k stars 27.19k forks source link

[path_provider] "`getApplicationSupportDirectory` should not be used for user data files", is this misleading? #112419

Open interacsion opened 1 year ago

interacsion commented 1 year ago

I am developing an app (on android, but ios needs to be supported as well) and I need to save user taken images.

As I am developing on android, I was looking for path_provider methods that get the app's local storage (as that's where I need to save them, in android at least), and there seems to be two methods that return a directory in the local storage: getApplicationDocumentsDirectory and getApplicationSupportDirectory.

now, here's where I get confused:

getApplicationDocumentsDirectory returns /data/data/com.example.app/app_flutter/, which seems like an odd location to save app data; why is it in a flutter specific directory, and not a standard android location?

on the other hand, getApplicationSupportDirectory returns /data/data/com.example.app/files/, which seems much more correct, though its dart doc says Your app should not use this directory for user data files.

So, is there an explanation to the documents directory's odd location? or perhaps the support directory's doc is misleading?

danagbemava-nc commented 1 year ago

Labeling for further insight from the team

stuartmorgan commented 1 year ago

The implementation of this plugin has changed over time for Android as Android APIs it used to use were deprecated; it may be that the current mapping to underlying APIs is no longer ideal.

We can investigate whether there are better options, although any changes would need to be made carefully (likely as opt-in) to avoid data loss.

interacsion commented 1 year ago

Which API should I use then? getApplicationDocumentsDirectory, as the documentation says, even though its result on android isn't very appropriate?

Hesamedin commented 1 year ago

I use getApplicationDocumentsDirectory() on iOS and getExternalStorageDirectory() on Android.

nhannguyenandpad commented 1 month ago

I use getApplicationDocumentsDirectory() on iOS and getExternalStorageDirectory() on Android.

Can you explain what the reason for that is?