Search code examples
fluttercompiler-warningsimagepicker

ImagePicker.platform shows warning - Flutter


I am using the following code to pick an image from user's gallery.

Future getImageFromGallery(BuildContext context) async {
    await ImagePicker.platform()
        .pickImage(source: ImageSource.gallery)
        .then((image) {
      if (image != null) {
        _cropImage(image, context);
      }
    });
  }

I am getting the following warning.

The member 'platform' can only be used within 'package:image_picker/image_picker.dart' or a test.

I'm not sure what the warning means. I tried looking it up but couldn't figure out the solution to resolve this warning.


Solution

  • You can just change the code

    ImagePicker.platform().pickImage(...)
    

    to

    ImagePicker().pickImage(...)
    

    so

    Future getImageFromGallery(BuildContext context) async {
        await ImagePicker()
          .pickImage(source: ImageSource.gallery)
          .then((image) {
          if (image != null) {
             _cropImage(image, context);
          }
       });
    }