使用包
path_provider
获取下载路径
Future<String?> getDownloadPath() async {
Directory? directory;
try {
if (Platform.isIOS) {
directory = await getApplicationDocumentsDirectory();
} else {
directory = Directory('/storage/emulated/0/Download');
// Put file in global download folder, if for an unknown reason it didn't exist, we fallback
// ignore: avoid_slow_async_io
if (!await directory.exists()) directory = await getExternalStorageDirectory();
}
} catch (err, stack) {
print("Cannot get download folder path");
}
return directory?.path;
}
- 在IOS系统中,它创建了一个带有你的应用程序名称的文件夹,并将文件放在里面
- 在安卓系统上,使用
/storage/emulated/0/Download
这个目录