In Javascript I would use a spread operator:
Now I have the same problem with Flutter:
Widget build(BuildContext context) { return Column( children: <Widget>[ MyHeader(), _buildListOfWidgetForBody(), // <- how to spread this <Widget>[] ???? MyCustomFooter(), ], ); }
Dart does not support unpacking a List into function arguments. However, you can unpack a List into another List by typing three dots ... before the list name.
Since version 2.3, Dart adds a new operator called spread which uses three dots ( ... ) notations. It can be used to extend the elements of a Collection . The examples below show the usage of the notation on List , Set , and Map .
The Dart list is defined by storing all elements inside the square bracket ([]) and separated by commas (,). list1 - It is the list variable that refers to the list object. Index - Each element has its index number that tells the element position in the list.
You can use . add() method to add single item to a list and . addAll() method to add multiple items to a list in Dart programming language.
You can now do spreading from Dart 2.3
var a = [0,1,2,3,4]; var b = [6,7,8,9]; var c = [...a,5,...b]; print(c); // prints: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With