dimanche 26 mars 2023

Flutter: The function setState isn't defined and I am using a Stateful widget

I'll put the code briefly to show how everything is meant to flow from the Stateful widget.

I basically want the checkbox on my card to change state when the user clicks on it.

Error message: The function 'setState' isn't defined.

I did my research and I know it only works under a stateful widget. My widget tree is under a StatefulWidget so it should work but isn't.

class MyAppState extends StatefulWidget{

       Scaffold{
          //calls CardWidget to build individual cards for my list
       }       
}

     Widget CardWidget{

          Return Inkwell {
              Container{
                   
                        child: Checkbox(
                             value: item.checkBox,
                             onChanged: (bool? value) {
                             item.checkBox = !value!;

                             setState(() {
                             item.checkBox;
                             });
                           },
                       ),



Aucun commentaire:

Enregistrer un commentaire