elise-ng/flutter_is_lock_screen
기기가 잠금 화면에 있는지 확인하는 Flutter 플러그인입니다. 앱이 화면 잠금으로 인해 백그라운드로 전환되었는지 또는 앱을 떠났는지 여부를 판단하는 데 유용합니다.
- Stars
- 4
- Forks
- 34
- 최근 푸시(UTC)
- 2023. 3. 13.
- 프로젝트 상태
- 활성
기술 주제
사용 중인 의존성
의존성 목록 2 개
- flutter
{"sdk":"flutter"} - flutter_test개발 의존성
{"sdk":"flutter"}
원본 README
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
README 펼치기 / 접기
is_lock_screen
Detects if device is locked. Useful for determining whether app entered background due to locking screen or leaving app.
Usage
Import library and call the following method.
Note that this only works on physical device for iOS.
bool? result = await isLockScreen();
You will probably observe the AppLifecycleState with a WidgetsBindingObserver and call this when app is in background:
@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.inactive) {
print('app inactive, is lock screen: ${await isLockScreen()}');
} else if (state == AppLifecycleState.resumed) {
print('app resumed');
}
}
See example app code for details
Why this plugin?
An alternative to this plugin is hardware_buttons, which uses non-public API (com.apple.springboard.lockcomplete) on iOS to detect lock button usage and violates App Store requirements.
To circumvent this issue, this plugin detects whether iOS device is in lock screen by checking if screen brightness is 0.0 (the user-adjustable minimum is >0.01).
On android, this plugin uses KeyguardManager and PowerManager API to check if device is secured or display is off as suggested in this gist. A similar flow was tested on iOS with LocalAuthentication and UIApplication.shared.isProtectedDataAvailable but failed due to long grace period of the system lock down. The flag always return true the moment screen is locked.