buildItem method

Widget buildItem(
  1. int index
)

the composite of all the components for the option at index

Implementation

Widget buildItem(int index) {
  final option = options[index];
  final optionValue = option.value;
  final isOptionDisabled = true == disabled?.contains(optionValue);
  final control = Checkbox(
    visualDensity: visualDensity,
    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,
  );

  Widget compositeItem = Column(
    mainAxisSize: MainAxisSize.min,
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          if (controlAffinity == ControlAffinity.leading) control,
          Flexible(flex: 1, child: label),
          if (controlAffinity == ControlAffinity.trailing) control,
          if (orientation != OptionsOrientation.vertical &&
              separator != null &&
              index != options.length - 1)
            separator!,
        ],
      ),
      if (orientation == OptionsOrientation.vertical &&
          separator != null &&
          index != options.length - 1)
        separator!,
    ],
  );

  if (itemDecoration != null) {
    compositeItem = Container(
      decoration: itemDecoration,
      margin: EdgeInsets.only(
        bottom: orientation == OptionsOrientation.vertical
            ? wrapSpacing
            : 0.0,
        right: orientation == OptionsOrientation.horizontal
            ? wrapSpacing
            : 0.0,
      ),
      child: compositeItem,
    );
  }

  return compositeItem;
}