Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

class _LandingScreenState extends State<LandingScreen>{
       late File imageFile;
       
       _openGallery() async{
       var picture = await ImagePicker.pickImage(source: 
       ImageSource.gallery);
       this.setState(() {
       imageFile = picture as File;
       });
}
like image 290
Ayodeji Onibuje Avatar asked Oct 24 '25 17:10

Ayodeji Onibuje


1 Answers

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

like image 53
Yeasin Sheikh Avatar answered Oct 26 '25 06:10

Yeasin Sheikh



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!