I’m trying to create a nested map in dart :
static Map<String, Map<String, dynamic>> items = new Map<String, Map<String, dynamic>>();
and add values to this map when pressing a button :
Mainclass.items.addAll({
"keyname" : {
"firestvalue": 100, // cghange every press
"secondvalue": 100 // cghange every press
}
});
This is not working, it everytime shows length 1 :
print("length" + account.items.length.toString());
Any suggestions ?
2
Answers
here is an implementation how you can do
you can make function addValuesToMap()
then this function you can call in elevated button
I am not sure what you expect to happen. However, if you want to dump values into a map of map, you want to maintain a key/index for each inner map you add.
You can call the
addValuesToMap()
function from the onpressed of a button.