Search code examples
firebaseflutterdart-null-safety

The method 'map' can't be unconditionally invoked because the receiver can be 'null'


enter image description here

there is error with the map even when i add .toList() to the map


Solution

  • This error indicates that map((note) => Text(note.title)) can potentially be null.

    If you are sure that you will always have items in notes, use the "!" to tell the compiler that it won't be null:

    final children = notes.map((note) => Text(note.title))!.toList();