While run release app.
pick image from device and during store that path during throw this error.
PlatformException(channel-error, Unable to establish connection on channel., null, null)
Here code.
Future<String> _saveToInternalStorage(XFile file) async {
String newPath = '';
try {
final directory = await getApplicationDocumentsDirectory();
newPath = '${directory.path}/${file.name}';
await file.saveTo(newPath);
} catch (e) {
print("Error accessing documents directory: $e");
}
return newPath;
}
get permission
Future<void> pickImage(ImageSource source) async {
if (/*await _requestPermission(Permission.camera) &&*/ await _requestPermission(Permission.photos) && await _requestPermission(Permission.mediaLibrary)) {
final XFile? pickedFile = await _picker.pickImage(source: source);
if (pickedFile != null) {
for (int i = 0; i < imageList.length; i++) {
if (imageList[i].path.isEmpty) {
String path = await _saveToInternalStorage(pickedFile);
imageList[i] = XFile(path);
break;
}
}
refresh();
}
} else {
print('Permissions not granted');
}
}