bool isChecked = false;
class _TasksTileState extends State<TasksTile> {
bool isChecked = false;
@override
Widget build(BuildContext context) {
print('$isChecked is the value of isChecked');
return CheckboxListTile(
title: Text('this is the Task 1.',style: TextStyle(
decoration: isChecked? TextDecoration.lineThrough: null,
),),
value: isChecked,
onChanged: (newValue) {
setState(() {
print('$newValue is the value of newValue');
isChecked = newValue;
});
},
);
}
}
2
Answers
problem is
onChanged: (newValue)
, newValue is nullable, and yourisChecked
variable is not. you cannot assign nullable variable to non null. Either make isChecked nullable (bool? isChecked = false
) or supply default value when assigning:isChecked = newValue ?? false;
Here is correct way to use bool all you need is to add null operator