Обнаружить нажатие кнопки назад, когда диалоговое окно открыто во флаттере - PullRequest
0 голосов
/ 05 ноября 2018

Я создаю приложение во флаттере, в котором мне нужно отобразить диалоговое окно с предупреждением. И это не недопустимый диалог. Но когда я нажимаю кнопку "Назад" на Android, он уходит. Я пытался использовать виджет WillPopScope для обнаружения события обратного нажатия. Я могу обнаружить нажатие кнопки «Назад» с помощью WillPopScope, но это не работает, когда открыто диалоговое окно. Любое предложение и руководство будет действительно полезным. Спасибо.

Фрагмент создания диалога:

void buildMaterialDialog(
  String dialogTitle,
  String dialogContent,
  String negativeBtnText,
  String positiveBtnText,
  String positiveTextUri) {

showDialog(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return new AlertDialog(
        title: new Text(dialogTitle),
        content: new Text(dialogContent),
        actions: <Widget>[
          new FlatButton(
            onPressed: () {
              //Function called
              _updateDialogNegBtnClicked(isCancelable);
            },
            child: new Text(negativeBtnText),
          ),
          new FlatButton(
            onPressed: () => launch(positiveTextUri),
            child: new Text(positiveBtnText),
          ),
        ],
      );
    });}

1 Ответ

0 голосов
/ 05 ноября 2018

Кнопка «Назад» не закрывает диалог.

showDialog(
                            context: context,
                            barrierDismissible: false,
                            builder: (BuildContext context) {
                              return WillPopScope(
                                onWillPop: () {},
                                child: new AlertDialog(
                                  title: new Text('Title'),
                                  content: new Text('This is Demo'),
                                  actions: <Widget>[
                                    new FlatButton(
                                      onPressed: () {
                                        //Function called
                                      },
                                      child: new Text('Ok Done!'),
                                    ),
                                    new FlatButton(
                                      onPressed: () {
                                        Navigator.pop(context);
                                      },
                                      child: new Text('Go Back'),
                                    ),
                                  ],
                                ),
                              );
                            });
...