pin lock? bug fixes

fix_ssl_master
suvaissov 2021-01-20 01:11:21 +06:00
parent e1301e7340
commit 8a53233afd
4 changed files with 29 additions and 31 deletions

View File

@ -18,7 +18,7 @@ class SettingState {
mode: payload?.mode ?? SettingModeKassa, mode: payload?.mode ?? SettingModeKassa,
tradeType: payload?.tradeType ?? SettingTradeTypeGood, tradeType: payload?.tradeType ?? SettingTradeTypeGood,
pinCode: payload?.pinCode ?? null, pinCode: payload?.pinCode ?? null,
pinLocked: payload?.pinLocked ?? false, pinLocked: true,
pinSkip: false, pinSkip: false,
); );
} }

View File

@ -58,6 +58,7 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
AppLifecycleState.values[prevState] != AppLifecycleState.paused; AppLifecycleState.values[prevState] != AppLifecycleState.paused;
final bool pinIsExist = Redux.store.state.settingState?.pinCode?.isNotEmpty; final bool pinIsExist = Redux.store.state.settingState?.pinCode?.isNotEmpty;
final bool pinSkipped = Redux.store.state.settingState.pinSkip; final bool pinSkipped = Redux.store.state.settingState.pinSkip;
print('prevStateIsNotPaused=$prevStateIsNotPaused, pinIsExist=$pinIsExist, pinSkipped=$pinSkipped');
if(prevStateIsNotPaused && pinSkipped == false && pinIsExist == true) { if(prevStateIsNotPaused && pinSkipped == false && pinIsExist == true) {
// save App backgrounded time to Shared preferences // save App backgrounded time to Shared preferences
sp.setInt(backgroundedTimeKey, DateTime.now().millisecondsSinceEpoch); sp.setInt(backgroundedTimeKey, DateTime.now().millisecondsSinceEpoch);
@ -72,28 +73,14 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
final allowedBackgroundTime = bgTime + pinLockMillis; final allowedBackgroundTime = bgTime + pinLockMillis;
final shouldShowPIN = DateTime.now().millisecondsSinceEpoch > allowedBackgroundTime; final shouldShowPIN = DateTime.now().millisecondsSinceEpoch > allowedBackgroundTime;
if(shouldShowPIN && bgTime > 0) { if(shouldShowPIN && bgTime > 0) {
Redux.store.dispatch(changePinLockedFromSetting(true)); await Redux.store.dispatch(changePinLockedFromSetting(true));
// show PIN screen pushToLockScreen();
// Navigator.pushReplacement(context, MaterialPageRoute(
// builder: (_) => PassCodeScreen( title: 'Безопасность',)));
Navigator.of(context).push(MaterialPageRoute(
builder: (_) =>
WillPopScope(
onWillPop: () async {
return false;
},
child: PassCodeScreen( title: 'Безопасность',)
)
));
} }
sp.remove(backgroundedTimeKey); // clean sp.remove(backgroundedTimeKey); // clean
sp.setInt(lastKnownStateKey, AppLifecycleState.resumed.index);// previous state sp.setInt(lastKnownStateKey, AppLifecycleState.resumed.index);// previous state
} }
_checkLockPin () async { void pushToLockScreen() {
if ( Redux.store.state.settingState.pinLocked == true) {
await Future.delayed(Duration(milliseconds: 200));
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(MaterialPageRoute(
builder: (_) => builder: (_) =>
WillPopScope( WillPopScope(
@ -104,6 +91,17 @@ class _HomeViewState extends State<HomeView> with WidgetsBindingObserver {
) )
)); ));
} }
_checkLockPin () async {
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();
}
} }
@override @override

View File

@ -184,7 +184,7 @@ class KassaTab extends StatelessWidget {
Future<void> scan() async { Future<void> scan() async {
try { try {
Redux.store.dispatch(changePinSkipFromSetting(true)); await Redux.store.dispatch(changePinSkipFromSetting(true));
var options = ScanOptions(strings: { var options = ScanOptions(strings: {
"cancel": 'Отмена', "cancel": 'Отмена',
"flash_on": 'Вкл фонарик', "flash_on": 'Вкл фонарик',
@ -219,7 +219,7 @@ class KassaTab extends StatelessWidget {
List<Good> goods = List<Good> goods =
await _dataService.getGoodsByBarcode(barcode: barcode); await _dataService.getGoodsByBarcode(barcode: barcode);
if (goods != null && goods.isNotEmpty) { if (goods != null && goods.isNotEmpty) {
Redux.store.dispatch(addProductToKassaItems(goods.first, dataMatrix)); await Redux.store.dispatch(addProductToKassaItems(goods.first, dataMatrix));
} else { } else {
_dialogService.showDialog( _dialogService.showDialog(
description: 'Товар не найден: $barcode'); description: 'Товар не найден: $barcode');
@ -241,7 +241,7 @@ class KassaTab extends StatelessWidget {
_dialogService.showDialog(description: 'Неизвестная ошибка: $e'); _dialogService.showDialog(description: 'Неизвестная ошибка: $e');
} }
} finally { } finally {
Redux.store.dispatch(changePinSkipFromSetting(false)); await Redux.store.dispatch(changePinSkipFromSetting(false));
} }
} }

View File

@ -38,7 +38,7 @@ class _SettingViewState extends State<SettingView> {
void _setPinCode(BuildContext _context) async { void _setPinCode(BuildContext _context) async {
FocusScope.of(_context).unfocus(); FocusScope.of(_context).unfocus();
var value = _pinController.text; var value = _pinController.text;
if(value.isEmpty || value.length !=4){ if(value.isNotEmpty && value.length !=4){
_dialogService.showDialog(description: 'Необходимо указать 4-х значный числовой код'); _dialogService.showDialog(description: 'Необходимо указать 4-х значный числовой код');
} else { } else {
await Redux.store.dispatch(changePinCodeFromSetting(_pinController.text)); await Redux.store.dispatch(changePinCodeFromSetting(_pinController.text));
@ -62,7 +62,7 @@ class _SettingViewState extends State<SettingView> {
children: <Widget>[ children: <Widget>[
verticalSpaceTiny, verticalSpaceTiny,
Text( Text(
'Ддя блокировки приложения пин-кодом, укажите 4-ех значный числовой код', 'Для блокировки приложения пин-кодом, укажите 4-х значный числовой код',
style: TextStyle(fontSize: 15.0), style: TextStyle(fontSize: 15.0),
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),