Flutter: doing math to each item in a list?

Viewed 24

How do we do math to each item in a list (add numbers from variable and multiply final value) and return another List?

1 Answers

Something like this:

var list = [1, 2, 3, 4, 5];
print(list); // Prints [1, 2, 3, 4, 5]
var list2 = list.map((i) => i * 2 + 5 /* math here*/).toList();
print(list2); // Prints [7, 9, 11, 13, 15]
Related