Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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 颤振-显示对话框不显示对话框_Flutter - Fatal编程技术网

Flutter 颤振-显示对话框不显示对话框

Flutter 颤振-显示对话框不显示对话框,flutter,Flutter,以下是my_showDialog函数: Future<void> _showDialog({BuildContext context, String msg, String title}) async { showDialog<bool>( context: context, builder: (context) { return AlertDialog( title: Text(title),

以下是my_showDialog函数:

Future<void> _showDialog({BuildContext context, String msg, String title}) async {
  showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text(title),
          content: Text(msg),
          actions: [
            FlatButton(
              child: Text('Ok'),
              onPressed: () => Navigator.of(context).pop(true),
            ),
          ],
        );
      });
}
如果发生错误,将显示错误对话框。 但如果没有错误,则不会显示“成功”对话框

如果这条线

Navigator.pop(context);
在显示的“成功”对话框中被注释掉


在返回上一屏幕之前,我需要显示“成功”对话框。

然后您应该等待对话框上的“关闭”按钮响应,如:

Future _showDialog({BuildContext context, String msg, String title}) async {
return await showDialog<bool>(
  context: context,
  builder: (context) {
    return AlertDialog(
      title: Text(title),
      content: Text(msg),
      actions: [
        FlatButton(
          child: Text('Ok'),
          onPressed: () => Navigator.of(context).pop(true),
        ),
      ],
    );
    });
}
Future _showDialog({BuildContext context, String msg, String title}) async {
return await showDialog<bool>(
  context: context,
  builder: (context) {
    return AlertDialog(
      title: Text(title),
      content: Text(msg),
      actions: [
        FlatButton(
          child: Text('Ok'),
          onPressed: () => Navigator.of(context).pop(true),
        ),
      ],
    );
    });
}
if (result.contains("Error")) {
      // Error!!! 
      // Show ERROR dialog box.

      _showDialog(context: context, title: "Error", msg: result);

    } else {
      // Success!!! 
      // Show SUCCESS dialog box, then return to the previous screen.
      
      await _showDialog(context: context, title: "Success", msg: "Success!");

      Navigator.pop(context); // return to the previous screen

    }