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.

Share:
1,059
Salem
Author by

Salem

Updated on December 29, 2022

Comments

  • Salem
    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
      EngineSense about 3 years
      Are you using statelesswidget?
    • Salem
      Salem about 3 years
      no I am using StatefulWidget