我需要处理一个表单输入小部件上的返回按钮按下事件。以下是我实现的WillPopScope的onWillPop方法:
Future<bool> _onWillPop() {
if (changed) {
return showDialog(
context: context,
builder: (context) => new AlertDialog(
title: new Text('Save'),
content: new Text("Do you want to save the changes?"),
actions: <Widget>[
new FlatButton(
onPressed: () => Navigator.of(context).pop(true),
child: new Text('No'),
),
new FlatButton(
onPressed: () {
Navigator.of(context).pop(false);
saveMeeting();
},
child: new Text('Yes'),
),
],
),
) ??
false;
} else {
print("No changes");
Navigator.of(context).pop(true);
//return some future null from here ????
}
}
这部分代码是有效的,但会出现异常:
[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 7374): Failed assertion: boolean expression must not be null
我该如何正确实现这个?
if
外部或者else
内部返回 bool 值。 - Blasanka