简体   繁体   English

ios 上的 flutter 下载器和路径提供程序

[英]flutter downloader and path provider on ios

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?我已经设法使 flutter 下载器和路径提供程序在 android 上工作,但它在 ios 上不起作用,说这是一个 ZC31B32364CE1ECCECEAFCD 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.对于 iOS,在获得许可后,您应该使用final externalDir = await getApplicationDocumentsDirectory() ,因为getExternalStorageDirectory()

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM