The syntax of List.List.empty constructor is:
List.empty({bool growable = false})
This List.empty constructor of List creates a new empty list.
Parameter | Optional/Required | Description |
---|---|---|
growable | optional [default value is false] | whether the list is growable |
In this example,
numbers
by calling List.empty()
.void main() {
List<int> numbers = List.empty();
print(numbers); // Output: []
}
[]
In this example,
characters
by calling List.empty(growable: true)
.growable
parameter to true
, making the list growable.void main() {
List<String> characters = List.empty(growable: true);
print(characters); // Output: []
}
[]
In this example,
strings
by calling List.empty()
.void main() {
List<String> strings = List.empty();
print(strings); // Output: []
}
[]
In this Dart tutorial, we learned about List.empty constructor of List: the syntax and few working examples with output and detailed explanation for each example.