Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to spread a list in dart

Tags:

flutter

dart

In Javascript I would use a spread operator:

enter image description here

Now I have the same problem with Flutter:

 Widget build(BuildContext context) {     return Column(       children: <Widget>[         MyHeader(),         _buildListOfWidgetForBody(), // <- how to spread this <Widget>[] ????         MyCustomFooter(),       ],     );   } 
like image 941
TSR Avatar asked Feb 15 '19 12:02

TSR


People also ask

How do you unpack a List in darts?

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.

What does 3 dots mean in Dart?

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 .

How do you define a List in darts?

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.

How do you add multiple values to a List in Dart?

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.


1 Answers

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] 
like image 168
ikben Avatar answered Oct 01 '22 17:10

ikben