Iam opening the camera directly when the user enters the page. It opens and Iam able to take an image and display it. But I get the error " type 'Future' is not a subtype of type 'Widget' " before the camera opens and when I close it to display the taken image instead of the camera. I know it is because Iam using an async function to open the camera and get the image file. But Iam not able to get around this error. Can someone help me with this problem?
Here is my Code in a Stateful widget:
File _imageFile;
_getLocalImage() async {
final imageFile = await ImagePicker().getImage(source: ImageSource.camera, imageQuality: 100);
if (imageFile != null) {
setState(() {
_imageFile = File(imageFile.path);
});
} else {
Navigator.of(context).pop();
}
}
@override
Widget build(BuildContext context) {
double _width = MediaQuery.of(context).size.width;
double _height = MediaQuery.of(context).size.height;
return _imageFile == null? _getLocalImage() :
Image.file(
_imageFile,
fit: BoxFit.cover,
height: _height - 20,
width: _width,
);
}