StreamList<E>.filled constructor
StreamList<E>.filled (
- int length,
- E fill, {
- bool growable = false,
- OnUpdate<
List< ? onUpdate,E> > - OnEvent<
CollectionEvent< ? onEvent,int, E> > - OnChange<
CollectionChangeEvent< ? onChange,int, E> >
Creates a list of the given length with fill
at each position.
The length
must be a non-negative integer.
Example:
List<int>.filled(3, 0, growable: true); // [0, 0, 0]
The created list is fixed-length if growable
is false (the default)
and growable if growable
is true.
If the list is growable, changing its length will not initialize new
entries with fill
.
After being created and filled, the list is no different from any other
growable or fixed-length list created using List.
All elements of the returned list share the same fill
value.
var shared = List.filled(3, []);
shared[0].add(499);
print(shared); // => [[499], [499], [499]]
You can use List.generate to create a list with a new object at each position.
var unique = List.generate(3, (_) => []);
unique[0].add(499);
print(unique); // => [[499], [], []]
Implementation
factory StreamList.filled(
int length,
E fill, {
bool growable = false,
OnUpdate<List<E>>? onUpdate,
OnEvent<CollectionEvent<int, E>>? onEvent,
OnChange<CollectionChangeEvent<int, E>>? onChange,
}) {
return StreamList(
value: List<E>.filled(length, fill, growable: growable),
onUpdate: onUpdate,
onEvent: onEvent,
onChange: onChange,
);
}