Issue
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}];
Solution
Do you need something like this?
List<String> stringList = ["one", "two", "three"];
List<Map<String, dynamic>> mapList = [];
stringList.forEach((element) {
mapList.add({"name": "$element", "selected": false});
});
It will loop the stringList array and take each element and put it in the mapList
Answered By - Harsh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.