From 3797b7d8ce097bd5b508924c8900374d1df2e7d8 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 2 Oct 2024 08:59:06 -0300 Subject: [PATCH] WIP --- lib/backend/api_requests/api_calls.dart | 10 +++--- .../local_profile_component_widget.dart | 26 ++++++++------- .../reception_page/reception_page_widget.dart | 3 +- .../shared_preferences_storage_helper.dart | 33 +++++++++++-------- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index dd576740..fb1e4dc9 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -642,7 +642,7 @@ class RegisterCall { }, params: { 'name': name, - 'email': email.toLowerCase(), + 'email': email?.toLowerCase(), 'password': password, 'token': token, 'uuid': uuid, @@ -724,10 +724,10 @@ class GetLocalsCall { class PostScheduleVisitorCall { Future call({ - final String? documento, - final String? nome, - final String? tipo, - final String? foto, + required final String documento, + required final String nome, + required final String tipo, + required final String foto, }) async { final String baseUrl = PhpGroup.getBaseUrl(); 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 d6f5fb82..7509da9e 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 @@ -41,9 +41,8 @@ class _LocalProfileComponentWidgetState _model.setOnUpdate(onUpdate: () => setState(() {})); _model.setStateCallback = () => safeSetState(() {}); - WidgetsBinding.instance.addPostFrameCallback((_) async { - await processLocals(); - }); + WidgetsBinding.instance + .addPostFrameCallback((_) async => await processLocals()); } @override @@ -97,29 +96,32 @@ class _LocalProfileComponentWidgetState final ApiCallResponse response = await callback.call(); - final List locals = response.jsonBody['locais'] - .where((local) => local['CLU_STATUS']) - .toList() ?? - []; + final List locals = response.jsonBody['locais'].toList() ?? []; - final bool isEnable = locals.any((local) => local['CLU_STATUS'] == 'A'); + final bool isActive = response.jsonBody['locais'] + .where((local) => local['CLU_STATUS'] == 'A') + .toList() + .isNotEmpty; final bool isUnique = locals.length == 1; final bool isBlocked = locals[0]['CLU_STATUS'] == 'B'; + final bool isEnable = isUnique && isActive; final bool isDisabled = isUnique && isBlocked; final bool isSelected = - StorageUtil().cliUUID.isNotEmpty && StorageUtil().cliName.isNotEmpty; + StorageUtil().cliUUID.isEmpty && StorageUtil().cliName.isEmpty; + + if (!mounted) return; if (isDisabled) { - context.go('/welcomePage'); + if (mounted) context.go('/welcomePage'); } else if (isEnable) { await showModalSelectLocal(); - } else if (!isSelected) { + } else if (isSelected) { await showModalSelectLocal(); } else { await processData(); } } catch (e) { - await showModalSelectLocal(); + 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 f768032c..2d828fe4 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -60,8 +60,9 @@ class _ReceptionPageWidgetState extends State .where((local) => local['CLU_STATUS'] == 'A') .toList() .isNotEmpty; + final bool isEnable = !isEmpty && isActive; - if (!isEmpty && isActive) { + if (isEnable) { StorageUtil().haveLocal = true; StorageUtil().isLogged = true; await WidgetsBinding.instance.endOfFrame; diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart index 422b8675..c6b84dd4 100644 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -5,7 +5,8 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:hub/shared/utils/cache_util.dart'; class SharedPreferencesStorageHelper implements Storage { - static final SharedPreferencesStorageHelper _instance = SharedPreferencesStorageHelper._internal(); + static final SharedPreferencesStorageHelper _instance = + SharedPreferencesStorageHelper._internal(); SharedPreferences? _prefs; SharedPreferences? get prefs => _prefs; set prefs(SharedPreferences? value) => _prefs = value; @@ -18,45 +19,50 @@ class SharedPreferencesStorageHelper implements Storage { bool _isFirstRun = true; bool get isFirstRun => _isFirstRun; - set isFirstRun(bool value) => _setAndCacheBool('first_run', value, (v) => _isFirstRun = v); + 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 { + Future _setAndCache(String key, T value, Function(T) cacheSetter, + Future Function(String, T) setFunc) async { log('setAndCache value for key: $key to $value'); await setFunc(key, value); CacheUtil.instance.set(key, value); cacheSetter(value); } - Future _setAndCacheString(String key, String value, Function(String) cacheSetter) async { + Future _setAndCacheString( + String key, String value, Function(String) cacheSetter) async { log('setAndCacheString value for key: $key to $value'); await _setAndCache(key, value, cacheSetter, _prefs!.setString); } - Future _setAndCacheBool(String key, bool value, Function(bool) cacheSetter) async { + Future _setAndCacheBool( + String key, bool value, Function(bool) cacheSetter) async { log('setAndCacheBool value for key: $key to $value'); await _setAndCache(key, value, cacheSetter, _prefs!.setBool); } - Future _setAndCacheInt(String key, int value, Function(int) cacheSetter) async { + Future _setAndCacheInt( + String key, int value, Function(int) cacheSetter) async { log('setAndCacheInt value for key: $key to $value'); await _setAndCache(key, value, cacheSetter, _prefs!.setInt); } - Future _setAndCacheDouble(String key, double value, Function(double) cacheSetter) async { + Future _setAndCacheDouble( + String key, double value, Function(double) cacheSetter) async { log('setAndCacheDouble value for key: $key to $value'); await _setAndCache(key, value, cacheSetter, _prefs!.setDouble); } - Future _setAndCacheStringList(String key, List value, Function(List) cacheSetter) async { + Future _setAndCacheStringList(String key, List value, + Function(List) cacheSetter) async { log('setAndCacheStringList value for key: $key to $value'); await _setAndCache(key, value, cacheSetter, _prefs!.setStringList); } @override - Future set(String key, dynamic value, Function(dynamic) cacheSetter) async { - + Future set( + String key, dynamic value, Function(dynamic) cacheSetter) async { if (value is bool) { await _prefs?.setBool(key, value); } else if (value is String) { @@ -94,6 +100,5 @@ class SharedPreferencesStorageHelper implements Storage { log('Purging shared preferences'); await _prefs?.clear(); CacheUtil.instance.clear(); - } -} \ No newline at end of file +}