flutter - 在 Flutter 中关闭相机后出现白屏/黑屏
问题描述
我有一个小部件可以在我的应用程序上拍照,如下所示:
final File imageFile =
await ImagePicker.pickImage(source: ImageSource.camera).then((test) {
print('TEST $test');
return test;
});
我可以毫无错误地打开相机并拍照,但是当我尝试返回或接受我拍摄的照片时,应用程序会显示白屏,并且控制台根本没有显示任何错误。
这在真实设备(小米红米 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);
}
推荐阅读
- python - 使用 Python 3 获取 base64 编码字符串的格式
- installshield - Installshield 2008 Professional - 管理员模式安装相关查询
- javascript - 是否可以在 Plotly.js 中显示带有烛台提要(高、低、打开、关闭)值的文本的单独工具提示?
- angular - 角度和 PWA
- android - 如何自定义 EXOPlayer 视频广告 UI?
- android - 链接引用失败 - 在 appcompat 中找不到样式属性“@android:attr/textColor”
- node.js - mongodb更新链接与find?
- java - log4j 2 不显示依赖日志
- java - 使用 Keycloak 登录时,Tomcat 有时会响应 403,有时不会
- sql - sql查询中的错误'未能找到从未知到文本的转换函数'