问题
I have an application that i develop with flutter and i need to acces local storage. what is expected return of that code?
i use the package path_provider:^1.2.2
var directory=await getExternalStorageDirectory();
print(directory.path)
I obtains: /storage/emulated/0/Android/data/com.myapplication.application/files
while i expect to have /storage/emulated/0/.
I want to know if is not an error.
回答1:
Remove the .getAbsolutePath() and it will be fine. Environment.getExternalStoreDirectory() will give you the path to wherever the manufacture has set its external storage. https://api.dartlang.org/stable/2.4.1/dart-core/String/substring.html for trimming path as you need...
回答2:
another solution is to do like that
Directory directory = await getExternalStorageDirectory();
List<String> segment = directory.uri.pathSegments;
String rootPath = "/" + segment[0] + "/" + segment[1] + "/" + segment[2];
print(rootPath);
and you obtains /storage/emulated/0
来源:https://stackoverflow.com/questions/57800057/what-expected-have-getexternalstoragedirectory-of-path-provider-dependency