Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Navigator.of(context.pop();使整个屏幕消失,而不是弹出窗口_Flutter_Dart - Fatal编程技术网

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;
      },
    );
  }