choiceChipBuilder<T> function
A FastChoiceChipBuilder that is the default FastChoiceChips.chipBuilder.
Returns a ChoiceChip that updates the FastChoiceChipsState.value in ChoiceChip.onSelected.
Implementation
ChoiceChip choiceChipBuilder<T>(
FastChoiceChip<T> chip, FastChoiceChipsState<T> field) {
final FastChoiceChipsState<T>(:didChange, :enabled, :value!, :widget) = field;
void onSelected(selected) {
chip.onSelected?.call(selected);
Set<T> updatedValue;
if (selected) {
updatedValue = {...value, chip.value};
} else {
updatedValue = {
...[...value]..remove(chip.value)
};
}
didChange(updatedValue);
}
return ChoiceChip(
autofocus: chip.autofocus,
avatar: chip.avatar,
avatarBorder: chip.avatarBorder,
backgroundColor: chip.backgroundColor,
checkmarkColor: chip.checkmarkColor,
clipBehavior: chip.clipBehavior,
color: chip.color,
disabledColor: chip.disabledColor,
elevation: chip.elevation,
focusNode: chip.focusNode,
iconTheme: chip.iconTheme,
label: chip.label,
labelPadding: chip.labelPadding,
labelStyle: chip.labelStyle,
materialTapTargetSize: chip.materialTapTargetSize,
onSelected: enabled && chip.isEnabled ? onSelected : null,
padding: chip.padding ?? widget.chipPadding,
pressElevation: chip.pressElevation,
selected: value.contains(chip.value),
selectedColor: chip.selectedColor,
selectedShadowColor: chip.selectedShadowColor,
shadowColor: chip.shadowColor,
shape: chip.shape,
showCheckmark: chip.showCheckmark ?? widget.showCheckmark,
side: chip.side,
surfaceTintColor: chip.surfaceTintColor,
tooltip: chip.tooltip,
visualDensity: chip.visualDensity,
);
}