0

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;
                });
              }),
        ])),
      ),
    );

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

also tried it this way still not sure why it gives the same problem ? I then tried to either make 'check1' nullable or give 'newVal' a check operator (as require4d by editor) it still produced the same results ,neither seemed to be working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.