Flutter 我创建了两种方法,一种是从Gallery拍摄图像,另一种是';Let’我们从相机上拍照,但我遇到了一些编码错误,下面是我的代码
我想在我的android项目中使用相机拍摄图像,并从图库功能中拍摄图像,并尝试如下所示,下面是我的两种方法,我知道我犯了一些错误,请帮助修复?? 第一个错误“PickedFile”类型的值无法分配给“File”类型的变量。尝试更改变量的类型,或将右侧类型强制转换为“File”Flutter 我创建了两种方法,一种是从Gallery拍摄图像,另一种是';Let’我们从相机上拍照,但我遇到了一些编码错误,下面是我的代码,flutter,dart,Flutter,Dart,我想在我的android项目中使用相机拍摄图像,并从图库功能中拍摄图像,并尝试如下所示,下面是我的两种方法,我知道我犯了一些错误,请帮助修复?? 第一个错误“PickedFile”类型的值无法分配给“File”类型的变量。尝试更改变量的类型,或将右侧类型强制转换为“File” 2nd Error, A value of type 'PickedFile' can't be assigned to a variable of type 'File'. Try changing the t
2nd Error, A value of type 'PickedFile' can't be assigned to a variable of type 'File'. Try changing the type of the variable, or casting the right-hand type to 'File'.
how to correct this error[![enter image description here][1]][1]
我创建文件_imageFile;状态小部件
//Methods to Take images from camera,
CaptureImageWithCamera()async {
Navigator.pop(context);
File imagefile=await ImagePicker().getImage(
source: ImageSource.camera,
maxHeight: 680,
maxWidth: 970,
);
setState(() {
this._imageFile=imagefile;
});
}
// here below is methoda to take images from gallery
ImageFromGallery()async {
Navigator.pop(context);
PickedFile Imagefile=await ImagePicker().getImage(
source: ImageSource.gallery,
);
setState(() {
this._imageFile=Imagefile;
});
}
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/NBTx4.png
这是他们的第一个教程:
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print('No image selected.');
}
});
}
注意他们是如何从pickedFile
创建文件的,因为pickedFile
不是文件
:
_image = File(pickedFile.path);
你也需要这样做
作为个人的旁注:你为什么不读教程?考虑到你发布这个问题并等待答案所花的时间,这会快得多。当您在编程方面取得进展时,处理此类信息将变得越来越重要,因此请尽早开始。我按照您所说的进行了更改,但仍然不起作用,我遇到了异步暂停错误,它没有告诉我任何事情。你能用你更新的代码和完整的错误信息提出一个新问题吗?