How can I dynamically add data to a list like this [Dart]

Viewed 42

I need some help. I just cannot figure out how to add data (here more animals with values) to a List like following:

List animal = [{ "display": "Dog", "value": "1",},{"display": "Cat","value": "2",}];

-> so the structure of a entry must be like {"display" : "XYZ", "value": "NRXYZ"}. Is there a function to dynamically add more animals with values.

Thanks a lot!

1 Answers

You can use add() method:

animal.add({"display" : "XYZ", "value": "NRXYZ"});

If you want to add multiple animals at the end of the list you can use addAll() method:

animal.addAll([{ "display": "Ferret", "value": "3",}, {"display": "Bird", "value": "4",}]);
Related