check Box in drop down list flutter
1,059
You need to wrap all your checkboxes with StatefulBuilder
. The setState
that you're using only applies to the state of the widget containing all your dropdown menus but not the state of the checkbox.
Here how you can do it:
StatefulBuilder(
builder: (BuildContext context, StateSetter stateSetter) {
return Checkbox(
onChanged: (bool value) {
// note here we call stateSetter from the StatefulBuilder!
stateSetter(() {
// reverse the value
isFri = !isFri;
});
},
value: isFri,
);
}),
You've to do it for each CheckBox
widget.
Author by
Salem
Updated on December 29, 2022Comments
-
Salem over 1 year
I am using check Box in drop down Menu but when I chose the box nothing change unless closing the menu and open it again here is my code
items: [ DropdownMenuItem( child: Row( children: <Widget>[ Checkbox( onChanged: (bool value) { setState(() { isSat = value;});}, value: isSat,), Text( daysList[0]['days'],),],),), DropdownMenuItem( child: Row( children: <Widget>[ Checkbox( onChanged: (bool value) { setState(() { isFri = value;});}, value: isFri,), Text( daysList[6]['days'],),],),) ].toList(), onChanged: (value) {},),
-
EngineSense about 3 yearsAre you using statelesswidget?
-
Salem about 3 yearsno I am using StatefulWidget
-