SearchableListPrompt<T> class

SearchableListPrompt – composable system for searchable/filterable list prompts.

Extends the SelectableListPrompt pattern with:

  • Real-time search/filter via TextInputBuffer
  • Dynamic item filtering with constraint handling
  • Toggleable search mode

Design principles:

  • Composition over inheritance (uses same components as SelectableListPrompt)
  • Separation of concerns (search is separate from selection/navigation)
  • DRY: Centralizes the searchable list pattern

Usage:

final prompt = SearchableListPrompt<String>(
  title: 'Search and select',
  items: allItems,
  multiSelect: true,
);

final result = prompt.run();

With custom filter:

final result = prompt.run(
  filter: (item, query) => item.name.contains(query),
  itemLabel: (item) => item.name,
);

Constructors

SearchableListPrompt({required String title, required List<T> items, PromptTheme theme = PromptTheme.dark, bool multiSelect = false, int maxVisible = 10, Set<int>? initialSelection, bool searchEnabled = true, int reservedLines = 7})

Properties

bindings KeyBindings
Current key bindings.
no setter
filtered List<T>
Currently filtered items.
no setter
hashCode int
The hash code for this object.
no setterinherited
initialSelection Set<int>?
Initial selection indices.
final
isSearchActive bool
Whether search is currently active.
no setter
items List<T>
All items (before filtering).
final
maxVisible int
Maximum visible items (viewport size).
final
multiSelect bool
Whether multiple items can be selected.
final
Current navigation state.
no setter
queryInput TextInputBuffer
Current search query input.
no setter
reservedLines int
Terminal lines to reserve for chrome.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchEnabled bool
Whether search is initially enabled.
final
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
run({bool filter(T item, String query)?, String itemLabel(T item)?, void renderItem(FrameContext ctx, T item, int absoluteIndex, bool isFocused, bool isSelected, String query)?, bool highlightMatches = true, KeyBindings? extraBindings}) List<T>
Runs the searchable prompt.
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 maxVisible = 10, Set<int>? initialSelection, String labelBuilder(T)?, bool searchEnabled = true}) List<T>
Creates a multi-select searchable prompt.
single<T>({required String title, required List<T> items, PromptTheme theme = PromptTheme.dark, int maxVisible = 10, String labelBuilder(T)?, bool searchEnabled = true}) → T?
Creates a single-select searchable prompt.