single<T> static method
T?
single<T>({
- required String title,
- required List<
T> items, - PromptTheme theme = PromptTheme.dark,
- int maxVisible = 12,
- String labelBuilder(
- 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;
}