what expected have getExternalStorageDirectory() of path_provider dependency?

让人想犯罪 __ 提交于 2021-01-29 17:52:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!