Created
December 7, 2020 11:02
-
-
Save jonasfranz/67148d132cb930bc6f1cee6a8a4fcff1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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