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:;
       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:;

A use nullable Xfile for safe case.

  XFile? imageFile;

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

Leave a Reply