checkboxList<T> method

void checkboxList<T>(
  1. List<T> items, {
  2. required int focusedIndex,
  3. required Set<int> checkedIndices,
  4. int startIndex = 0,
  5. String itemBuilder(
    1. T item
    )?,
})

Writes a list of checkbox items.

items is the list of items to display. focusedIndex is the currently focused index. checkedIndices is the set of checked item indices. startIndex is the offset for viewport scrolling (default 0). itemBuilder converts an item to its display string.

Implementation

void checkboxList<T>(
  List<T> items, {
  required int focusedIndex,
  required Set<int> checkedIndices,
  int startIndex = 0,
  String Function(T item)? itemBuilder,
}) {
  for (var i = 0; i < items.length; i++) {
    final absoluteIndex = startIndex + i;
    final isFocused = absoluteIndex == focusedIndex;
    final isChecked = checkedIndices.contains(absoluteIndex);
    final text = itemBuilder?.call(items[i]) ?? items[i].toString();
    checkboxItem(text, focused: isFocused, checked: isChecked);
  }
}