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;
});
},
),
3
Answers
This will be the widget structure
More about StatefulWidget
You should put the
CardWidget
inside a class that extendsStatefulWidget
:now with
_CardWidgetState
you can usesetState
.happy coding….
CarWidget() has to be written liket this: