Introduction
Sometimes, we'll like to combine two or more lists in Flutter. In this tutorial, we'll learn several ways to do it.
How to combine Lists in Flutter
To combine two or more lists in Flutter we can use from()
and addAll()
method:
The output:
Using expand()
method to combine lists in Flutter:
The output:
Combining lists in Flutter using the operator +
:
The output:
Combine lists in Flutter using the spread operator ...
:
The output:
The spread operator introduced in Dart 2.3, works similarly to the spread operator available in JavaScript.
Conclusion
In this short tutorial, we showcased several ways to combine lists in Flutter.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}