I have managed to make flutter downloader and the path provider work on android but it won't work on ios saying that this is a android only operation, what's wrong? here is the code:
secondaryActions: <Widget>[
IconSlideAction(
caption: 'Download',
color: Colors.green,
icon: Icons.arrow_circle_down,
onTap: () async {
final status = await Permission.storage.request();
if (status.isGranted) {
final externalDir = await getExternalStorageDirectory();
final id = await FlutterDownloader.enqueue(
url: f.url,
savedDir: externalDir.path,
showNotification: true,
openFileFromNotification: true);
} else {
toast('Permission Denied');
}
},
),
For iOS, after having permission, you should use final externalDir = await getApplicationDocumentsDirectory()
since getExternalStorageDirectory()
is not supported for iOS.
You can do an OS check:
var externalDir;
if (Platform.isIOS) { // Platform is imported from 'dart:io' package
externalDir = await getApplicationDocumentsDirectory();
} else if (Platform.isAndroid) {
externalDir = await getExternalStorageDirectory();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.