Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Instance member 'pickImage' can't be accessed using static access

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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(() {});
  }

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading