Dart Collections: Dart Spread Operations

Dart Collections: Dart Spread Operations

In Dart, spread operations allow you to easily combine or create collections by spreading the elements of another collection. There are two types of spread operations: spread (...) and null-aware spread (...?).

Spread ( . . .) Operations

List:

Set:

Maps:

Null-aware Spread (...?) Operation

The null-aware spread operator (...?) is used to spread elements only if the source collection is not null.

List:

Set:

Maps:

Spread operations are useful for creating new collections, combining existing ones, and handling cases where collections might be null. They provide a concise and readable way to manipulate collections in Dart.