GridController class

Owns the grid's view state: column order/widths/freeze, sort, filters, search, selection, focus. Mutating data goes through GridDataSource; mutating the view goes through GridController. Both bump revisions independently so renderers only repaint what changed.

Inheritance

Constructors

GridController({required GridSchema schema, required GridDataSource source})
Builds a controller bound to a schema + source. Seeds column / row widths and freeze sides from the schema's defaults and subscribes to the source so data mutations rebuild derived state automatically.

Properties

columnLayout ColumnLayout
Precomputed column partition (start-frozen / scrollable / end-frozen)
no setter
columnOrder List<ColId>
Current visible column order. Reflects reorderColumn calls and hides. Read-only view — call reorderColumn to mutate.
no setter
filters Map<ColId, FilterPredicate>
Active filters keyed by column id. Mutate via setFilter; pass null as the predicate to clear one column.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
hiddenColumns Set<ColId>
Columns hidden via hideColumn. Hidden columns disappear from layout but stay in the schema and data source.
no setter
mergeIndex MergeIndex
Computed merge layout for the current view. Tracks which cells are occluded by a MergeRange anchor so the body skips them.
no setter
pipelineResult ViewPipelineResult
Output of the single-pass view pipeline (filter -> sort -> search). Contains the visible row-index list and the search-hit bitset that the body renderer uses to draw highlights.
no setter
revision int
Monotonic counter bumped on every mutation. Renderers can compare it across frames to decide whether their cached layout is still valid.
no setter
rowLayout RowLayout
Precomputed row partition (top-frozen / middle / bottom-frozen) + cumulative offsets. Frozen rows skip the filter / sort pipeline so they remain stable across view changes.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
schema GridSchema
The schema this controller was constructed with. Read-only — build a new controller if the schema shape changes.
final
searchMode SearchMode
Whether the search query searchMode matches by highlight or by filter. See SearchMode for the two modes.
no setter
searchQuery String
Current search query string. Empty means no search active.
no setter
selection Selection
The current selection state. Mutate via setSelection, selectCell, extendSelectionTo, etc. — never reassign the field directly.
no setter
sortKeys List<SortKey>
Active sort keys in priority order (first = primary). Mutate via setSortKeys; pass const [] to clear.
no setter
source GridDataSource
The data source this controller is bound to. The controller listens on it; cell mutations through source.setValue bump the controller's derived state automatically.
final

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
addSelectionRange(int rowIndex, int colIndex, {CellAddress? focus}) → void
Cmd/Ctrl-click: push a new single-cell range onto the existing list.
clearSelection() → void
Clears the selection. Equivalent to setSelection(Selection.empty).
dispose() → void
Discards any resources used by the object.
override
extendSelectionTo(int rowIndex, int colIndex, {CellAddress? focus}) → void
Shift-click / drag-extend: move the active range's extent.
fitColumnToText({required ColId id, required double measure(String text), double padding = 24, int maxRowsToScan = 200}) double
Resize column id to fit the widest visible cell. Caller supplies the measure callback (typically backed by a TextPainter or paragraph cache) — the controller stays UI-framework agnostic. padding is added to each measurement before taking the max. Returns the chosen width.
freezeOf(ColId id) FrozenSide?
Effective freeze side of column id, or null if scrollable.
freezePriorityOf(ColId id) int
Effective pin priority of column id among same-side frozen columns. Lower values render closer to the outside edge.
heightOf(RowId id) double
Effective height of row id. Falls back to the schema's RowSpec.defaultHeight, then to 44 if no spec exists.
hideColumn(ColId id) → void
Hides column id from the visible layout. The schema and data source are untouched; pair with showColumn to restore.
isColumnHidden(ColId id) bool
Whether column id is currently hidden via hideColumn.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
reorderColumn(ColId id, int toIndex) → void
Move column id to flat index toIndex in the current visible order.
reorderRow(RowId id, int toIndex) → void
Move row id to flat position toIndex in the underlying source. Frozen rows still freeze; the schema order changes underneath.
rowFreezeOf(RowId id) FrozenSide?
Effective freeze side of row id, or null if scrollable.
rowFreezePriorityOf(RowId id) int
Effective pin priority of row id among same-side frozen rows. Lower values render closer to the outside edge of the strip.
selectAll() → void
Select every cell in the visible view.
selectCell(int rowIndex, int colIndex, {CellAddress? focus}) → void
Set the selection to a single cell.
selectColumn(int colIndex, {CellAddress? focus}) → void
Select an entire column (Excel "click on the column letter" gesture).
selectRow(int rowIndex, {CellAddress? focus}) → void
Select an entire row (Excel "click on the row number" gesture).
setColumnFreeze(ColId id, FrozenSide? side, {int priority = 0}) → void
Pins column id to side (or unpins when null) with the given priority among same-side frozen columns. Lower priority renders closer to the outside edge.
setColumnWidth(ColId id, double width) → void
Sets the width of column id. Clamped up to the spec's minWidth (default 40). No-op if the width is unchanged.
setFilter(ColId id, FilterPredicate? predicate) → void
Sets the filter predicate for column id, or clears it when predicate is null. Build predicates with the helpers in Filters.*.
setRowFreeze(RowId id, FrozenSide? side, {int priority = 0}) → void
Pins row id to side (or unpins when null) with the given priority among same-side frozen rows.
setRowHeight(RowId id, double height) → void
Sets the height of row id in logical pixels. No-op if unchanged.
setSearchMode(SearchMode mode) → void
Switches between SearchMode.highlight (keep every row, mark hits) and SearchMode.filter (drop rows with no hits).
setSearchQuery(String query) → void
Updates the global search query. Cells whose string form contains query are marked as hits; whether they're highlighted or filter non-matches depends on searchMode.
setSelection(Selection next) → void
Replaces the current selection wholesale. No-op if next is the same instance as the current selection.
setSortKeys(List<SortKey> keys) → void
Replaces the active sort keys with keys (first = primary). Pass const [] to clear sorting and return to the source's natural order.
showColumn(ColId id) → void
Re-shows column id previously hidden via hideColumn.
toString() String
A string representation of this object.
inherited
widthOf(ColId id) double
Effective width of column id. Falls back to the schema's ColumnSpec.defaultWidth, then to 120 if no spec exists.

Operators

operator ==(Object other) bool
The equality operator.
inherited