I was wondering if there was an easy way to concatenate two lists in dart to create a brand new list object. I couldn\'t find anything and something like this:
My list:>
addAll
is the most common way to merge two lists.
But to concatenate list of lists, you can use any of these three functions (examples below):
void main() {
List a = [1,2,3];
List b = [4,5];
List c = [6];
List> abc = [a,b,c]; // list of lists: [ [1,2,3], [4,5], [6] ]
List ints = abc.expand((x) => x).toList();
List ints2 = abc.reduce((list1,list2) => list1 + list2);
List ints3 = abc.fold([], (prev, curr) => prev + curr); // initial value is []
print(ints); // [1,2,3,4,5,6]
print(ints2); // [1,2,3,4,5,6]
print(ints3); // [1,2,3,4,5,6]
}