single<T> static method

T? single<T>({
  1. required String title,
  2. required List<T> items,
  3. PromptTheme theme = PromptTheme.dark,
  4. int maxVisible = 12,
  5. String labelBuilder(
    1. T
    )?,
})

Creates a single-select prompt.

Returns the selected item or null if cancelled.

Implementation

static T? single<T>({
  required String title,
  required List<T> items,
  PromptTheme theme = PromptTheme.dark,
  int maxVisible = 12,
  String Function(T)? labelBuilder,
}) {
  final prompt = SelectableListPrompt<T>(
    title: title,
    items: items,
    theme: theme,
    multiSelect: false,
    maxVisible: maxVisible,
  );

  final result = prompt.run(
    renderItem: (ctx, item, index, focused, _) {
      final label = labelBuilder?.call(item) ?? item.toString();
      ctx.selectableItem(label, focused: focused);
    },
  );

  return result.isEmpty ? null : result.first;
}