DynamicListPrompt<T> class

DynamicListPrompt – composable system for lists with dynamic items.

Handles patterns where items change based on state:

  • Tree navigation (expand/collapse)
  • File system navigation
  • Any hierarchical or mutable list

Design principles:

  • Composition over inheritance
  • Separation of concerns (item generation is separate from navigation)
  • DRY: Centralizes the dynamic list pattern

Usage:

final prompt = DynamicListPrompt<TreeEntry>(
  title: 'Explorer',
  buildItems: () => flattenTree(root, expandedNodes),
);

final result = prompt.run(
  onAction: (item, action) {
    if (action == ItemAction.expand) expandedNodes.add(item);
    if (action == ItemAction.collapse) expandedNodes.remove(item);
  },
);

Constructors

DynamicListPrompt({required String title, PromptTheme theme = PromptTheme.dark, int maxVisible = 18})

Properties

bindings KeyBindings
Current key bindings.
no setter
hashCode int
The hash code for this object.
no setterinherited
items List<T>
Current items.
no setter
maxVisible int
Maximum visible items (viewport size).
final
Current navigation state.
no setter
result → T?
The result item (if confirmed).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
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({required List<T> buildItems(), DynamicAction onPrimary(T item, int index)?, DynamicAction onSecondary(T item, int index)?, DynamicAction onToggle(T item, int index)?, required void renderItem(FrameContext ctx, T item, int absoluteIndex, bool isFocused), void beforeItems(FrameContext ctx)?, KeyBindings? extraBindings, KeyBindings? customBindings}) → T?
Runs the dynamic list prompt.
toString() String
A string representation of this object.
inherited

Operators

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