Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to open another widget by clicking checkbox?

I want to create such logic: when checkbox is true, it returns widget with Image, then it false, image disappears. I have tried this code:

bool checkBoxValue = true;

Checkbox(
value: checkBoxValue,
onChanged: (bool? value) {
 setState(() {
checkBoxValue = value ?? true;
if (value == true) {
Image.network('https://imgd.aeplcdn.com/370x208/n/cw/ec/40432/scorpio-n-exterior-right-front-three-quarter-15.jpeg?isig=0&q=75')
}else if(value == false){
        return;}
});

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you may try out with below code

Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Checkbox(
                value: checkBoxValue,
                onChanged: (bool value) {
                  checkBoxValue = value;
                  setState(() {
                    
                  });
                }),
            checkBoxValue
                ? Image.network(
                    'https://imgd.aeplcdn.com/370x208/n/cw/ec/40432/scorpio-n-exterior-right-front-three-quarter-15.jpeg?isig=0&q=75')
                : Container()
          ],
        )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading