Solved: Is it possible to remove data from a map based on a key-value pair in dart/flutter?

Question

Asked by Mark on January 03, 2022 (source).

I have a map that goes like this

[
  {
   pid: 8876,
   name: Alex
  },
  {
   pid: 5228,
   name: John
  },
  {
   pid: 9762,
   name: Fred
  }
]

And I need to delete an entire entry based on the pid, so for example, if pid == 5228 then it would delete the entire corresponding entry and the result would be:

[
  {
   pid: 8876,
   name: Alex
  },
  {
   pid: 9762,
   name: Fred
  }
]

Answer

Question answered by zabaykal (source).

You can use removeWhere method.

For example: map.removeWhere((pid, name) => pid == 5228);

DART FLUTTER
SHARE: