SelectionController<T> constructor

SelectionController<T>({
  1. required String indexGetter(
    1. T
    ),
  2. required Iterable<T> selectableOptions,
  3. String groupNameGetter(
    1. T
    )?,
  4. Iterable<String>? initiallySelected,
  5. SelectionMode mode = SelectionMode.multiple,
})

Each selectableOptions must somehow can be identified uniquely in String. Specify how that identification is done on indexGetter.

You can groups options (selectableOptions's elements) by some String identification (like index) which you can specify on groupNameGetter.

Implementation

SelectionController({
  required this.indexGetter,
  required Iterable<T> selectableOptions,
  String Function(T)? groupNameGetter,
  Iterable<String>? initiallySelected,
  this.mode = SelectionMode.multiple,
}) {
  assert(T is! String);

  // fill default
  this.groupNameGetter = groupNameGetter ?? (t) => 'noGroup';
  _selected = Set.from(initiallySelected ?? <String>[]);

  _init(selectableOptions);

  _originalSelected = Set.from(_constrainedSelected());
  // constraint only done at runtime
}