ListGrid<E>.fromCells constructor
Creates a new list grid from elements
in row-major order.
Each element in rows
, a column, must have the same length, and the
resulting grid will have a width equal to the number of columns, and a
height equal to the length of each column.
The grid is initialized with the elements in the rows, where the element
at index (x, y)
is rows.elementAt(y).elementAt(x)
. If the empty
element is omitted, the most common element in the rows is used.
The elements
must be non-empty.
Implementation
factory ListGrid.fromCells(
Iterable<E> elements, {
required int width,
E? empty,
}) {
final (cells, size) = checkRectangular1D(elements, width: width);
return _ListGrid(
size.x,
size.y,
empty ?? _mostCommonElement(cells),
List.of(cells),
);
}