Skip to content

Instantly share code, notes, and snippets.

@jonasfranz
Created December 7, 2020 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasfranz/67148d132cb930bc6f1cee6a8a4fcff1 to your computer and use it in GitHub Desktop.
Save jonasfranz/67148d132cb930bc6f1cee6a8a4fcff1 to your computer and use it in GitHub Desktop.
void main() {
List<Map<String, dynamic>> arr1 = [
{"id": "1", "name": "First Item", "price": 10},
{"id": "2", "name": "Second Item", "price": 12}
];
List<Map<String, dynamic>> arr2 = [
{"id": "1", "quantity": 1},
{"id": "2", "quantity": 3},
{"id": "3", "quantity": 2}
];
final arr3 = arr1.map((product) {
final quantity = arr2
.where((quantities) => quantities["id"] == product["id"])
.map((quantities) => quantities["quantity"] as int)
.first;
return product..["quantity"] = quantity;
});
print(arr3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment