Git Product home page Git Product logo

giorgio79 / flutter_is_lock_screen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jpm84/flutter_is_lock_screen

0.0 0.0 0.0 112 KB

Flutter Plugin to detect if device is in lock screen. Useful for determining whether app entered background due to locking screen or leaving app.

Home Page: https://pub.dev/packages/is_lock_screen

License: MIT License

Ruby 21.17% Objective-C 6.36% Kotlin 31.12% Dart 21.33% Swift 9.65% HTML 10.37%

flutter_is_lock_screen's Introduction

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.

flutter_is_lock_screen's People

Contributors

elise-ng avatar jpm84 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.