Flutter Navigator.of(context.pop();使整个屏幕消失,而不是弹出窗口
在我的Flutter Navigator.of(context.pop();使整个屏幕消失,而不是弹出窗口,flutter,dart,Flutter,Dart,在我的flatter应用程序中,当用户按下按钮时,我想用两个按钮显示弹出窗口,我使用以下代码: class ProfileScreen extends StatefulWidget { @override _ProfileScreenState createState() { return _ProfileScreenState(); } } class _ProfileScreenState extends State<ProfileScreen> { @o
flatter
应用程序中,当用户按下按钮时,我想用两个按钮显示弹出窗口,我使用以下代码:
class ProfileScreen extends StatefulWidget {
@override
_ProfileScreenState createState() {
return _ProfileScreenState();
}
}
class _ProfileScreenState extends State<ProfileScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 400),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
...[
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: () {
showAlertDialog(context);
},
child: Text('Remove account'),
),
),
它工作正常,弹出窗口显示正确,但当我单击“取消”时,弹出窗口保持在前面,但其下方的屏幕消失(并保持黑色)。为什么会这样?我怎样才能修好它呢?谢谢 Navigator.of(上下文,rootNavigator:true).pop() 这也可能有帮助:
showAlertDialog(BuildContext context) {
// set up the buttons
Widget cancelButton = FlatButton(
child: Text("Cancel"),
onPressed: () {
Navigator.of(context).pop();
},
);
Widget continueButton = FlatButton(
child: Text("Continue"),
onPressed: () {},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Text("AlertDialog"),
content: Text("Would you like to continue learning how to use Flutter alerts?"),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}