setGrid method

void setGrid(
  1. Uint8List grid,
  2. int cols
)

Sets the grid of the Matrix object.

This method takes a 2D list of boolean values representing the grid of the Matrix. It ensures that all rows have the same length, and creates a deep copy of the grid to store in the Matrix's internal _data field.

If the input grid is empty or has no rows, the Matrix's rows and cols fields are set to 0, and the _data field is set to an empty list.

Parameters: grid (Uint8List): The 2D list of boolean values representing the grid.

Implementation

void setGrid(final Uint8List grid, final int cols) {
  if (grid.isEmpty) {
    clear();
    return;
  }
  this.cols = cols;

  // Create a deep copy of the grid
  _matrix = Uint8List.fromList(grid);
}