diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart b/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart index 7509da9e..aa3a771a 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart +++ b/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart @@ -79,13 +79,14 @@ class _LocalProfileComponentWidgetState safeSetState(() {}); return; } else if (error == true) { + log('() => error: $error'); DialogUtil.warningDefault(context).whenComplete(() => processLocals()); safeSetState(() {}); } return; } catch (e) { - log('() => error: $e'); // Add this line to log the error + log('() => error: $e'); DialogUtil.warningDefault(context).whenComplete(() => processLocals()); } } @@ -104,7 +105,7 @@ class _LocalProfileComponentWidgetState .isNotEmpty; final bool isUnique = locals.length == 1; final bool isBlocked = locals[0]['CLU_STATUS'] == 'B'; - final bool isEnable = isUnique && isActive; + final bool isEnabled = isUnique && isActive; final bool isDisabled = isUnique && isBlocked; final bool isSelected = StorageUtil().cliUUID.isEmpty && StorageUtil().cliName.isEmpty; @@ -113,14 +114,17 @@ class _LocalProfileComponentWidgetState if (isDisabled) { if (mounted) context.go('/welcomePage'); - } else if (isEnable) { - await showModalSelectLocal(); + } else if (isEnabled) { + StorageUtil().cliName = locals[0]['CLI_NOME']; + StorageUtil().cliUUID = locals[0]['CLI_ID']; + StorageUtil().ownerUUID = locals[0]['CLU_OWNER_ID']; } else if (isSelected) { await showModalSelectLocal(); } else { await processData(); } } catch (e) { + log('() => error: $e'); if (mounted) await showModalSelectLocal(); } } diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 2d828fe4..f6833f10 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -57,7 +57,7 @@ class _ReceptionPageWidgetState extends State final List locals = response.jsonBody['locais'] ?? []; final bool isEmpty = locals.isEmpty; final bool isActive = locals - .where((local) => local['CLU_STATUS'] == 'A') + .where((local) => local['CLU_STATUS'] != 'B') .toList() .isNotEmpty; final bool isEnable = !isEmpty && isActive; @@ -68,7 +68,6 @@ class _ReceptionPageWidgetState extends State await WidgetsBinding.instance.endOfFrame; dispose(); StorageUtil().context?.go('/homePage'); - await showModalSelectLocal(); } } } catch (e, s) { @@ -145,6 +144,7 @@ class _ReceptionPageWidgetState extends State @override void didChangeAppLifecycleState(AppLifecycleState state) { + log('() => state: $state'); if (state == AppLifecycleState.resumed) { setState(() { processLocals(); diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart index 49486f8a..df5c29f0 100644 --- a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart +++ b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/templates_components/details_component/details_component_widget.dart'; @@ -79,37 +81,46 @@ class ScheduleCompleteVisitPageModel visitorJsonList[index] = updateFn(visitorJsonList[index]); bool isValid() { - if ((textController1!.text != '') && - (textController2!.text != '') && - (dropDownValue1 != null && dropDownValue1 != '') && - (dropDownValue2 != null && dropDownValue2 != '') && - (visitorStrList.isNotEmpty)) { - DateTime selectedDateTime; - DateTime currentDateTime = DateTime.now().subtract(Duration(minutes: 10)); - try { - selectedDateTime = - DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController1.text); - if (selectedDateTime.isBefore(currentDateTime)) { - return false; - } - } catch (e) { - return false; - } - - try { - selectedDateTime = - DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController2.text); - if (selectedDateTime.isBefore(currentDateTime)) { - return false; - } - } catch (e) { - return false; - } - - return true; + if (textController1!.text.isEmpty || + textController2!.text.isEmpty || + dropDownValue1 == null || + dropDownValue1!.isEmpty || + dropDownValue2 == null || + dropDownValue2!.isEmpty) { + return false; } - return false; + if (textController1.text.isEmpty) return false; + if (textController2.text.isEmpty) return false; + if (dropDownValue1 == null || dropDownValue1!.isEmpty) return false; + if (dropDownValue2 == null || dropDownValue2!.isEmpty) return false; + + if (visitorStrList == '[]' || visitorJsonList.isEmpty) return false; + + DateTime selectedDateTime1; + DateTime selectedDateTime2; + DateTime currentDateTime = + DateTime.now().subtract(const Duration(minutes: 10)); + + try { + selectedDateTime1 = + DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController1.text); + selectedDateTime2 = + DateFormat('dd/MM/yyyy HH:mm:ss').parse(textController2.text); + } catch (e) { + return false; + } + + if (selectedDateTime1.isBefore(currentDateTime) || + selectedDateTime2.isBefore(currentDateTime)) { + return false; + } + + if (selectedDateTime1.isAfter(selectedDateTime2)) { + return false; + } + + return true; } final unfocusNode = FocusNode(); diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart index c6b84dd4..6614402b 100644 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -17,11 +17,6 @@ class SharedPreferencesStorageHelper implements Storage { static SharedPreferencesStorageHelper get instance => _instance; - bool _isFirstRun = true; - bool get isFirstRun => _isFirstRun; - set isFirstRun(bool value) => - _setAndCacheBool('milestone', value, (v) => _isFirstRun = v); - Future _setAndCache(String key, T value, Function(T) cacheSetter, Future Function(String, T) setFunc) async { log('setAndCache value for key: $key to $value'); @@ -64,6 +59,7 @@ class SharedPreferencesStorageHelper implements Storage { Future set( String key, dynamic value, Function(dynamic) cacheSetter) async { if (value is bool) { + log('() => setAndCacheBool $key to $value'); await _prefs?.setBool(key, value); } else if (value is String) { await _prefs?.setString(key, value); diff --git a/lib/shared/utils/storage_util.dart b/lib/shared/utils/storage_util.dart index 975547a5..3b9e2a64 100644 --- a/lib/shared/utils/storage_util.dart +++ b/lib/shared/utils/storage_util.dart @@ -109,8 +109,8 @@ class StorageUtil { static Future purge() async { try { - await SecureStorageHelper().purge(); - await SharedPreferencesStorageHelper().purge(); + // await SecureStorageHelper().purge(); + // await SharedPreferencesStorageHelper().purge(); await SQLiteStorageHelper().purge(); } catch (e) { log('Error purging data: $e'); @@ -125,8 +125,9 @@ class StorageUtil { Future initSharedPreferences() async { _sharedPreferences.prefs ??= await SharedPreferences.getInstance(); - isFirstRun = _sharedPreferences.prefs?.getBool('milestone') ?? true; - if (isFirstRun) { + final bool milestone = + _sharedPreferences.prefs?.getBool('milestone') ?? true; + if (milestone) { isFirstRun = false; await _sharedPreferences.prefs?.setBool('milestone', false); _secureStorage.purge();