Grid<T extends Object> class

A generic grid class that holds a 2D list of objects of type T.

Constructors

Grid.make(int rows, int columns, T initialValue)
Factory constructor to create a grid with the specified number of rows and columns, initializing all cells with the initialValue.
factory

Properties

columns int
Returns the number of columns in the grid.
no setter
hashCode int
The hash code for this object.
no setteroverride
initialValue → T
The initial value for the grid cells.
final
rows int
Returns the number of rows in the grid.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size → ({int columns, int rows})
Returns the size of the grid as a map with keys rows and columns.
no setter
vector Vector2D<T>
Returns the _vector
no setter

Methods

copyWith({Vector2D<T>? vector}) Grid<T>
Creates a copy of the grid with the option to replace the vector values. If vector is provided, it will be used to create the new grid.
fillCells(List<GridCell> cells, T state) → void
Fills the specified cells with the given state.
filledCells(bool filter(T state)) List<GridCell>
Returns a list of GridCells that match the given filter function.
filledCellsCount(bool filter(T state)) int
Returns the count of cells that match the given filter function.
filter(GridCell cell, bool filter(T state)) bool
Applies the filter function to the cell at the given cell position.
filterCells(List<GridCell> cells, bool filter(T state)) bool
Applies the filter function to all the specified cells. Returns true if all cells match the filter, otherwise false.
firstWhereOrNull(bool predicate(T state)) GridCell?
Returns the first GridCell that matches the given predicate function, or null if none found.
getNeighbourPositions(GridCell cell) Map<String, GridCell?>
Returns a map of neighboring positions for the given cell. The keys are above, below, left, and right.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resetCells(List<GridCell> cells) → void
Resets the specified cells to the initial value.
toString() String
A string representation of this object.
inherited
validPosition(GridCell cell) bool
Checks if the given cell position is valid within the grid boundaries.

Operators

operator ==(Object other) bool
The equality operator.
override
operator [](GridCell cell) → T
operator []=(GridCell cell, T value) → void