ListGrid<E>.fromRows constructor
Creates a new list grid from a 2D list of rows of columns.
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, in which
case the rows must be non-empty.
The rows
and columns must be non-empty.
Implementation
factory ListGrid.fromRows(Iterable<Iterable<E>> rows, {E? empty}) {
final (cells, size) = checkRectangular2D(rows);
return _ListGrid(
size.x,
size.y,
empty ?? _mostCommonElement(cells),
List.of(cells),
);
}