很棒的对话框未在Flutter应用中关闭

问题描述 投票:0回答:2

我在flutter应用程序中使用了Awesome Dialog,但是当我单击OK时,它仅导航到另一个屏幕并且没有关闭。这是我的代码。

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

  }
flutter dart
2个回答
1
投票

我无法复制您的问题。我在点击RaisedButton时使用了一个简单的AwesomeDialog。然后点击对话框的OK按钮将其正确关闭。我还通过在单击确定按钮时添加导航功能进行了测试,该功能可以关闭对话框并导航至下一个屏幕。我使用的代码:

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

控制台输出:

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

希望这会有所帮助。


0
投票

尽管此库的doc说,

处理肯定按钮单击,关闭对话框的功能在内部处理。


UPDATE:我自己尝试过,并且使用的方法效果很好,我按了一个按钮打开对话框,

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

由于对话框的关闭默认是由我使用Navigator.pop(context);的库处理的,因此使用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();
  }

注意:我导航到Navigator.pushNamed对话框的对话框。因此,如果调用Navigator.pop(context);,则仅返回此屏幕。

Navigator.pushNamed(context, RouteName.ReportScreen);

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.