【发布时间】:2021-08-08 10:26:42
【问题描述】:
我正在使用图像选择器,我需要将图像存储在文件中以便显示。
我就是这样的
final ImagePicker _picker = ImagePicker();
PickedFile? _imageFile;
File? imageFile;
_imgFromCamera() async {
final pickedFile =
await _picker.getImage(source: ImageSource.camera, imageQuality: 50);
setState(() {
_imageFile = pickedFile;
imageFile = File(pickedFile!.path);
});
}
_imgFromGallery() async {
final pickedFile =
await _picker.getImage(source: ImageSource.gallery, imageQuality: 50);
setState(() {
_imageFile = pickedFile;
imageFile = File(pickedFile!.path);
});
}
但是当我展示这个时
Image.file(
imageFile,
width: 100,
height: 100,
fit: BoxFit.fitHeight,
)
它显示了这个错误 Flutter The argument type 'File?' can't be assigned to the parameter type 'File'。如果我从文件中删除?,那么它会显示一些空安全错误。
【问题讨论】: