如何解决Flutter:图像选择器> 相机未打开
我正在尝试使用源为相机的图像选择器。我打电话给所有可能的包裹并做了所有事情,但相机仍然无法打开。它请求许可,但之后什么也没有发生。我在这里做错了什么。
class Camera extends StatefulWidget {
@override
_CameraState createState() => _CameraState();
}
class _CameraState extends State<Camera> {
File _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print('No image selected.');
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: _image == null ? Text('No image selected.') : Image.file(_image),),floatingActionButton: FloatingActionButton(
onPressed: getImage,tooltip: 'Pick Image',child: Icon(Icons.add_a_photo),);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。