SelectableGridPrompt<T> class

SelectableGridPrompt – composable system for grid-based selection prompts.

Composes:

Design principles:

  • Composition over inheritance
  • Separation of concerns
  • DRY: Centralizes grid selection patterns
  • Parallel to SelectableListPrompt for lists

Usage:

final prompt = SelectableGridPrompt<String>(
  title: 'Pick colors',
  items: ['Red', 'Green', 'Blue', 'Yellow'],
  columns: 2,
  multiSelect: true,
);

final result = prompt.run(
  renderCell: (ctx, item, index, focused, selected, cellWidth) {
    // Custom cell rendering
  },
);

Auto layout:

final prompt = SelectableGridPrompt.responsive(
  title: 'Select',
  items: items,
  cellWidth: 20,
);
Available extensions

Constructors

SelectableGridPrompt({required String title, required List<T> items, PromptTheme theme = PromptTheme.dark, bool multiSelect = false, int columns = 0, int? cellWidth, int? maxColumns, Set<int>? initialSelection})
SelectableGridPrompt.responsive({required String title, required List<T> items, required int cellWidth, PromptTheme theme = PromptTheme.dark, bool multiSelect = false, int? maxColumns, Set<int>? initialSelection})
Creates a responsive grid that adapts to terminal width.
factory

Properties

bindings KeyBindings
Current key bindings.
no setter
cellWidth int?
Fixed cell width (null = auto-calculate from items).
final
columns int
Number of columns (0 = auto-calculate).
final
computedCellWidth int
Computed cell width.
no setter
computedColumns int
Computed column count.
no setter
grid GridNavigator
Current grid navigation state.
no setter
hashCode int
The hash code for this object.
no setterinherited
initialSelection Set<int>?
Initial selection indices.
final
items List<T>
Items to select from.
final
maxColumns int?
Maximum columns for auto layout.
final
multiSelect bool
Whether multiple items can be selected.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selection SelectionController
Current selection state.
no setter
theme PromptTheme
Theme for styling.
final
title String
Title for the frame header.
final
wasCancelled bool
Whether the prompt was cancelled.
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
renderCard({required String title, String? subtitle, required bool isFocused, required bool isSelected}) CardRender

Available on SelectableGridPrompt<T>, provided by the SelectableGridPromptCards extension

Renders a two-line card with title and subtitle.
renderChip(T item, bool isFocused, bool isSelected, {String labelBuilder(T)?}) String

Available on SelectableGridPrompt<T>, provided by the SelectableGridPromptTags extension

Renders items as tag chips: tag
run({void renderCell(FrameContext ctx, T item, int index, bool isFocused, bool isSelected, int cellWidth)?, String itemLabel(T item)?, KeyBindings? extraBindings, bool showCellSeparators = true, bool showRowSeparators = true}) List<T>
Runs the grid prompt.
runCustom({required void renderContent(FrameContext ctx), KeyBindings? extraBindings}) List<T>
Runs with custom full-render control (for complex grids like ChoiceMap).
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

multi<T>({required String title, required List<T> items, PromptTheme theme = PromptTheme.dark, int columns = 0, int? cellWidth, int? maxColumns, Set<int>? initialSelection, String labelBuilder(T)?}) List<T>
Creates a multi-select grid prompt.
single<T>({required String title, required List<T> items, PromptTheme theme = PromptTheme.dark, int columns = 0, int? cellWidth, int? maxColumns, String labelBuilder(T)?}) → T?
Creates a single-select grid prompt.