Reputation: 63
File? imageFile;
ImagePicker imagePicker = ImagePicker();
Future\<File?\> getImage(ImageSource imageSource) async {
final XFile? pickedFile = await imagePicker.pickImage(source: imageSource);
if (pickedFile == null) {
return null;
}
return File(pickedFile.path);
}
// source is camera
// save to SharedPreferences
final String duplicateFilePath = await getApplicationDocumentsDirectory().then((value) =\> value.path);
final fileName = basename(file.path);
final File newImage = await file.copy('$duplicateFilePath/$fileName');
// save newImage.path
After restarting the app, when I try to load the image, I encounter the following error: The following PathNotFoundException was thrown resolving an image codec: Cannot retrieve length of file, path = '/var/mobile/Containers/Data/Application/7D7645C5-CAF6-43F5-A484-CA93872D2996/Documents/image_picker_46D51663-C51D-4DA6-B350-57C79EFAC368-3158-00000333318B1CCD.jpg' (OS Error: No such file or directory, errno = 2)
What could be the problem? this issue only ios not android
Upvotes: 1
Views: 151
Reputation: 38029
It is not a bug, it is a feature (from the Apple point of view)
This value 7D7645C5-CAF6-43F5-A484-CA93872D2996 is a unique hash for the iOS app installation.
Restarting the app from the IDE is a reinstallation. So the value changes. That's why the app cannot find the file location.
If you install from the TestFlight or the App Store the same app, then close and open the app again, the file will be in place. After deleting the app and installing again, will not.
Good luck!
Upvotes: 0