From 8a53233afd57d42708f28fc733ee000e4801fcc9 Mon Sep 17 00:00:00 2001 From: suvaissov Date: Wed, 20 Jan 2021 01:11:21 +0600 Subject: [PATCH] pin lock? bug fixes --- lib/redux/state/setting_state.dart | 2 +- lib/views/home/home_view.dart | 48 +++++++++++++-------------- lib/views/home/tabs/KassaTab.dart | 6 ++-- lib/views/settings/settings_view.dart | 4 +-- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/lib/redux/state/setting_state.dart b/lib/redux/state/setting_state.dart index 894cf8d..48bf38b 100644 --- a/lib/redux/state/setting_state.dart +++ b/lib/redux/state/setting_state.dart @@ -18,7 +18,7 @@ class SettingState { mode: payload?.mode ?? SettingModeKassa, tradeType: payload?.tradeType ?? SettingTradeTypeGood, pinCode: payload?.pinCode ?? null, - pinLocked: payload?.pinLocked ?? false, + pinLocked: true, pinSkip: false, ); } diff --git a/lib/views/home/home_view.dart b/lib/views/home/home_view.dart index 1de534f..727c9fc 100644 --- a/lib/views/home/home_view.dart +++ b/lib/views/home/home_view.dart @@ -58,6 +58,7 @@ class _HomeViewState extends State with WidgetsBindingObserver { AppLifecycleState.values[prevState] != AppLifecycleState.paused; final bool pinIsExist = Redux.store.state.settingState?.pinCode?.isNotEmpty; final bool pinSkipped = Redux.store.state.settingState.pinSkip; + print('prevStateIsNotPaused=$prevStateIsNotPaused, pinIsExist=$pinIsExist, pinSkipped=$pinSkipped'); if(prevStateIsNotPaused && pinSkipped == false && pinIsExist == true) { // save App backgrounded time to Shared preferences sp.setInt(backgroundedTimeKey, DateTime.now().millisecondsSinceEpoch); @@ -72,37 +73,34 @@ class _HomeViewState extends State with WidgetsBindingObserver { final allowedBackgroundTime = bgTime + pinLockMillis; final shouldShowPIN = DateTime.now().millisecondsSinceEpoch > allowedBackgroundTime; if(shouldShowPIN && bgTime > 0) { - Redux.store.dispatch(changePinLockedFromSetting(true)); - // show PIN screen - // Navigator.pushReplacement(context, MaterialPageRoute( - // builder: (_) => PassCodeScreen( title: 'Безопасность',))); - Navigator.of(context).push(MaterialPageRoute( - builder: (_) => - WillPopScope( - onWillPop: () async { - return false; - }, - child: PassCodeScreen( title: 'Безопасность',) - ) - )); - + await Redux.store.dispatch(changePinLockedFromSetting(true)); + pushToLockScreen(); } sp.remove(backgroundedTimeKey); // clean sp.setInt(lastKnownStateKey, AppLifecycleState.resumed.index);// previous state } + void pushToLockScreen() { + Navigator.of(context).push(MaterialPageRoute( + builder: (_) => + WillPopScope( + onWillPop: () async { + return false; + }, + child: PassCodeScreen( title: 'Безопасность',) + ) + )); + } + _checkLockPin () async { - if ( Redux.store.state.settingState.pinLocked == true) { - await Future.delayed(Duration(milliseconds: 200)); - Navigator.of(context).push(MaterialPageRoute( - builder: (_) => - WillPopScope( - onWillPop: () async { - return false; - }, - child: PassCodeScreen( title: 'Безопасность',) - ) - )); + final bool pinIsExist = Redux.store.state.settingState?.pinCode?.isNotEmpty; + final bool pinLocked = Redux.store.state.settingState?.pinLocked; + final sp = await SharedPreferences.getInstance(); + sp.remove(backgroundedTimeKey); + sp.setInt(lastKnownStateKey, AppLifecycleState.resumed.index);// previous state + if ( pinIsExist == true && pinLocked == true ) { + await Future.delayed(Duration(milliseconds: 50)); + pushToLockScreen(); } } diff --git a/lib/views/home/tabs/KassaTab.dart b/lib/views/home/tabs/KassaTab.dart index 928a10a..d4075ba 100644 --- a/lib/views/home/tabs/KassaTab.dart +++ b/lib/views/home/tabs/KassaTab.dart @@ -184,7 +184,7 @@ class KassaTab extends StatelessWidget { Future scan() async { try { - Redux.store.dispatch(changePinSkipFromSetting(true)); + await Redux.store.dispatch(changePinSkipFromSetting(true)); var options = ScanOptions(strings: { "cancel": 'Отмена', "flash_on": 'Вкл фонарик', @@ -219,7 +219,7 @@ class KassaTab extends StatelessWidget { List goods = await _dataService.getGoodsByBarcode(barcode: barcode); if (goods != null && goods.isNotEmpty) { - Redux.store.dispatch(addProductToKassaItems(goods.first, dataMatrix)); + await Redux.store.dispatch(addProductToKassaItems(goods.first, dataMatrix)); } else { _dialogService.showDialog( description: 'Товар не найден: $barcode'); @@ -241,7 +241,7 @@ class KassaTab extends StatelessWidget { _dialogService.showDialog(description: 'Неизвестная ошибка: $e'); } } finally { - Redux.store.dispatch(changePinSkipFromSetting(false)); + await Redux.store.dispatch(changePinSkipFromSetting(false)); } } diff --git a/lib/views/settings/settings_view.dart b/lib/views/settings/settings_view.dart index a4070cc..1b89fea 100644 --- a/lib/views/settings/settings_view.dart +++ b/lib/views/settings/settings_view.dart @@ -38,7 +38,7 @@ class _SettingViewState extends State { void _setPinCode(BuildContext _context) async { FocusScope.of(_context).unfocus(); var value = _pinController.text; - if(value.isEmpty || value.length !=4){ + if(value.isNotEmpty && value.length !=4){ _dialogService.showDialog(description: 'Необходимо указать 4-х значный числовой код'); } else { await Redux.store.dispatch(changePinCodeFromSetting(_pinController.text)); @@ -62,7 +62,7 @@ class _SettingViewState extends State { children: [ verticalSpaceTiny, Text( - 'Ддя блокировки приложения пин-кодом, укажите 4-ех значный числовой код', + 'Для блокировки приложения пин-кодом, укажите 4-х значный числовой код', style: TextStyle(fontSize: 15.0), textAlign: TextAlign.center, ),