Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White/blank screen after close camera in Flutter

I have a widget to take pictures on my app working like so:

final File imageFile =
        await ImagePicker.pickImage(source: ImageSource.camera).then((test) {
      print('TEST $test');
      return test;
    });

I can open the camera without any error and also take the picture but when I try to go back or accept the picture I've taken the app displays an white screen and the console show no errors at all.

This is failing on a real device (Xiaomi Redmi Note 8t) but it works on Android Emulator.

The only message I can see is Lost connection to device. when I take the camera

like image 814
Dani Avatar asked Jan 23 '26 09:01

Dani


1 Answers

Fixed adding a 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);
  }
like image 93
Dani Avatar answered Jan 25 '26 23:01

Dani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!