无法在 flutter 中检索保存的图像(问题只能在 iOS 上重现)
Unable to retrieve saved image in flutter (issue reproducible only on iOS)
我正在使用 SQflite 保存图像,当我从头开始重新启动应用程序时,我无法再次找到图像文件。
以下代码供您参考。
File _storedImage;
Future<void> _takePicture() async {
final imageFile = await ImagePicker.pickImage(
source: ImageSource.gallery,
maxWidth: 600,
);
if (imageFile == null) {
return;
}
setState(() {
_storedImage = imageFile;
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(imageFile.path);
final savedImage = await imageFile.copy('${appDir.path}/$fileName');
widget.onSelectImage(savedImage);
}
以下为异常详情供您参考。
════════ Exception caught by image resource service ════════════════════════════
The following FileSystemException was thrown resolving an image codec:
Cannot open file, path = '/Users/*****/Library/Developer/CoreSimulator/Devices/C561CB20-67D1-4188-996C-8B06CFB483A9/data/Containers/Data/Application/0A5D4A4F-3B4B-41E5-AFBA-B1A99C2CBFDB/Documents/image_picker_6231C3D6-D4D4-4962-861B-0792D42D2C24-78611-000007A4CC408DD4.jpg' (OS Error: No such file or directory, errno = 2)
When the exception was thrown, this was the stack
#0 _File.open.<anonymous closure> (dart:io/file_impl.dart:364:9)
(elided 13 frames from package dart:async)
Path: /Users/*****/Library/Developer/CoreSimulator/Devices/C561CB20-67D1-4188-996C-8B06CFB483A9/data/Containers/Data/Application/0A5D4A4F-3B4B-41E5-AFBA-B1A99C2CBFDB/Documents/image_picker_6231C3D6-D4D4-4962-861B-0792D42D2C24-78611-000007A4CC408DD4.jpg
Xcode更新似乎解决了这个问题!虽然很奇怪 :-P
感谢所有试图找到解决方案的人:)
我正在使用 SQflite 保存图像,当我从头开始重新启动应用程序时,我无法再次找到图像文件。
以下代码供您参考。
File _storedImage;
Future<void> _takePicture() async {
final imageFile = await ImagePicker.pickImage(
source: ImageSource.gallery,
maxWidth: 600,
);
if (imageFile == null) {
return;
}
setState(() {
_storedImage = imageFile;
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(imageFile.path);
final savedImage = await imageFile.copy('${appDir.path}/$fileName');
widget.onSelectImage(savedImage);
}
以下为异常详情供您参考。
════════ Exception caught by image resource service ════════════════════════════
The following FileSystemException was thrown resolving an image codec:
Cannot open file, path = '/Users/*****/Library/Developer/CoreSimulator/Devices/C561CB20-67D1-4188-996C-8B06CFB483A9/data/Containers/Data/Application/0A5D4A4F-3B4B-41E5-AFBA-B1A99C2CBFDB/Documents/image_picker_6231C3D6-D4D4-4962-861B-0792D42D2C24-78611-000007A4CC408DD4.jpg' (OS Error: No such file or directory, errno = 2)
When the exception was thrown, this was the stack
#0 _File.open.<anonymous closure> (dart:io/file_impl.dart:364:9)
(elided 13 frames from package dart:async)
Path: /Users/*****/Library/Developer/CoreSimulator/Devices/C561CB20-67D1-4188-996C-8B06CFB483A9/data/Containers/Data/Application/0A5D4A4F-3B4B-41E5-AFBA-B1A99C2CBFDB/Documents/image_picker_6231C3D6-D4D4-4962-861B-0792D42D2C24-78611-000007A4CC408DD4.jpg
Xcode更新似乎解决了这个问题!虽然很奇怪 :-P
感谢所有试图找到解决方案的人:)