相关疑难解决方法(0)

如何在 Flutter App 中按时间注销?

如果用户在登录后对应用程序没有反应或不活动超过 5 分钟,我需要从应用程序中注销用户。该应用程序将转到主登录页面。

我尝试在这里实现给定的解决方案,但没有成功。请帮助我如何实现这一目标。

我的代码

    class AppRootState extends State<AppRoot> {
    
          Timer _rootTimer;
        
          @override
          void initState() {
            // TODO: implement initState
            super.initState();
            initializeTimer();
          }
        
          void initializeTimer() {
           
            const time = const Duration(minutes: 5);
            _rootTimer = Timer(time, () {
              logOutUser();
            });
          }
        
          void logOutUser() async {
           
             // Log out the user if they're logged in, then cancel the timer.
            // You'll have to make sure to cancel the timer if the user manually logs out
            //   and to call _initializeTimer …
Run Code Online (Sandbox Code Playgroud)

timer dart flutter

2
推荐指数
1
解决办法
3815
查看次数

标签 统计

dart ×1

flutter ×1

timer ×1