我正在 Flutter 中开发一个移动应用程序,它需要用户从图库中选择一个图像。
我正在使用 image_picker: ^0.6.7+11 这是我的代码:
if (await Permission.photos.request().isGranted) {
try {
final image =
await ImagePicker().getImage(source: ImageSource.gallery);
if (image != null) {
photo.clearData();
File _image = File(image.path);
photo.addOriginal(_image);
} else {
print('no image selected');
}
} on PlatformException catch (e) {
print('Platform exception $e');
} catch (e) {
print('Unknown error: $e');
}
}
Run Code Online (Sandbox Code Playgroud)
在 android 模拟器中,一切正常。在 iOS 模拟器中,我可以选择一个图像,但如果我尝试选择第二个图像,则应用程序会崩溃并显示“与设备的连接丢失”。打印在运行选项卡中 - 但没有错误。
问题:如何解决此问题,以便我可以返回图库并在 iOS 上根据需要多次选择不同的图像?
调试时我遇到了这个:
PlatformException(multiple_request, Cancelled by a second request, null, null)
Run Code Online (Sandbox Code Playgroud)
我已经在这里、GitHub 等上找到了尽可能多的类似问题......我有: