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

outdated

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

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:is_lock_screen/is_lock_screen.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) async {
    super.didChangeAppLifecycleState(state);
    if (state == AppLifecycleState.inactive) {
      print('app inactive, is lock screen: ${await isLockScreen()}');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Test by changing app lifecycle (locking device / exiting app). Result will be print in console.'),
        ),
      ),
    );
  }
}
46
likes
40
points
1.25k
downloads

Publisher

verified publishertarosago.xyz

Weekly Downloads

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

Repository (GitHub)

License

MIT (license)

Dependencies

flutter

More

Packages that depend on is_lock_screen