简体   繁体   English

令人敬畏的对话框未在颤振应用程序中关闭

[英]Awesome Dialog not closing in flutter app

I am using the Awesome Dialog in my flutter application but when I click on OK it just navigates to another screen and doesn't close.我在我的 flutter 应用程序中使用Awesome Dialog但是当我点击 OK 它只是导航到另一个屏幕并且没有关闭。 here is my code.这是我的代码。

    Future requestSupport(String userid, String supportType, String duration) async {
        final response =
  await http.post('http://url/api/Support',
  headers: {"Content-Type": "application/json", 
             'Accept': 'application/json',},
  body: json.encode({'userid' : userid ,  'supportType' : supportType, 'duration' : duration}));

 if (response.statusCode == 200) {

 showAlertDialogOnOkCallback();  

    }



 }
 void showAlertDialogOnOkCallback() {
        AwesomeDialog(
              context: context,
              animType: AnimType.LEFTSLIDE,
              dialogType: DialogType.SUCCES,
              tittle: 'Success',
              desc:
                  'You have been entered into the queue, press OK to go back.',
              btnOkOnPress:  () {  },
              btnOkIcon: Icons.check_circle,
              onDissmissCallback: () {
                debugPrint('Dialog Dissmiss from callback');
              }).show();
 }

  }

Although doc for this library says,虽然这个库的文档说,

Function that handle click of positive Button, closing the dialog is handled internally.处理正按钮点击、关闭对话框的功能是内部处理的。


UPDATE : I have tried it myself and it works fine approach I used, I took a button to open dialog,更新:我自己试过了,我使用的方法很好,我用一个按钮打开对话框,

     RaisedButton(
          child: Text("ok",),
          onPressed: () {
              open();
          },
        ),

Since dialog closing is handled by default by the library I used Navigator.pop(context);由于对话框关闭是由库默认处理的,所以我使用了Navigator.pop(context); this to go back to the previous screen using btnOkOnPress使用btnOkOnPress返回上一屏幕

  void open() {
    AwesomeDialog(
        context: context,
        dialogType: DialogType.INFO,
        animType: AnimType.BOTTOMSLIDE,
        tittle: 'Dialog Title',
        desc:
            'Dialog description here',
        btnCancelOnPress: () {},
        btnOkOnPress: () {
          Navigator.pop(context);
        }).show();
  }

Note: I navigate to screen which is having dialog by Navigator.pushNamed .注意:我导航到Navigator.pushNamed有对话框的屏幕。 So if Navigator.pop(context);所以如果Navigator.pop(context); is called it comes back to this screen only.被称为它只返回到这个屏幕。

Navigator.pushNamed(context, RouteName.ReportScreen);

Output:输出:

在此处输入图片说明

I am unable to replicate your issue.我无法复制您的问题。 I used a simple RaisedButton upon tapping on it opens AwesomeDialog .我在点击它时使用了一个简单的RaisedButton打开AwesomeDialog Then tapping on OK button of the dialog closes it properly.然后点击对话框的OK按钮将其正确关闭。 I also tested by adding a navigation upon ok button tap that closes the dialog and navigates to next screen.我还通过在确定按钮点击时添加导航来关闭对话框并导航到下一个屏幕来进行测试。 Code I used:我使用的代码:

body: Center(
        child: RaisedButton(
          onPressed: () {
            _openDialog();
          },
          child: Text('Tap')
        )
      )

void _openDialog() {
    AwesomeDialog(
        context: context,
        animType: AnimType.LEFTSLIDE,
        dialogType: DialogType.SUCCES,
        tittle: 'Success',
        desc:
        'You have been entered into the queue, press OK to go back.',
        btnOkOnPress:  () {
          Navigator.push(context, MaterialPageRoute(builder: (context) => PageB()));
        },
        btnOkIcon: Icons.check_circle,
        onDissmissCallback: () {
          debugPrint('Dialog Dissmiss from callback');
        }).show();
  }

Console output:控制台输出:

I/flutter (13279): Dialog Dissmiss from callback
I/flutter (13279): Dialog Dissmiss from callback

Hope this helps.希望这可以帮助。

I am trying to use the Awesome Dialogue and then use the property "useRootNavigator" and set it to true.我正在尝试使用Awesome Dialogue ,然后使用属性“useRootNavigator”并将其设置为 true。

AwesomeDialog(
        useRootNavigator: true,
        context: context,
        animType: AnimType.LEFTSLIDE,
        headerAnimationLoop: false,
        dialogType: DialogType.SUCCES,
        title: 'Go',
        desc: 'Continue Adding ',
        btnOkOnPress: () {
          Navigator.push(
              context, MaterialPageRoute(builder: (context) => Page2()));
        },
        btnOkIcon: Icons.receipt,
        onDissmissCallback: () {
          debugPrint('Dialog Dissmiss from callback');
        },
        btnOkText: "Add More members",
        btnCancelOnPress: () {
          Navigator.push(
              context, new MaterialPageRoute(builder: (context) => Home()));
        },
        btnCancelIcon: Icons.home,
        btnCancelText: "Go to Home Page")
      ..show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM