I have the following code that does all the work, but I'm having trouble passing it to a function that takes the array as an argument.
void main()
{
var pairs = [[9, 5, 1], [3, 6]];
var example= pairs.expand((pair) => pair).toList();
example.sort();
print('Result: $example');
}
CodePudding user response:
type '(dynamic) => dynamic' is not a subtype of type '(List) => Iterable'. SO, you can pass with List<List>
type.
void main()
{
var pairs = [[3, 2, 1], [4, 6, 5], [], [9, 7, 8]];
getListOfData(pairs);
}
getListOfData(List<List> pairs){
var desempacotada = pairs.expand((pair) => pair).toList();
desempacotada.sort();
print('Result: $desempacotada'); //Result: [1, 2, 3, 4, 5, 6, 7, 8, 9]
}