答案是获取不到的需要再加一个插件去适配ios

path_provider: ^2.0.1

可以先从pub.dev去看下集成文档 有些配置需要配置上去

 

image_gallery_saver ios获取下载路径_android

配置好后代码如下

Future<void> _save(String url, {bool share = false}) async {
//取文件后缀
String localPath = url.substring(0, url.indexOf("\?"));
//edcd6694de4555bda0ce1cf3ddd7c9ed.jpg
localPath = localPath.substring(url.lastIndexOf("/") + 1);
var response = await Dio()
.get(url, options: Options(responseType: ResponseType.bytes));
var android_result = null;
File iosPath = null;
var imageData = Uint8List.fromList(response.data);
EasyLoading.show(status: '下载中,请稍后...', dismissOnTap: true);
if (Platform.isAndroid) {
// 如果是Android 的话,直接使用image_gallery_saver就可以了
// 图片byte数据转化unit8

// 调用image_gallery_saver的saveImages方法,返回值就是图片保存后的路径
android_result = await ImageGallerySaver.saveImage(imageData,name:localPath.substring(0,localPath.indexOf(".")-1) );
// 需要去除掉file://开头。生成要使用的file

} else if (Platform.isIOS) {
// 获取手机存储
Directory applicationDir = await getApplicationDocumentsDirectory();
// 判断路径是否存在
bool isDirExist = await Directory(applicationDir.path).exists();
if (!isDirExist) Directory(applicationDir.path).create();
// 直接保存,返回的就是保存后的文件


iosPath =
await File(applicationDir.path + localPath).writeAsBytes(imageData);
}
//判断是否下载成功 下载成功可以执行分享逻辑
if (Platform.isAndroid) {
bool status = android_result['isSuccess'];
if (status) {
String filePath = android_result['filePath'];
if (filePath != null) {
filePath = filePath.replaceAll("file://", "");
}
SpUtil.putString(_downCacheKey, filePath);
setState(() {
_isDownloadPic = true;
EasyLoading.showSuccess("下载成功");

if (share) {
Share.shareFiles([filePath],
text: widget.avatarEmoticonsListsData.name);
}
});
} else {
String errorMessage = android_result['errorMessage'];
EasyLoading.showError("下载失败,原因:$errorMessage");
}
} else if (Platform.isIOS) {
if (iosPath != null) {
if (iosPath.existsSync()) {
SpUtil.putString(_downCacheKey, iosPath.path);
setState(() {
_isDownloadPic = true;
EasyLoading.showSuccess("下载成功");
if (share) {
Share.shareFiles([iosPath.path],
text: widget.avatarEmoticonsListsData.name);
}
});
}
} else {
EasyLoading.showError("保存失败。请授予保存照片权限");
}
}
}