Home > Mobile >  How to check phone lock screen state?
How to check phone lock screen state?

Time:08-22

Is there any way to check phone is lock/unlock state from Flutter app?

I've used screen_state: ^2.0.0, but it didn't work for ios

CodePudding user response:

Give the package is_lock_screen a try:

https://pub.dev/packages/is_lock_screen

As per the linked documentation, you can check if the screen is locked as follows:

bool? result = await isLockScreen();

CodePudding user response:

You can use is_lock_screen: ^2.0.0

bool? result = await isLockScreen();

@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');
  }
}
  • Related