Michele Volpato

Michele Volpato

Dart spread operator

Dart

Dart supports the spread operator, which allows to insert multiple elements into a collection.

For instance, from the cascade I described yesterday, this

return someVariable.toList()
    ..add(anotherObject)
    ..addAll(anotherListOfObjects);

becomes

return [
    ...someVariable.toList(),
    anotherObject,
    ...anotherListOfObjects
];

Even more concise and easier to read.

Get a weekly email about Flutter

Subscribe to get a weekly curated list of articles and videos about Flutter and Dart.

    We respect your privacy. Unsubscribe at any time.

    Leave a comment