【问题标题】:The dialog button is doing its job but the Alert box is not disappearing对话框按钮正在执行其工作,但警报框并未消失
【发布时间】:2021-08-29 11:05:32
【问题描述】:

我正在尝试从第二个屏幕转到主屏幕。 对话框按钮正在发挥作用,但 警告框没有消失。关于它如何工作的任何建议?

我正在为 AlrtBox 使用 rflutter_alert 包。

包含警报代码的第二个屏幕:

    setState(() {
      if (quizBrain.isFinished() == true) {
        var image = null;
        if (trueAns < 5) {
          image = AlertType.warning;
        } else {
          image = AlertType.success;
        }
        Alert(
          context: context,
          type: image,
          title: "RFLUTTER ALERT",
          desc: "Correct Answers: $trueAns \nFalse Answers: $falseAns.",
          buttons: [
            DialogButton(
              child: Text(
                "COOL",
                style: TextStyle(color: Colors.white, fontSize: 20),
              ),
              onPressed: () {
                Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (BuildContext context) => HomeRoute(),
                    ));

               /* Navigator.pop(context);
                Navigator.of(context)
                    .push(MaterialPageRoute(builder: (context) => HomeRoute()));*/
                setState(() {
                  quizBrain.reset();
                  scoreKeeper.clear();
                  trueAns = 0;
                  falseAns = 0;
                });
              },
              width: 120,
            )
          ],
        ).show();
      }   

Alert is not disappearing image

【问题讨论】:

  • 你的意思是当你点击酷按钮时对话框已经关闭?

标签: android flutter dart dart-pub


【解决方案1】:

Navigator.push()之前调用Navigator.of(context).pop()

【讨论】:

    【解决方案2】:

    你必须弹出它:

    onPressed: () {
                    Navigator.pop(context);
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                          builder: (BuildContext context) => HomeRoute(),
                        ));
      ...
    

    【讨论】:

    • 警报仍然没有消失,现在如果我再次尝试开始测验,它会显示此错误。Could not find a generator for route RouteSettings("/second", null) in the _WidgetsAppState
    【解决方案3】:

    使用这个:

    onPressed: () {
        Navigator.of(context).pop();
        Navigator.push(
            context,
            MaterialPageRoute(
            builder: (BuildContext context) => HomeRoute(),
        ));
    }
    

    【讨论】:

    • 警报仍然没有消失,现在如果我再次尝试开始测验,它会显示此错误。Could not find a generator for route RouteSettings("/second", null) in the _WidgetsAppState.
    猜你喜欢
    • 2011-11-01
    • 2015-08-27
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    相关资源
    最近更新 更多