-2

I am getting the image by image picker and then adding the file to the list of file but it shows the error-The method 'add' was called on null.. My code:-

final picker=ImagePicker();    
selectImageFromGallery() async
      {
        setState(() {
          inProcess=true;
        });
        final imageFile= await picker.getImage(source: ImageSource.gallery);
        if(imageFile!=null)
          {
            File _image=File(imageFile.path);
            files.add(_image);
          }
        setState(() {
          inProcess=false;
        });
      }
Deepak Lohmod
  • 2,072
  • 2
  • 8
  • 18

1 Answers1

1

It seems like files is a List<File> but it's not properly initialized.

You need to initialize it as an empty list, such as:

final files = <File>[];

so you can add files to it.

osaxma
  • 2,657
  • 2
  • 12
  • 21