White/blank 在 Flutter 中关闭相机后的屏幕
White/blank screen after close camera in Flutter
我有一个小部件可以在我的应用程序上拍照,工作原理如下:
final File imageFile =
await ImagePicker.pickImage(source: ImageSource.camera).then((test) {
print('TEST $test');
return test;
});
我可以毫无错误地打开相机并拍摄照片,但是当我尝试返回或接受我拍摄的照片时,应用程序显示白屏并且控制台完全没有显示任何错误。
这在真实设备(小米 Redmi Note 8t)上失败,但它在 Android 模拟器上有效。
我唯一能看到的信息是Lost connection to device.
当我拿起相机时
修复了添加 try catch 的问题:
Future<Null> _pickImageFromCamera(BuildContext context, int index) async {
File imageFile;
try {
imageFile = await ImagePicker.pickImage(source: ImageSource.camera)
.then((picture) {
return picture; // I found this .then necessary
});
} catch (eror) {
print('error taking picture ${error.toString()}');
}
setState(() => this._imageFile = imageFile);
}
我找到了 flutter 2 的解决方案
在Android
您需要将此添加到您的清单 3(调试、主要、配置文件)
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
然后用 try catch 选择图片,像这样
Future getbehind() async {
try{
final pickedFile = await picker.getImage(source: (ImageSource.camera:ImageSource.gallery),)
.then((value) {
setState(() {
if (value != null) {
behind = File(value.path);
} else {
print('No image selected.');
}
});
});
}catch(e){
}
运行 应用处于发布模式并完成!
我有一个小部件可以在我的应用程序上拍照,工作原理如下:
final File imageFile =
await ImagePicker.pickImage(source: ImageSource.camera).then((test) {
print('TEST $test');
return test;
});
我可以毫无错误地打开相机并拍摄照片,但是当我尝试返回或接受我拍摄的照片时,应用程序显示白屏并且控制台完全没有显示任何错误。
这在真实设备(小米 Redmi Note 8t)上失败,但它在 Android 模拟器上有效。
我唯一能看到的信息是Lost connection to device.
当我拿起相机时
修复了添加 try catch 的问题:
Future<Null> _pickImageFromCamera(BuildContext context, int index) async {
File imageFile;
try {
imageFile = await ImagePicker.pickImage(source: ImageSource.camera)
.then((picture) {
return picture; // I found this .then necessary
});
} catch (eror) {
print('error taking picture ${error.toString()}');
}
setState(() => this._imageFile = imageFile);
}
我找到了 flutter 2 的解决方案
在Android
您需要将此添加到您的清单 3(调试、主要、配置文件)
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
然后用 try catch 选择图片,像这样
Future getbehind() async {
try{
final pickedFile = await picker.getImage(source: (ImageSource.camera:ImageSource.gallery),)
.then((value) {
setState(() {
if (value != null) {
behind = File(value.path);
} else {
print('No image selected.');
}
});
});
}catch(e){
}
运行 应用处于发布模式并完成!