Munib Shah
Munib Shah

Reputation: 43

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

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

Upvotes: 0

Views: 49

Answers (1)

Jigar Patel
Jigar Patel

Reputation: 5423

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

List<Image> imagesList = [];

Upvotes: 2

Related Questions