我试图创建一个退出对话框,但由于空错误而无法完成它。
Future<bool> exitDialog () async {
return showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text('Wanna Exit?'),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context, false), // passing false
child: Text('No'),
),
FlatButton(
onPressed: () => Navigator.pop(context, true), // passing true
child: Text('Yes'),
),
],
);
}).then((exit) async {
if (exit == null) return false;
if (exit) {
// user pressed Yes button
} else {
// user pressed No button
}
});
}