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 :
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()
],
)