Flutter 颤振:如果设备处于锁定屏幕中,则AppLifecycleState不工作

Flutter 颤振:如果设备处于锁定屏幕中,则AppLifecycleState不工作,flutter,dart,Flutter,Dart,我使用AppLifeycleState来检测用户使用我的应用程序时的行为。为了检测我的应用程序未被使用,我使用 AppLifecycleState.暂停 AppLifecycleState.inActive AppLifecycleState.detached 因为我想检测我的应用程序是否有1秒未被使用,所以我会将用户抛出确认指纹(如Whatsapp)。一切都很好,如果我的应用程序没有被使用,我可以检测到,如果用户按下最近的应用程序,主页按钮,并抛出用户确认指纹,如果用户再次回来。 但问题是

我使用AppLifeycleState来检测用户使用我的应用程序时的行为。为了检测我的应用程序未被使用,我使用

  • AppLifecycleState.暂停
  • AppLifecycleState.inActive
  • AppLifecycleState.detached
因为我想检测我的应用程序是否有1秒未被使用,所以我会将用户抛出确认指纹(如Whatsapp)。一切都很好,如果我的应用程序没有被使用,我可以检测到,如果用户按下最近的应用程序,主页按钮,并抛出用户确认指纹,如果用户再次回来。 但问题是,当设备屏幕锁定后又重新打开时,用户并没有投掷确认指纹。 我当然可以在控制台中看到我的应用程序是AppLifecycleState.pausedAppLifecycleState.inActive,但奇怪的是,如果我在IDE中热重新加载ctrl+s,我的应用程序就会抛出确认指纹

为什么会这样

工作1

工作2

不行!

已经在真实设备上进行了测试(Redmi注4),但仍然无法工作

源代码AppLifecycleState
@override
  void didChangeAppLifecycleState(AppLifecycleState state) async {
    setState(() => _appLifecycleState = state);
    if (widget.userBox == null) {
      print('Box User Null');
      return;
    } else {
      if (widget.userModelHive.fingerPrint || widget.userModelHive.pinCode) {
        if (_appLifecycleState != AppLifecycleState.resumed) {
          //? Berarti Lifecylenya InActive , Paused , Detached , Maka Simpan Waktu Keluarnya
          final actionBox = await repository.changeDateExit(
            userModelHive: UserModelHive()
              ..id = widget.userModelHive.id
              ..giverName = widget.userModelHive.giverName
              ..pinCode = widget.userModelHive.pinCode
              ..fingerPrint = widget.userModelHive.fingerPrint
              ..darkMode = widget.userModelHive.darkMode
              ..tokenExpiry = true
              ..durationToken = widget.userModelHive.durationToken
              ..dateExit = DateTime.now()
                  .add(Duration(seconds: widget.userModelHive.durationToken)),
          );
          print(state);
          return actionBox;
        } else {
          print('Resumed Lifecycle');
        }
      }
    }
    if (mounted) {
      setState(() {});
    }
    super.didChangeAppLifecycleState(state);
  }