multi<T> static method

List<T> multi<T>({
  1. required String title,
  2. required List<T> items,
  3. PromptTheme theme = PromptTheme.dark,
  4. int maxVisible = 12,
  5. Set<int>? initialSelection,
  6. String labelBuilder(
    1. T
    )?,
  7. bool withSelectAll = true,
})

Creates a multi-select prompt with checkbox UI.

Returns selected items (empty if cancelled).

Implementation

static List<T> multi<T>({
  required String title,
  required List<T> items,
  PromptTheme theme = PromptTheme.dark,
  int maxVisible = 12,
  Set<int>? initialSelection,
  String Function(T)? labelBuilder,
  bool withSelectAll = true,
}) {
  final prompt = SelectableListPrompt<T>(
    title: title,
    items: items,
    theme: theme,
    multiSelect: true,
    maxVisible: maxVisible,
    initialSelection: initialSelection,
  );

  KeyBindings? extra;
  if (withSelectAll) {
    extra = KeyBindings.letter(
      char: 'A',
      onPress: () => prompt.selection.toggleAll(items.length),
      hintDescription: 'select all / clear',
    );
  }

  return prompt.run(
    renderItem: (ctx, item, index, focused, selected) {
      final label = labelBuilder?.call(item) ?? item.toString();
      ctx.checkboxItem(label, focused: focused, checked: selected);
    },
    extraBindings: extra,
  );
}