时间计数继续更新时,当应用程序锁定在颤音中

发布于 2025-02-04 06:58:18 字数 41 浏览 2 评论 0 原文

我该如何计算应用程序锁定时的时间,因为我需要在第二次结束后导航到屏幕

How can I count time in when the app is locked because I need to navigate to the screen after the second is over can anyone help me in this task

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

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

发布评论

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

评论(1

谁与争疯 2025-02-11 06:58:18

首先,您需要确定lifecylestate应用程序是否锁定。您可以查看
如何使用它是:将与widgetsbindingobserver 添加到您的状态小部件

class _MyState extends State<MyStatefulWidget>
    with WidgetsBindingObserver

,然后使用 didchangeapplifecyclestate 这样:

    @override
      void didChangeAppLifecycleState(AppLifecycleState state) {
        super.didChangeAppLifecycleState(state);
        switch (state) {
          case AppLifecycleState.resumed:    
            //make your operations        
            break;
          case AppLifecycleState.inactive: 
//make your operations          
            break;
          case AppLifecycleState.paused: 
//make your operations           
            break;
          case AppLifecycleState.detached: 
//make your operations          
            break;
          default:
            break;
        }
      }

到达计数时间时,查看 flutter_count_count_countdown_timer 软件包 https://pab.dev/packages/plutter_coutts_count_countdowndown_timer
实现它,当应用程序暂停时,启动计时器。完成后,进行操作并在简历下,重置您的倒数计时器。请注意,您只需要在1个状态下的1个中写下它,它在全球范围内起作用。

First of all, you need to determine the lifecylestate if app is locked or not. You can have a look at https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver/didChangeAppLifecycleState.html
How you use it is: Add with WidgetsBindingObserver to your Stateful Widget like

class _MyState extends State<MyStatefulWidget>
    with WidgetsBindingObserver

then use didChangeAppLifecycleState like this:

    @override
      void didChangeAppLifecycleState(AppLifecycleState state) {
        super.didChangeAppLifecycleState(state);
        switch (state) {
          case AppLifecycleState.resumed:    
            //make your operations        
            break;
          case AppLifecycleState.inactive: 
//make your operations          
            break;
          case AppLifecycleState.paused: 
//make your operations           
            break;
          case AppLifecycleState.detached: 
//make your operations          
            break;
          default:
            break;
        }
      }

When coming to counting time, look at flutter_countdown_timer package https://pub.dev/packages/flutter_countdown_timer
Implement it and when app is paused, start your timer. When it finishes, do your operations and under resume, reset your countdown timer. Note that, you only need to write this in 1 of your StatefulWidgets, it works globally.

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