I'm trying to add a Checkbox (or CheckboxListTile) to the content of an AlertDialog. The checkbox is shown with the correct initial value, however tapping the Checkbox doesn't check/uncheck it.
This is my (simplified) code:
class MyState extends State<MyStatefulWidget> {
bool checked = true;
_MyState() {
_showDialog();
}
Future<Null> _showDialog() async {
return showDialog(
context: context,
child: new AlertDialog(
content: new Checkbox(
value: checked,
onChanged: (bool value) {
setState(() {
checked = value;
});
},
),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop(checked);
},
child: new Text('OK')
)
],
);
}
}
It works when I add the Checkbox directly to the main layout, but not inside the AlertDialog. What is going on here? How can this be solved?
Aucun commentaire:
Enregistrer un commentaire