0
Checkbox(
                  onChanged: (bool value) {
                    setState(() {
                      isHighBloodDisease = value;
                    });
                  },
                  value: isHighBloodDisease,
                ),

this is my code and when i click the checkbox the check is not apper but when i close the dropDownList and reopen it the box i have choice is checked and I tryed to print the value and it works when i click it print true

return SizedBox(
      height: 50,
      width: 350,
      child: DropdownButtonFormField(
        iconSize: 50,
        iconEnabledColor: white,
        decoration: InputDecoration(
          hintText: 'الامراض المزمنة',
          hintStyle: TextStyle(
              fontSize: 23, fontWeight: FontWeight.bold, color: white),
          enabledBorder: OutlineInputBorder(
            borderSide: BorderSide(
              color: white,
            ),
            borderRadius: BorderRadius.circular(30.0),
          ),
        ),
        items: [
          DropdownMenuItem(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Text(
                  chronicDisease[0]['disease'],
                  style: textStyle,
                ),
                Checkbox(
                  value: isHeartDisease,
                  onChanged: (bool value) {
                    setState(() {
                      isHeartDisease = value;
                    });
                  },
                ),
              ],
            ),
          ),
DropdownMenuItem(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Text(
                  chronicDisease[4]['disease'],
                  style: textStyle,
                ),
                Checkbox(
                  onChanged: (bool value) {
                    setState(() {
                      isHighBloodDisease = value;
                    });
                  },
                  value: isHighBloodDisease,
                ),
              ],
            ),
          )
        ].toList(),
        onChanged: (value) {},
      ),
    );
  }
}
Ruba
  • 43
  • 7

2 Answers2

0

Try the below snippet code:

Create a statefullwidget for checkboxes:

class CheckboxSelectorPage extends StatefulWidget {
  bool isChecked = false;

  CheckboxSelectorPage(this.isChecked, {Key key}) : super(key: key);

  @override
  _CheckboxSelectorPageState createState() => _CheckboxSelectorPageState();
}

class _CheckboxSelectorPageState extends State<CheckboxSelectorPage> {
  @override
  Widget build(BuildContext context) {
    return Checkbox(
      onChanged: (bool value) {
        widget.isChecked = value;
        print("value: $value Is mounted: $mounted");
        setState(() {
          widget.isChecked = value;
        });
      },
      value: widget.isChecked,
    );
  }
}

Replace Checkbox widget by:

 CheckboxSelectorPage(),

This example has been tested in dartpad.dev

Jhakiz
  • 1,519
  • 9
  • 16
  • i have another prob I am developing an arabic app so i want the arrow of the dropDown in the next side how can I change the alignment? – Ruba Feb 02 '21 at 19:20
  • If it works you can mark it as accepted answer! – Jhakiz Feb 02 '21 at 19:53
0

To respond to your comment:

i have another prob I am developing an arabic app so i want the arrow of the dropDown in the next side how can I change the alignment?

Wrap DropdownButtonFormField with Directionality widget:

SizedBox(
    height: 50,
    width: 350,
        child: Directionality(
        textDirection: TextDirection.rtl,
            child: DropdownButtonFormField(
                 iconSize: 50,
                 decoration: InputDecoration(
                    hintText: 'الامراض المزمنة',

For more info take a look to this question: right-to-left (RTL) in flutter

Jhakiz
  • 1,519
  • 9
  • 16
  • this was ssoo helpful I tried to wrap it with another widget but it didn’t work , I didn’t hear about directionality widget before. However thankss alot – Ruba Feb 02 '21 at 21:18