How to solve: Converting List<String> to List<Map<String,dynamic>>

Question

Asked by A_Bee on November 16, 2021 (source).

How can I convert my List to List<Map<String,dynamic>>? The selected field value will always be false.

List<String> stringList = ["one", "two", "three"];

List<Map<String, dynamic>> mapList = [
 {"name": "one","selected": false},
 {"name": "two","selected": false},
 {"name": "three", "selected": false}];

Answer

Question answered by Dorrineeee (source).

final List<Map<String, dynamic>> mapList = stringList.map(
    (s) => {'name': s, 'selected': false}
).toList();
DART FLUTTER
SHARE: