Reputation: 45
i followed a many a tutorials on YT on how to change the state of my check box when i tap on it , but i found nothing seems to work , or every solution ive tried when i click on checkbox no change is rendered to show its been touched
class _ViewMealState extends ConsumerState<ViewMeal> {
@override
Widget build(BuildContext context) {
bool check1 = false;
bool check2 = false;
bool check3 = false;
return Scaffold(
body: SingleChildScrollView(
child: (Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
CheckboxListTile(
title: Text(widget.documentSnapshot['Choice_1']),
value: check1,
onChanged: (newVal) {
setState(() {
newVal = check1;
});
}),
CheckboxListTile(
title: Text(widget.documentSnapshot['Choice_2']),
value: check2,
onChanged: (newVal) {
setState(() {
newVal = check2;
});
}),
CheckboxListTile(
title: Text(widget.documentSnapshot['Choice_3']),
value: check3,
onChanged: (newVal) {
setState(() {
newVal = check3;
});
}),
])),
),
);
Upvotes: 0
Views: 65
Reputation: 3678
You have the assignment statement order wrong.
Instead of newVal = check1
, you must do check1 = newVal
. The way you currently have it changes the newVal
parameter variable's value, rather than the value of check1
.
Upvotes: 1