如何在5秒后停止加载器

发布于 2025-02-10 09:41:08 字数 1160 浏览 3 评论 0原文

我正在尝试在按钮上单击整个屏幕上显示加载程序,并在5秒钟显示对话框后想要停止加载程序。这是我的代码

          setState(() {
              _isLoading = true;
            });
            _isLoading
                ? showDialog(
                    context: context,
                    barrierDismissible: false,
                    builder: (BuildContext context) {
                      return WillPopScope(
                        onWillPop: () async {
                          return false;
                        },
                        child: Center(
                          child: CircularProgressIndicator(
                            color: Apptheme.primaryColor,
                          ),
                        ),
                      );
                    })
                : null;
            await Future.delayed(const Duration(seconds: 5), () {
              AppDialogs()
                  .showInfoDialogue(context, "Sorry all drivers are busy!", () {
                Navigator.pop(context);
              });
            });
            setState(() {
              _isLoading = false;
            });

在按钮上调用此代码,它在5秒后显示对话框,但不会停止加载程序。请帮助我做错了什么。

I'm trying to display the loader on whole screen on button click and after 5 seconds displaying a dialogue box an want to stop the loader. here is my code

          setState(() {
              _isLoading = true;
            });
            _isLoading
                ? showDialog(
                    context: context,
                    barrierDismissible: false,
                    builder: (BuildContext context) {
                      return WillPopScope(
                        onWillPop: () async {
                          return false;
                        },
                        child: Center(
                          child: CircularProgressIndicator(
                            color: Apptheme.primaryColor,
                          ),
                        ),
                      );
                    })
                : null;
            await Future.delayed(const Duration(seconds: 5), () {
              AppDialogs()
                  .showInfoDialogue(context, "Sorry all drivers are busy!", () {
                Navigator.pop(context);
              });
            });
            setState(() {
              _isLoading = false;
            });

calling this code on button click, it shows the dialogue box after 5 seconds but not stop the loader. kindly help where i'm doing wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇柔作态 2025-02-17 09:41:08

调用showdialog将加载程序安装在屏幕上,如果您在导航器上有一个简单的设置.pop()您显示对话框。需要修改:

await Future.delayed(const Duration(seconds: 5), () {
    Navigator.of(context).pop();
    AppDialogs().showInfoDialogue(context, "Sorry all drivers are busy!", () {
      Navigator.pop(context);
    });
});

Once you call showDialog the loader is mounted on the screen and it will not disappear, if you have a simple setup calling .pop() on the navigator will remove your loader before you show the dialog. Modification required:

await Future.delayed(const Duration(seconds: 5), () {
    Navigator.of(context).pop();
    AppDialogs().showInfoDialogue(context, "Sorry all drivers are busy!", () {
      Navigator.pop(context);
    });
});
-小熊_ 2025-02-17 09:41:08

您可以在Instate事件

Future.delqyed(持续时间:持续时间(秒:5),(){showdialog(((buildContext上下文,widget child)=> dialog());
});

你可以尝试这个

You can define thai cde in instate event

Future.delqyed(duration:Duration(seconds:5),(){showdialog((BuildContext context,Widget child)=>Dialog());
});

You can try this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文