Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart maps, how to replace specific key value in a list<map> based on its key id?

void main() {
  List<Map<String, dynamic>> products = [
    {'id': 24, 'time': '2019-11-24 00:00:00.000'},
    {'id': 36, 'time': '2019-11-23 00:00:00.000'},
    {'id': 48, 'time': '2019-11-24 00:00:00.000'},
  ];

In the code above I want to replace 'time' entry '2019-11-24 00:00:00.000' to '2019-10-26 00:00:00.000' for the 'id' 48.

like image 660
Jan Avatar asked Oct 23 '25 09:10

Jan


1 Answers

You can try something like this:

   products.whereFirst((x) => x["id"] == 48)["time"] = "2019-10-26 00:00:00.000";
like image 185
Akif Avatar answered Oct 25 '25 00:10

Akif