简体   繁体   中英

How to create a clickable checkbox in flutter

Hi I want a clickable checkbox there are two checkboxes in a row of my code i want them to be clickable

secondly when either one of them is clicked the second one should be disabled automatically.

Here is my code:

 Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded(child: CheckboxListTile( title: Text("Yes"), controlAffinity: ListTileControlAffinity.leading, value: null, onChanged: (bool value) { }, ), ), Expanded(child: CheckboxListTile( title: Text("No"),value:false,onChanged:(bool value) {}, controlAffinity: ListTileControlAffinity.leading, ), ) ], ),

I am trying to acheive this but unable to do so any help would be highly appreciated

You should try this

bool firstCheck = false;
bool secondCheck = false;
Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(child:
                CheckboxListTile(
                  title: Text("Yes"),

                  controlAffinity: ListTileControlAffinity.leading, value: firstCheck, onChanged: (bool value) {
                    setState(() {
                      firstCheck = value;
                      secondCheck = !value;
                    });
                },
                ),
                ),
                Expanded(child:
                CheckboxListTile(
                  title: Text("No"),value:secondCheck,onChanged:(bool value) {
                    setState(() {
                      firstCheck = !value;
                      secondCheck = value;
                    });
                },
                  controlAffinity: ListTileControlAffinity.leading,
                ),
                )

              ],
            ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM