Search code examples
arraysflutterlistdictionaryobject

how to access a List<Map> in flutter


I have the following list:

List<Map> list = [{'id': 5, 'title': 'fdf', 'description': 'fdf'}];

Now, I want to access this list and retrieve, for example, the title value to store it in a variable.

How can I do that?

It is probably very simple, but I got confused.


Solution

  • You can access title's value like this:

    if(list.isNotEmpty){
      print("value = ${list.first["title"]}");
    }
    

    or if you list has multiple item you can access like this:

    for (var item in list) {
       print("value = ${item["title"]}");
    }
    

    and the result would be fdf.