This commit is contained in:
J. A. Messias 2024-10-02 08:59:06 -03:00
parent 5c567eb5dc
commit 3797b7d8ce
4 changed files with 40 additions and 32 deletions

View File

@ -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<ApiCallResponse> 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();

View File

@ -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<dynamic> locals = response.jsonBody['locais']
.where((local) => local['CLU_STATUS'])
.toList() ??
[];
final List<dynamic> 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();
}
}

View File

@ -60,8 +60,9 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
.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;

View File

@ -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<void> _setAndCache<T>(String key, T value, Function(T) cacheSetter, Future<void> Function(String, T) setFunc) async {
Future<void> _setAndCache<T>(String key, T value, Function(T) cacheSetter,
Future<void> 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<void> _setAndCacheString(String key, String value, Function(String) cacheSetter) async {
Future<void> _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<void> _setAndCacheBool(String key, bool value, Function(bool) cacheSetter) async {
Future<void> _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<void> _setAndCacheInt(String key, int value, Function(int) cacheSetter) async {
Future<void> _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<void> _setAndCacheDouble(String key, double value, Function(double) cacheSetter) async {
Future<void> _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<void> _setAndCacheStringList(String key, List<String> value, Function(List<String>) cacheSetter) async {
Future<void> _setAndCacheStringList(String key, List<String> value,
Function(List<String>) cacheSetter) async {
log('setAndCacheStringList value for key: $key to $value');
await _setAndCache(key, value, cacheSetter, _prefs!.setStringList);
}
@override
Future<void> set(String key, dynamic value, Function(dynamic) cacheSetter) async {
Future<void> 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();
}
}
}