screen_lock_detector 1.0.0 copy "screen_lock_detector: ^1.0.0" to clipboard
screen_lock_detector: ^1.0.0 copied to clipboard

A Flutter plugin to detect screen lock/unlock events across Android and iOS platforms.

example/lib/main.dart

// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';

import 'package:screen_lock_detector/screen_lock_detector.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();

    ScreenLockDetector.statusStream.listen((status) {
      // ignore: avoid_print
      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
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Screen Lock Detector')),
        body: Center(
          child: Column(
            children: [
              ElevatedButton(
                onPressed: () async {
                  final status = await ScreenLockDetector.checkScreenStatus();
                  // ignore: avoid_print
                  print("==> Screen status: $status");
                },
                child: const Text('Get Screen Status'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
7
likes
160
points
109
downloads
screenshot

Publisher

verified publishermrrhak.com

Weekly Downloads

A Flutter plugin to detect screen lock/unlock events across Android and iOS platforms.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

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

Documentation

API reference

Funding

Consider supporting this project:

ko-fi.com

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on screen_lock_detector

Packages that implement screen_lock_detector