Home > Mobile >  Instance member 'pickImage' can't be accessed using static access
Instance member 'pickImage' can't be accessed using static access

Time:08-10

I have ran into a problem concerning my Flutter app , I've been following a tutorial on Youtube on how to use select picture from gallery and also camera in Flutter but have not been able to get the image picker function to work. It always returns the error

"Instance member 'pickimage' can't be accessed using static access.

can anyone help out this cause I'm a little confused. thank you in advance.

class _LandingScreenState extends State<LandingScreen>{
       late File imageFile;
       
       _openGallery() async{
       var picture = await ImagePicker.pickImage(source: 
       ImageSource.gallery);
       this.setState(() {
       imageFile = picture as File;
       });
}

CodePudding user response:

pickImage is not a static method. You can create an instance and then call the method. It can be done directly create instance and call method like

await ImagePicker().pickImage(source: ImageSource.gallery);

A use nullable Xfile for safe case.

  XFile? imageFile;

  _openGallery() async {
    imageFile = await ImagePicker().pickImage(source: ImageSource.gallery);
    setState(() {});
  }

  • Related