diff --git a/example/lib/screens/my_home_page.dart b/example/lib/screens/my_home_page.dart index 24a91f5..abcdbb1 100644 --- a/example/lib/screens/my_home_page.dart +++ b/example/lib/screens/my_home_page.dart @@ -71,6 +71,9 @@ class _MyHomePageState extends State { } }, ), + const LatencyEditor( + key: Key('LatencyEditor'), + ), ], ), ), @@ -82,3 +85,57 @@ class _MyHomePageState extends State { ); } } + +class LatencyEditor extends StatefulWidget { + const LatencyEditor({Key? key}) : super(key: key); + + @override + State createState() => _LatencyEditorState(); +} + +class _LatencyEditorState extends State { + late TextEditingController backgroundLockLatencyEditingController; + + @override + void initState() { + backgroundLockLatencyEditingController = TextEditingController(text: "0"); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + onPressed: _setBackgroundLockLatency, + child: const Text('Set backgroundLockLatency to'), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 20), + child: TextField( + textAlign: TextAlign.right, + controller: backgroundLockLatencyEditingController, + ), + ), + ), + const Text('s'), + ], + ); + } + + void _setBackgroundLockLatency() { + try { + int latencyInSeconds = + int.parse(backgroundLockLatencyEditingController.text); + AppLock.of(context)?.backgroundLockLatency = + Duration(seconds: latencyInSeconds); + } catch (e) { + if (kDebugMode) { + print(e); + } + } + } +} diff --git a/lib/src/widgets/app_lock.dart b/lib/src/widgets/app_lock.dart index e3c3b6f..432b4fa 100644 --- a/lib/src/widgets/app_lock.dart +++ b/lib/src/widgets/app_lock.dart @@ -53,6 +53,8 @@ class _AppLockState extends State with WidgetsBindingObserver { late bool _isLocked; late bool _enabled; + late Duration backgroundLockLatency; + Timer? _backgroundLockLatencyTimer; @override @@ -63,6 +65,8 @@ class _AppLockState extends State with WidgetsBindingObserver { _isLocked = false; _enabled = widget.enabled; + backgroundLockLatency = widget.backgroundLockLatency; + super.initState(); } @@ -75,7 +79,7 @@ class _AppLockState extends State with WidgetsBindingObserver { if (state == AppLifecycleState.paused && (!_isLocked && _didUnlockForAppLaunch)) { _backgroundLockLatencyTimer = - Timer(widget.backgroundLockLatency, () => showLockScreen()); + Timer(backgroundLockLatency, () => showLockScreen()); } if (state == AppLifecycleState.resumed) {