【问题标题】:ShowDialog did not pop outShowDialog 没有弹出
【发布时间】:2022-12-02 18:54:30
【问题描述】:

i have created global method that call showDialog, whenever i call it, it wont come out if i put Navigator.pop(context) , if i remove the navigator it will come out. I cannot close the errordialog if i dont have the navigator. Did i do something wrong? below is my code

class GlobalMethod {
  static void showErrorDialog(
      {required String error, required BuildContext ctx}) {
    showDialog(
        context: ctx,
        builder: (context) {
          return AlertDialog(
            title: Row(children: [
              Padding(
                padding: EdgeInsets.all(8.0),
                child: Icon(
                  Icons.logout,
                  color: Colors.grey,
                  size: 35,
                ),
              ),
              Padding(
                padding: EdgeInsets.all(8.0),
                child: Text(\'Error Occured\'),
              ),
            ]),
            content: Text(error,
                style: TextStyle(
                    color: Colors.black,
                    fontSize: 20,
                    fontStyle: FontStyle.italic)),
            actions: [
              TextButton(
                onPressed: () {
                  Navigator.canPop(context) ? Navigator.canPop(context) : null;
                },
                child: Text(
                  \'Okay\',
                  style: TextStyle(
                    color: Colors.red,
                  ),
                ),
              )
            ],
          );
        });
  }

This is example when i call the method. If i remove the Navigator.pop the error dialog will pop out, if i put the navigator.pop nothing will come out

else if (balance < price! ){
      GlobalMethod.showErrorDialog(error: \"you dont have enough balance , please top up first\", ctx: context);
      Navigator.pop(context);
      
    }
  • Remove Navigator.pop(context); after the dialog
  • Why are you using pop after showing you dialog? did you put there because you want to close your page after came back from dialog?
  • @SparkoSol if i remove the Navigator.pop , i cant close the error dialog
  • @eamirho3ein i want to close the error dialog

标签: android ios flutter dart


【解决方案1】:
【解决方案2】:
猜你喜欢
  • 2021-02-11
  • 2014-06-25
  • 2021-10-30
  • 2023-03-09
  • 2014-09-11
  • 2012-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多