Search code examples
flutterlistdartdart-null-safety

How to access the String inside the List in Map<String, List<String>>?


final Map<String, List<String>> todoDate = {
'today': ['code', 'read a book']};

I am trying to display the String value in the List.

Text(todoDate['today'][0], //ERROR!

Solution

  • It is possible to get null data while reading map. And Text widget doesn't accept null value. You can provide default value on null cases.

    Text(todoDate['today']?[0]??"default");