The method 'add' was called on null : Flutter, SQFlite

48 views Asked by At

I am getting data from SQLite in flutter. When I try to convert the list of Map to list of Objects. It gives the error of

The method 'add' was called on null

On debuging, it shows that it has data but still gives the error.

Here is my code

 List<Image> imagesList;
    if (imagesListMap != null) {
      imagesListMap.forEach((element) {
        imagesList.add(Image.FromDatabase(element));
      });
    }

And its the debugging screenshot

SS of debug

1

There are 1 answers

0
Jigar Patel On BEST ANSWER

You need to initialize the List like this before calling add() on it..

List<Image> imagesList = [];