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