From 8e8b57d8e8e33474ad622f479fa870114983b921 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 1 Jul 2024 10:15:17 -0500 Subject: [PATCH] enter pin automatically if autopin pref is set --- lib/pages/pinpad_views/lock_screen_view.dart | 18 +++++++++++++++++- .../change_pin_view/change_pin_view.dart | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/pages/pinpad_views/lock_screen_view.dart b/lib/pages/pinpad_views/lock_screen_view.dart index afb7c7a1d..ed20c12b7 100644 --- a/lib/pages/pinpad_views/lock_screen_view.dart +++ b/lib/pages/pinpad_views/lock_screen_view.dart @@ -188,12 +188,14 @@ class _LockscreenViewState extends ConsumerState { _timeout = Duration.zero; _checkUseBiometrics(); + _pinTextController.addListener(_onPinChanged); super.initState(); } @override dispose() { // _shakeController.dispose(); + _pinTextController.removeListener(_onPinChanged); super.dispose(); } @@ -208,13 +210,27 @@ class _LockscreenViewState extends ConsumerState { ); } - final _pinTextController = TextEditingController(); final FocusNode _pinFocusNode = FocusNode(); late SecureStorageInterface _secureStore; late Biometrics biometrics; int pinCount = 1; + final _pinTextController = TextEditingController(); + + void _onPinChanged() async { + String enteredPin = _pinTextController.text; + final storedPin = await _secureStore.read(key: 'stack_pin'); + final autoPin = ref.read(prefsChangeNotifierProvider).autoPin; + + if (autoPin && enteredPin == storedPin) { + await Future.delayed( + const Duration(milliseconds: 200), + ); + unawaited(_onUnlock()); + } + } + Widget get _body => Background( child: SafeArea( child: Scaffold( diff --git a/lib/pages/settings_views/global_settings_view/security_views/change_pin_view/change_pin_view.dart b/lib/pages/settings_views/global_settings_view/security_views/change_pin_view/change_pin_view.dart index 57fa710ad..bc1eb6fae 100644 --- a/lib/pages/settings_views/global_settings_view/security_views/change_pin_view/change_pin_view.dart +++ b/lib/pages/settings_views/global_settings_view/security_views/change_pin_view/change_pin_view.dart @@ -61,9 +61,12 @@ class _ChangePinViewState extends ConsumerState { int pinCount = 1; + final TextEditingController _pinTextController = TextEditingController(); + @override void initState() { _secureStore = ref.read(secureStoreProvider); + _pinTextController.addListener(_onPinChanged); super.initState(); } @@ -74,9 +77,23 @@ class _ChangePinViewState extends ConsumerState { _pinPutController2.dispose(); _pinPutFocusNode1.dispose(); _pinPutFocusNode2.dispose(); + _pinTextController.removeListener(_onPinChanged); super.dispose(); } + void _onPinChanged() async { + String enteredPin = _pinTextController.text; + final storedPin = await _secureStore.read(key: 'stack_pin'); + final autoPin = ref.read(prefsChangeNotifierProvider).autoPin; + + if (autoPin && enteredPin == storedPin) { + await _pageController.nextPage( + duration: const Duration(milliseconds: 300), + curve: Curves.linear, + ); + } + } + @override Widget build(BuildContext context) { return Background(