When changing the selected state of a chip, the style properties specified in the style
function should update accordingly, regardless of whether an avatarText
function is provided.
A workaround for this issue is to provide an empty avatarText function even if it's not needed for the specific use case. This forces the ChipsChoice
widget to update the style properties specified in the style
function.
ChipsChoice.multiple(
value: selectedCashier,
alignment: WrapAlignment.start,
wrapCrossAlignment: WrapCrossAlignment.start,
wrapped: true,
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
choiceItems: C2Choice.listFrom<String, CashierSummary>(
source: data.data!,
value: (index, item) => item.name,
label: (index, item) => item.name,
style: (index, item) {
final selected = selectedCashier.contains(item.name);
return C2ChipStyle(
borderRadius: const BorderRadius.all(Radius.circular(15)),
borderColor: Theme.of(context).colorScheme.primary,
backgroundColor: selected
? Colors.White
: Colors.Brown,
foregroundColor: selected
? Colors.White
: Colors.Brown,
);
},
avatarText: (index, item) {
bool selected = selectedCashier.contains(item.name);
return Icon(
selected
? Icons.check_circle_outline
: Icons.circle_outlined,
color: !selected
? Colors.White
: Colors.Brown,
size: 20,
);
},
),
choiceStyle: C2ChipStyle(
borderRadius: const BorderRadius.all(Radius.circular(15)),
checkmarkColor: Theme.of(context).colorScheme.primary,
borderWidth: 2,
borderStyle: BorderStyle.solid,
backgroundOpacity: 1,
),
onChanged: (values) {
ref
.read(selectedCashiersProvider.notifier)
.update((state) => state = values);
},
);