castFrom<S, T> static method
Adapts source
to be a LabeledList<T>
.
Any time the list would produce an element that is not a T
,
the element access will throw.
Any time a T
value is attempted stored into the adapted list,
the store will throw unless the value is also an instance of S
.
If all accessed elements of source
are actually instances of T
,
and if all elements stored into the returned list are actually instance
of S
, then the returned list can be used as a LabeledList<T>
.
Implementation
static LabeledList<T> castFrom<S, T>(
List<S> source, {
Iterable<String?>? labels,
bool growable = true,
}) {
assert(labels == null || labels.length == source.length);
final elements = List.castFrom<S, T>(source);
return LabeledList<T>.from(
elements,
labels: _buildLabels(labels, source.length, growable: growable),
growable: growable,
);
}