I have a Map
like following:
final Map<String, dynamic> question = {
'rating': {
'added': false,
}
};
And I want to use it inside another Map
like below:
final Map<String, dynamic> book = {
'detail': {
'questions': [
question // here I need to have a list of the above Map
]
}
};
But it doesn’t work. How can I use another Map
‘s definition inside a Map
I am gonna define as it’s parent?
3
Answers
try to put the spread operator "…" like this:
[EDIT]
try this instead,it should work fine now :
Use it like this:
I tried your code and it works just fine, but as mentioned by @Soliev, it is recommended to use classes instead of plain maps.
Here is an example of how you can use your code with classes.
This is a very simple example, but later on, you can research data classes, toJson, and FromJson methods, and add them to your classes if needed.