I want to have a map which saves two types of lists. When I try to add a list with two items into a map, the map gets a list with only one item, although it had two! How can I add the list to the map, without losing any items?
Map<String, dynamic> habitMap = json.decode(oldJsonString);
List<HabitBuild> habitBuildList = [];
List<dynamic> dynamicList = habitMap["habitBuildList"];
dynamicList.forEach((element) {
habitBuildList.add(HabitBuild.fromJson(element));
});
habitBuildList.add(habitBuild);
habitMap.putIfAbsent("habitBuildList", () => habitBuildList);
String jsonString = json.encode(habitMap);