item method

Widget item(
  1. int index
)

Implementation

Widget item(int index) {
  final option = options[index];
  final optionValue = option.value;
  final isOptionDisabled = true == disabled?.contains(optionValue);
  final control = Checkbox(
    activeColor: activeColor,
    checkColor: checkColor,
    focusColor: focusColor,
    hoverColor: hoverColor,
    materialTapTargetSize: materialTapTargetSize,
    value: tristate
        ? value?.contains(optionValue)
        : true == value?.contains(optionValue),
    tristate: tristate,
    onChanged: isOptionDisabled
        ? null
        : (selected) {
            List<T> selectedListItems = value == null ? [] : List.of(value!);
            selected!
                ? selectedListItems.add(optionValue)
                : selectedListItems.remove(optionValue);
            onChanged(selectedListItems);
          },
  );
  final label = GestureDetector(
    onTap: isOptionDisabled
        ? null
        : () {
            List<T> selectedListItems = value == null ? [] : List.of(value!);
            selectedListItems.contains(optionValue)
                ? selectedListItems.remove(optionValue)
                : selectedListItems.add(optionValue);
            onChanged(selectedListItems);
          },
    child: option,
  );

  return Row(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      if (controlAffinity == ControlAffinity.leading) control,
      Flexible(flex: 1, child: label),
      if (controlAffinity == ControlAffinity.trailing) control,
      if (separator != null && index != options.length - 1) separator!,
    ],
  );
}