From b3b4ca08cace25f6235da8eb1b3dba3419387903 Mon Sep 17 00:00:00 2001 From: Jakob Leck Date: Thu, 2 Mar 2023 18:37:28 +0100 Subject: [PATCH 1/2] added: allow changes of backgroundLockLatency --- lib/src/widgets/app_lock.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) { From 2813de5bc3774284ebc8181e085c7359927a3cb3 Mon Sep 17 00:00:00 2001 From: Jakob Leck Date: Thu, 2 Mar 2023 18:37:48 +0100 Subject: [PATCH 2/2] added change of backgroundLockLatency to example app --- example/lib/screens/my_home_page.dart | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) 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); + } + } + } +}