An open API service indexing awesome lists of open source software.

https://github.com/mrrhak/screen_lock_detector

A Flutter plugin that enables your app to detect screen lock and unlock events across Android and iOS platforms. The plugin provides native event callbacks for both Android and iOS, making it easy to respond to lock screen changes — such as pausing sensitive activities, logging out users, or triggering background operations.
https://github.com/mrrhak/screen_lock_detector

device-lock lockscreen screen-lock screen-lock-detector

Last synced: about 2 months ago
JSON representation

A Flutter plugin that enables your app to detect screen lock and unlock events across Android and iOS platforms. The plugin provides native event callbacks for both Android and iOS, making it easy to respond to lock screen changes — such as pausing sensitive activities, logging out users, or triggering background operations.

Awesome Lists containing this project

README

          


ðŸŠī Screen Lock Detector ðŸŠī




A Flutter plugin that enables your app to detect screen lock and unlock events across Android and iOS platforms.

The plugin provides native event callbacks for both Android and iOS, making it easy to respond to lock screen changes — such as pausing sensitive activities, logging out users, or triggering background operations.









buy me a coffee


Ko-fi





Pub Package


Pub Likes


Pub Score


Pub Monthly Downloads

Star on Github
Forks on Github

Contributors


Build Status


Code size


Platform

---


screen lock detector preview

## How it's work?
For iOS, this plugin just listen to `UIApplication` notification center API:
- `protectedDataWillBecomeUnavailableNotification` to detect is **locked**
- `protectedDataDidBecomeAvailableNotification` to detect is **unlocked**

For Android, this plugin uses `KeyguardManager` and `PowerManager` API to check if device is secured lock or display is off combine with listener on `Intent` actions:
- `ACTION_SCREEN_OFF` to detect is **locked**
- `ACTION_USER_PRESENT` to detect is **unlocked**

## Features
- ✅ Detect when the screen is locked.
- ✅ Detect when the screen is unlocked.
- ✅ Supports both event streams and manual status checks.
- ✅ Works on Android and iOS.

> **Note**
> This plugin does not work on simulators or emulators because it relies on native system events that are not available in these virtual environments. Please test on a physical device.

## Installation
Add `screen_lock_detector` as a dependency in your `pubspec.yaml` file:
```sh
flutter pub add screen_lock_detector
```

## Usage
### Import Plugin
```dart
import 'package:screen_lock_detector/screen_lock_detector.dart';
```

### Listen to Event Stream
```dart
ScreenLockDetector.statusStream.listen((status) {
print("Screen status: $status");
if (status == ScreenStatus.locked) {
// Do something here when screen is locked
} else if (status == ScreenStatus.unlocked) {
// Do something here when screen is unlocked
}
});
```

### Or Manual Status Check
```dart
final status = await ScreenLockDetector.checkScreenStatus();
print("Screen status: $status");
```

See the [example](https://github.com/mrrhak/screen_lock_detector/tree/master/example) for runnable examples of various usages.

## Bugs or Requests

If you encounter any problems feel free to open an [issue](https://github.com/mrrhak/screen_lock_detector/issues/new?template=bug_report.md). If you feel the library is missing a feature, please raise a [ticket](https://github.com/mrrhak/screen_lock_detector/issues/new?template=feature_request.md) on GitHub and I'll look into it. Pull request are also welcome.

See [Contributing.md](https://github.com/mrrhak/screen_lock_detector/blob/master/CONTRIBUTING.md).

## Support
Don't forget to give it a like 👍 or a star ⭐

## Activities
![Alt](https://repobeats.axiom.co/api/embed/35602a25c897379cbb5233a066c030c0c082b45d.svg "Repobeats analytics image")