LabeledList<E>.from constructor

LabeledList<E>.from(
  1. Iterable<E> elements,
  2. {Iterable<String?>? labels,
  3. bool growable = true}
)

Constructs a new LabeledList from elements.

If elements is a List, the returned LabeledList will wrap it; otherwise, a new List will be constructed from elements.

Note: Use the LabeledList.of constructor to construct a new LabeledList containing the elements of a List, without referencing the original list.

If labels are provided, there must be a label or a null value for every element in in the list. labels.length must equal the length of the list.

If growable is false, the returned list will be a fixed-length list, otherwise the list is growable and identical to the default constructor.

Implementation

LabeledList.from(
  Iterable<E> elements, {
  Iterable<String?>? labels,
  bool growable = true,
})  : assert(labels == null || labels.length == elements.length),
      _labels = _buildLabels(labels, elements.length, growable: growable),
      super(
        elements is List<E>
            ? elements
            : List<E>.from(elements, growable: growable),
        growable: growable,
      );