cameras.isEmpty null Flutter

612

I use library image_picker: ^0.4.12 and I implement

_getImage(context, ImageSource.camera

onTap and this is the magical code

void _getImage(BuildContext context, ImageSource source){
ImagePicker.pickImage(source: source, maxWidth: 400.0).then((File image){
  setState(() {
    _imageFile = image;
  });
  Navigator.pop(context);
});
}

voila!

enter image description here enter image description here enter image description here

thanks udemy :)

Share:
612
Vanya Rachel
Author by

Vanya Rachel

Updated on December 08, 2022

Comments

  • Vanya Rachel
    Vanya Rachel over 1 year

    Anyone can tell my fault, when I use example for camera Flutter the error was

    NoSuchMethodError: The getter 'isEmpty' was called on null. Receiver : null Tried calling: isEmpty

    I've implemented the permission for android and ios

    • Pankaj Kumar
      Pankaj Kumar over 5 years
      Are you using minSdkVersion 21
    • Vanya Rachel
      Vanya Rachel over 5 years
      yes I use minSdkVersion 21 in build.gradle android
    • Pankaj Kumar
      Pankaj Kumar over 5 years
      Are you using <uses-permission android:name="android.permission.CAMERA" /> permission in manifest. Not sure for flutter but when you read camera info or use camera, you need this permission.
    • Vanya Rachel
      Vanya Rachel over 5 years
      still doesn't work huhu. I don't know why it's happen :(
    • Pankaj Kumar
      Pankaj Kumar over 5 years
      Just wanted to confirm if you already enabled the Camera permission
    • Vanya Rachel
      Vanya Rachel over 5 years
      it's only working when I put the code on main.dart, thanks @PankajKumar