I'm trying to create a Checkbox List, selectedProvider contains a boolean list with length choices.lenght. Let's say choices.length is 4, the initial list should be [false, false, false, false], let's say the user click on the last one, the list should turned into [false, false, false, true], but the bullet box doesn't update. Am I doing something wrong?
Widget getCheckboxList(WidgetRef ref, int start, int end) {
List<Widget> content = [];
final selectedProvider = StateProvider<List<bool>>(
(ref) => List.filled(choices.length, false));
for (int i = start; i <= end; i++) {
content.add(
Theme(
data: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
contentPadding: const EdgeInsets.symmetric(horizontal: 4),
visualDensity: const VisualDensity(horizontal: -2, vertical: -2),
title: Row(
children: [
const SizedBox(width: 5),
Text(choices[i][0]),
const Spacer(),
Text(choices[i][1] == 0 ? '免費' : '+ HK\$ ${choices[i][1]}'),
const SizedBox(width: 16),
],
),
activeColor: primaryColor,
value:
ref.watch(selectedProvider.select((selected) => selected[i])),
onChanged: (bool? picked) {
ref.read(selectedProvider.notifier).state[i] = picked!;
},
),
),
);
}
return Column(children: [...content]);
}