ListGrid<T>.generate constructor

ListGrid<T>.generate(
  1. int width,
  2. int height,
  3. T generator(
    1. int x,
    2. int y
    )
)

Creates a new grid with the given width and height.

The grid is filled with the result of calling generator for each cell.

The width and height must be non-negative.

Implementation

factory ListGrid.generate(
  int width,
  int height,
  T Function(int x, int y) generator,
) {
  RangeError.checkNotNegative(width, 'width');
  RangeError.checkNotNegative(height, 'height');
  return ListGrid.fromCells(
    Iterable.generate(height, (y) {
      return Iterable.generate(width, (x) => generator(x, y));
    }).expand((row) => row),
    width: width,
  );
}