Google News
logo
Flutter - Interview Questions
Explain the Spread operator.
In Dart, Spread Operator (…) and Null-aware Spread Operator (…?) are used for inserting multiple elements in a collection like Lists, Maps, etc.

Syntaxes :

Spread operator :
...Data_structure
Example:-
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]
Null-aware Spread operator
...?Data_structure
Exmaple :-
List<int> l1 = [1, 2, 3];
List<int> nullList = null;
List<int> result = [...l1, ...?nullList];
print(result); // prints:   [1, 2, 3] ​
Advertisement