From 80d428b766a80477e23e87f0a3413beac39291e9 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 24 Sep 2024 10:55:10 -0300 Subject: [PATCH 1/6] add --- lib/app_state.dart | 372 ---------------- lib/backend/api_requests/api_calls.dart | 399 +++++------------- .../firebase_messaging_service.dart | 2 +- .../notifications/notification_service.dart | 6 +- .../menu_button_item_widget.dart | 4 +- ..._arrow_linked_locals_component_widget.dart | 6 +- .../local_profile_component_model.dart | 4 +- .../local_profile_component_widget.dart | 4 +- .../menu_component/menu_component_model.dart | 16 +- .../menu_component/menu_component_widget.dart | 2 +- .../message_well_component_widget.dart | 4 +- .../schedule_visit_detail_model.dart | 4 +- ...p_arrow_linked_locals_component_model.dart | 4 +- ...cation_modal_template_component_model.dart | 4 +- ...item_details_template_component_model.dart | 4 +- .../provisional_schedule_template_model.dart | 4 +- .../provisional_shcedule_template_widget.dart | 2 +- ...siter_vistor_template_component_model.dart | 4 +- .../sign_in_template_component_model.dart | 4 +- .../view_visit_detail_model.dart | 4 +- ...search_modal_template_component_model.dart | 4 +- lib/main.dart | 37 +- .../acess_history_page_model.dart | 4 +- .../fast_pass_page/fast_pass_page_widget.dart | 4 +- lib/pages/home_page/home_page_model.dart | 4 +- lib/pages/home_page/home_page_widget.dart | 4 +- .../liberation_history_model.dart | 4 +- .../message_history_page_model.dart | 4 +- .../package_order_page.dart | 4 +- lib/pages/pets_page/pets_history_screen.dart | 4 +- lib/pages/pets_page/pets_page_model.dart | 4 +- .../preferences_settings_model.dart | 4 +- .../preferences_settings_widget.dart | 4 +- .../qr_code_page/qr_code_page_model.dart | 4 +- .../qr_code_page/qr_code_page_widget.dart | 2 +- .../reception_page/reception_page_model.dart | 4 +- .../reservation_page_widget.dart | 4 +- .../schedule_complete_visit_page_model.dart | 4 +- .../visit_history_page_widget.dart | 38 +- .../welcome_page/welcome_page_widget.dart | 9 +- .../flutter_secure_storage_extensions.dart | 56 +++ lib/shared/helpers/secure_storage_helper.dart | 140 ++++++ .../shared_preferences_storage_helper.dart | 61 +++ ...helper.dart => sqlite_storage_helper.dart} | 47 ++- lib/shared/utils/biometric_util.dart | 32 ++ lib/shared/utils/cache_util.dart | 21 + lib/shared/utils/share_util.dart | 12 +- lib/shared/utils/storage_util.dart | 78 ++++ 48 files changed, 660 insertions(+), 790 deletions(-) create mode 100644 lib/shared/extensions/flutter_secure_storage_extensions.dart create mode 100644 lib/shared/helpers/secure_storage_helper.dart create mode 100644 lib/shared/helpers/shared_preferences_storage_helper.dart rename lib/shared/helpers/{db_helper.dart => sqlite_storage_helper.dart} (85%) create mode 100644 lib/shared/utils/biometric_util.dart create mode 100644 lib/shared/utils/cache_util.dart create mode 100644 lib/shared/utils/storage_util.dart diff --git a/lib/app_state.dart b/lib/app_state.dart index 96c8dd59..8b137891 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -1,373 +1 @@ -// import 'dart:ffi'; -import 'package:csv/csv.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:local_auth/local_auth.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:synchronized/synchronized.dart'; - -class AppState extends ChangeNotifier { - // Adiciona a variável para controle de autenticação biométrica - bool _isBiometricAuthenticated = false; - bool get isBiometricAuthenticated => _isBiometricAuthenticated; - - // Instância do LocalAuthentication - final LocalAuthentication auth = LocalAuthentication(); - - // Verifica suporte biométrico - Future checkBiometrics() async { - try { - return await auth.canCheckBiometrics; - } catch (e) { - clearBiometricAuthentication(); - return false; - } - } - - // Solicita autenticação biométrica - Future authenticateBiometric() async { - bool authenticated = false; - try { - authenticated = await auth.authenticate( - localizedReason: 'Scan your fingerprint to authenticate', - options: const AuthenticationOptions( - biometricOnly: true, - stickyAuth: true, - useErrorDialogs: true, - sensitiveTransaction: true, - )); - if (authenticated) { - _isBiometricAuthenticated = true; - notifyListeners(); - return Future.value(); - // Salvar o estado de autenticação biométrica, se necessário - } - } catch (e) { - clearBiometricAuthentication(); - return Future.error(e); - } - return Future.error( - ''); // Add this line to ensure a value is always returned - } - - // Função para limpar o estado de autenticação biométrica - void clearBiometricAuthentication() { - _isBiometricAuthenticated = false; - notifyListeners(); - // Limpar a informação salva, se necessário - } - - static AppState _instance = AppState._internal(); - - factory AppState() { - return _instance; - } - - AppState._internal(); - - static void reset() { - _instance = AppState._internal(); - } - - Future initializePersistedState() async { - secureStorage = const FlutterSecureStorage(); - - await _safeInitAsync(() async { - _email = await secureStorage.getString('ff_email') ?? _email; - }); - await _safeInitAsync(() async { - _passwd = await secureStorage.getString('ff_passwd') ?? _passwd; - }); - await _safeInitAsync(() async { - _deviceType = - await secureStorage.getString('ff_deviceType') ?? _deviceType; - }); - await _safeInitAsync(() async { - _isLogged = await secureStorage.getBool('ff_isLogged') ?? _isLogged; - }); - - await _safeInitAsync(() async { - _tokenAPNS = await secureStorage.getString('ff_tokenAPNS') ?? _tokenAPNS; - }); - - await _safeInitAsync(() async { - _accessPass = await secureStorage.getString('accessPass') ?? _accessPass; - }); - await _safeInitAsync(() async { - _panicPass = await secureStorage.getString('panicPass') ?? _panicPass; - }); - await _safeInitAsync(() async { - _fingerprintPass = - await secureStorage.getString('fingerprintPass') ?? _fingerprintPass; - }); - await _safeInitAsync(() async { - _context = await secureStorage.getObject('ff_context') ?? _context; - }); - - await _safeInitAsync(() async { - _haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal; - }); - - await _safeInitAsync(() async { - _deviceDescription = await secureStorage.getString('deviceDescription') ?? - _deviceDescription; - }); - await loadFirstRun(); - } - - bool _firstRun = true; - bool get firstRun => _firstRun; - - Future loadFirstRun() async { - final prefs = await SharedPreferences.getInstance(); - _firstRun = prefs.getBool('first_run') ?? true; - notifyListeners(); - } - - Future setFirstRun(bool value) async { - final prefs = await SharedPreferences.getInstance(); - _firstRun = value; - await prefs.setBool('first_run', value); - notifyListeners(); - } - - Future deleteFirstRun() async { - final prefs = await SharedPreferences.getInstance(); - _firstRun = true; - await prefs.remove('first_run'); - notifyListeners(); - } - - void update(VoidCallback callback) { - callback(); - notifyListeners(); - } - - late FlutterSecureStorage secureStorage; - - String _deviceDescription = ''; - String get deviceDescription => _deviceDescription; - set deviceDescription(String value) { - _deviceDescription = value; - secureStorage.setString('deviceDescription', value); - } - - void deleteDeviceDescription() { - secureStorage.delete(key: 'deviceDescription'); - } - - BuildContext? _context; - BuildContext? get context => _context; - set context(BuildContext? value) { - _context = value; - secureStorage.setString('ff_context', value.toString()); - } - - void deleteContext() { - secureStorage.delete(key: 'ff_context'); - } - - bool? _haveLocal = null; - bool? get haveLocal => _haveLocal; - set haveLocal(bool? value) { - _haveLocal = value; - secureStorage.setBool('ff_have_local', value); - } - - void deleteHaveLocal() { - secureStorage.delete(key: 'ff_have_local'); - } - - String _fingerprintPass = ''; - String get fingerprintPass => _fingerprintPass; - set fingerprintPass(String value) { - _fingerprintPass = value; - secureStorage.setString('fingerprintPass', value); - } - - void deleteFingerprintPass() { - secureStorage.delete(key: 'fingerprintPass'); - } - - String _accessPass = ''; - String get accessPass => _accessPass; - set accessPass(String value) { - _accessPass = value; - secureStorage.setString('accessPass', value); - } - - void deleteAccessPass() { - secureStorage.delete(key: 'accessPass'); - } - - String _panicPass = ''; - String get panicPass => _panicPass; - set panicPass(String value) { - _panicPass = value; - secureStorage.setString('panicPass', value); - } - - void deletePanicPass() { - secureStorage.delete(key: 'panicPass'); - } - - String? _tokenAPNS = ''; - String? get tokenAPNS => _tokenAPNS; - - set tokenAPNS(String? value) { - _tokenAPNS = value; - if (value != null) { - secureStorage.setString('ff_tokenAPNS', value); - } else { - secureStorage.delete(key: 'ff_tokenAPNS'); - } - } - - void deleteTokenAPNS() { - secureStorage.delete(key: 'ff_tokenAPNS'); - AppState().tokenAPNS = ''; - } - - String _email = ''; - String get email => _email; - set email(String value) { - _email = value; - secureStorage.setString('ff_email', value); - } - - void deleteEmail() { - secureStorage.delete(key: 'ff_email'); - AppState().email = ''; - } - - String _passwd = ''; - String get passwd => _passwd; - set passwd(String value) { - _passwd = value; - secureStorage.setString('ff_passwd', value); - } - - void deletePasswd() { - secureStorage.delete(key: 'ff_passwd'); - AppState().passwd = ''; - } - - String _deviceType = ''; - String get deviceType => _deviceType; - set deviceType(String value) { - _deviceType = value; - secureStorage.setString('ff_deviceType', value); - } - - void deleteDevice() { - secureStorage.delete(key: 'ff_deviceType'); - AppState().deviceType = ''; - } - - bool _isLogged = false; - bool get isLogged => _isLogged; - set isLogged(bool value) { - _isLogged = value; - secureStorage.setBool('ff_isLogged', value); - } - - void deleteIsLogged() { - secureStorage.delete(key: 'ff_isLogged'); - } - - String _token = ''; - String get token => _token; - set token(String value) { - _token = value; - secureStorage.setString('ff_token', value); - } - - void deleteToken() { - secureStorage.delete(key: 'ff_token'); - AppState().token = ''; - } - - void deleteAll() { - AppState().deleteAccessPass(); - AppState().deleteDevice(); - AppState().deleteEmail(); - AppState().deleteFingerprintPass(); - AppState().deleteIsLogged(); - AppState().deletePasswd(); - AppState().deletePanicPass(); - AppState().deleteToken(); - AppState().deleteTokenAPNS(); - AppState().deleteContext(); - secureStorage.deleteAll(); - - AppState().isLogged = false; - AppState().setFirstRun(false); - - AppState().update(() {}); - } -} - -void _safeInit(Function() initializeField) { - try { - initializeField(); - } catch (_) {} -} - -Future _safeInitAsync(Function() initializeField) async { - try { - await initializeField(); - } catch (_) {} -} - -extension FlutterSecureStorageExtensions on FlutterSecureStorage { - static final _lock = Lock(); - - Future writeSync({required String key, String? value}) async => - await _lock.synchronized(() async { - await write(key: key, value: value); - }); - - void remove(String key) => delete(key: key); - - Future getString(String key) async => await read(key: key); - Future setString(String key, String value) async => - await writeSync(key: key, value: value); - - Future getBool(String key) async => (await read(key: key)) == 'true'; - Future setBool(String key, bool? value) async => - await writeSync(key: key, value: value.toString()); - - Future getInt(String key) async => - int.tryParse(await read(key: key) ?? ''); - Future setInt(String key, int value) async => - await writeSync(key: key, value: value.toString()); - - Future getDouble(String key) async => - double.tryParse(await read(key: key) ?? ''); - Future setDouble(String key, double value) async => - await writeSync(key: key, value: value.toString()); - - Future getObject(String key) async { - final value = await read(key: key); - if (value == null || value.isEmpty) { - return null; - } - return value as BuildContext; - } - - Future?> getStringList(String key) async => - await read(key: key).then((result) { - if (result == null || result.isEmpty) { - return null; - } - return const CsvToListConverter() - .convert(result) - .first - .map((e) => e.toString()) - .toList(); - }); - Future setStringList(String key, List value) async => - await writeSync( - key: key, value: const ListToCsvConverter().convert([value])); -} diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 0a001a68..b66aeb0f 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -4,7 +4,8 @@ import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:hub/backend/notifications/firebase_messaging_service.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/utils/cache_util.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -59,13 +60,9 @@ class PhpGroup { class UnregisterDevice { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); return ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -94,16 +91,10 @@ class DeletePet { int? petID = 0, }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'excluirPet'; return ApiManager.instance.makeApiCall( @@ -145,16 +136,10 @@ class UpdatePet { String? notes = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'atualizarPet'; return ApiManager.instance.makeApiCall( @@ -199,16 +184,10 @@ class GetPets { int? pageSize = 0, }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'consultaPets'; return ApiManager.instance.makeApiCall( @@ -241,16 +220,10 @@ class GetPetPhoto { int? petId = 0, }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'consultaFotoPet'; return ApiManager.instance.makeApiCall( @@ -290,16 +263,10 @@ class RegisterPet { String? notes = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'cadastrarPet'; return ApiManager.instance.makeApiCall( @@ -344,16 +311,9 @@ class BuscaEnconcomendas { String? adresseeType = '', String? status = '', }) async { - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'getEncomendas'; final baseUrl = PhpGroup.getBaseUrl(); @@ -394,17 +354,11 @@ class CancelaVisita { String? DevDesc = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'cancelaVisita'; - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); return ApiManager.instance.makeApiCall( callName: 'cancelaVisita', @@ -435,13 +389,9 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + final devUUID = CacheUtil.get('devUUID'); + final userUUID = CacheUtil.get('userUUID'); + final baseUrl = PhpGroup.getBaseUrl(); return ApiManager.instance.makeApiCall( callName: 'deleteAccount', @@ -470,17 +420,10 @@ class ChangePanic { String? newSenhaPanico = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -513,16 +456,10 @@ class ChangePass { String? newSenha = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -556,13 +493,9 @@ class RespondeVinculo { String? cliID = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); return ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -593,16 +526,10 @@ class ChangeNotifica { String? notifica = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = CacheUtil.get('devUUID'); + final userUUID = CacheUtil.get('userUUID'); + final cliID = CacheUtil.get('cliUUID'); const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -633,13 +560,9 @@ class ChangeNotifica { class UpdToken { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); final token = AppState().token; return ApiManager.instance.makeApiCall( @@ -667,10 +590,8 @@ class UpdToken { class LoginCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); + final devUUID = CacheUtil.get('devUUID'); + final email = AppState().email; final password = AppState().passwd; final type = AppState().deviceType; @@ -772,13 +693,9 @@ class ForgotPasswordCall { class GetLocalsCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); return ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -816,16 +733,10 @@ class PostScheduleVisitorCall { String? foto = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'putVisitante'; return ApiManager.instance.makeApiCall( @@ -877,16 +788,10 @@ class PostScheduleVisitCall { String? obs = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'putVisita'; return ApiManager.instance.makeApiCall( @@ -937,16 +842,10 @@ class GetScheduleVisitCall { String? chaveBusca = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliUUID = await CacheUtil.get('cliUUID'); const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1217,16 +1116,10 @@ class GetScheduleVisitCall { class GetDadosCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliUUID = await CacheUtil.get('cliUUID'); const atividade = 'getDados'; return ApiManager.instance.makeApiCall( @@ -1466,16 +1359,10 @@ class GetVisitorByDocCall { String? documento = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'getVisitante'; return ApiManager.instance.makeApiCall( @@ -1526,16 +1413,10 @@ class GetFotoVisitanteCall { String? tipo = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'getFotoVisitante'; return ApiManager.instance.makeApiCall( @@ -1571,16 +1452,10 @@ class PostProvVisitSchedulingCall { String? proID = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'putAgendamentoProv'; return ApiManager.instance.makeApiCall( @@ -1626,16 +1501,10 @@ class GetVisitsCall { int? pageNumber, }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1895,16 +1764,10 @@ class DeleteVisitCall { String? idVisita = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliID = await CacheUtil.get('cliUUID'); const atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -1944,19 +1807,11 @@ class DeleteVisitCall { class GetPessoasLocalCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final ownerUUID = await db - .get(key: 'ownerUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final ownerUUID = await CacheUtil.get('ownerUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliUUID = await CacheUtil.get('cliUUID'); return ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -2018,16 +1873,10 @@ class RespondeSolicitacaoCall { String? idVisitante = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliUUID = await CacheUtil.get('cliUUID'); const atividade = 'respondeSolicitacao'; return ApiManager.instance.makeApiCall( @@ -2074,16 +1923,10 @@ class GetAccessCall { String? pesTipo = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = await CacheUtil.get('devUUID'); + final userUUID = await CacheUtil.get('userUUID'); + final cliUUID = await CacheUtil.get('cliUUID'); const atividade = 'getAcessos'; return ApiManager.instance.makeApiCall( @@ -2328,19 +2171,13 @@ class GetLiberationsCall { Stream call() { final baseUrl = PhpGroup.getBaseUrl(); final StreamController controller = StreamController(); - final DatabaseHelper db = DatabaseHelper(); Future.microtask(() async { - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - const atividade = 'getSolicitacoes'; + final devUUID = CacheUtil.get('devUUID'); + final userUUID = CacheUtil.get('userUUID'); + final cliUUID = CacheUtil.get('cliUUID'); + const atividade = 'getLiberacoes'; + try { final response = await ApiManager.instance.makeApiCall( callName: 'getLiberations', @@ -2527,16 +2364,10 @@ class GetMessagesCall { String? tipoDestino = '', }) async { final baseUrl = PhpGroup.getBaseUrl(); - final DatabaseHelper db = DatabaseHelper(); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final devUUID = CacheUtil.get('devUUID'); + final userUUID = CacheUtil.get('userUUID'); + final cliUUID = CacheUtil.get('cliUUID'); const atividade = 'getMensagens'; return ApiManager.instance.makeApiCall( diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index 3dd3ad68..e8492f5a 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -4,7 +4,7 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:hub/app_state.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'notification_service.dart'; diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index c02ff32d..448760dc 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -13,14 +13,14 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:sqflite/sqflite.dart'; Future onMessageReceived( Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final cliUUID = await db .get(key: 'cliUUID', field: 'value') .then((value) => value.toString()); @@ -292,7 +292,7 @@ class NotificationService { await AwesomeNotifications() .isNotificationAllowed() .then((isAllowed) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final bool requestOSnotification = await db .get(key: 'requestOSnotification', field: 'value') .then((value) => value.toString() == 'true'); diff --git a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart index 26968d47..c9e0c559 100644 --- a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart +++ b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import '../../../app_state.dart'; @@ -34,7 +34,7 @@ class _MenuButtonWidgetState extends State { hoverColor: Colors.transparent, highlightColor: Colors.transparent, onTap: () async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final cliUUID = await db .get(key: 'cliUUID', field: 'value') .then((value) => value.toString()); diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index 06f4b4ee..a6b10092 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -3,7 +3,7 @@ import 'package:hub/components/organism_components/bottom_arrow_linked_locals_co import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:provider/provider.dart'; @@ -65,7 +65,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState Future _fetchLocals() async { try { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final devUUID = await db.get(key: 'devUUID', field: 'value'); final userUUID = await db.get(key: 'userUUID', field: 'value'); @@ -173,7 +173,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState labelsHashMap: _labelsHashMap(local), statusHashMap: [_statusHashMap(local)], onTapCardItemAction: () async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); if (local['CLU_STATUS'] == 'A') { db.update('cliUUID', local['CLI_ID'], 'local'); diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart index 6b17df55..c5517351 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart +++ b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart @@ -1,7 +1,7 @@ import 'dart:ffi'; import 'dart:math'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'local_profile_component_widget.dart' show LocalProfileComponentWidget; @@ -11,7 +11,7 @@ import 'package:flutter/material.dart'; class LocalProfileComponentModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); String cliName = ''; String cliUUID = ''; VoidCallback? setStateCallback; 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 e0dbbc42..a5a164b3 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 @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:provider/provider.dart'; @@ -29,7 +29,7 @@ class LocalProfileComponentWidget extends StatefulWidget { class _LocalProfileComponentWidgetState extends State { late LocalProfileComponentModel _model; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); @override void setState(VoidCallback callback) { diff --git a/lib/components/organism_components/menu_component/menu_component_model.dart b/lib/components/organism_components/menu_component/menu_component_model.dart index fe9f9d7e..31e6e01a 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -3,7 +3,7 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:sqflite/sqflite.dart'; import '/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart'; @@ -70,7 +70,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future deliverySchedule(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final bool isProvisional = await db .get(key: 'provisional', field: 'value') @@ -93,7 +93,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future provisionalSchedule(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final isProvisional = await db .get(key: 'provisional', field: 'value') @@ -115,7 +115,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future fastPassAction(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { return value.toString() == 'true'; }) as bool; @@ -202,7 +202,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future signOut(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); showAlertDialog( context, @@ -242,7 +242,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future packageOrder(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { return value.toString() == 'true'; }) as bool; @@ -264,7 +264,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future reservation(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { return value.toString() == 'true'; }) as bool; @@ -383,7 +383,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future petsAction(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); bool isPet = await db.get(key: 'pets', field: 'value').then((value) { return value.toString() == 'true'; }) as bool; diff --git a/lib/components/organism_components/menu_component/menu_component_widget.dart b/lib/components/organism_components/menu_component/menu_component_widget.dart index 26650732..22c4710c 100644 --- a/lib/components/organism_components/menu_component/menu_component_widget.dart +++ b/lib/components/organism_components/menu_component/menu_component_widget.dart @@ -3,7 +3,7 @@ import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/atomic_components/menu_button_item/menu_button_item_widget.dart'; import 'package:hub/components/atomic_components/menu_card_item/menu_card_item.dart'; import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import '/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart'; import '/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart'; diff --git a/lib/components/organism_components/message_well_component/message_well_component_widget.dart b/lib/components/organism_components/message_well_component/message_well_component_widget.dart index abe13043..1965a718 100644 --- a/lib/components/organism_components/message_well_component/message_well_component_widget.dart +++ b/lib/components/organism_components/message_well_component/message_well_component_widget.dart @@ -8,7 +8,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:provider/provider.dart'; import 'package:rxdart/rxdart.dart'; @@ -339,7 +339,7 @@ class MessageWellState { class MessageWellNotifier extends StateNotifier { var _totalPageNumber = 1; int get totalPageNumber => _totalPageNumber; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); set totalPageNumber(int value) { _totalPageNumber = value; diff --git a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart index c9950487..86911a2b 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart @@ -5,12 +5,12 @@ import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:flutter/material.dart'; import 'package:hub/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:intl/intl.dart'; class ScheduleVisitDetailModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart index 5d2c488c..bbfbdbda 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart @@ -2,11 +2,11 @@ import 'package:hub/components/organism_components/up_arrow_linked_locals_compon import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:flutter/material.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart index 0ef05d34..267e858b 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -9,7 +9,7 @@ import 'access_notification_modal_template_component_widget.dart' class AccessNotificationModalTemplateComponentModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart index a95c1eaa..928bcbd4 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart @@ -4,12 +4,12 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class LiberationHistoryItemDetailsTemplateComponentModel extends FlutterFlowModel< LiberationHistoryItemDetailsTemplateComponentWidget> { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart index 19311f40..0f3ad802 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart @@ -2,12 +2,12 @@ import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:sqflite/sqflite.dart'; class ScheduleProvisionalVisitPageModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); String cliUUID = ''; String devUUID = ''; String userUUID = ''; diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart index 68f8a91f..b2b1b4cd 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:provider/provider.dart'; diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart index 3e752121..9328aa5b 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/backend/api_requests/api_calls.dart'; @@ -12,7 +12,7 @@ import 'regisiter_vistor_template_component_widget.dart'; class RegisiterVistorTemplateComponentModel extends FlutterFlowModel { Timer? _debounceTimer; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart index e17c09d5..1a2eb353 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart @@ -3,7 +3,7 @@ import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/flutter_flow/random_data_util.dart'; import 'package:hub/pages/home_page/home_page_model.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/device_util.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; @@ -86,7 +86,7 @@ class SignInTemplateComponentModel }) async { try { final ApiCallResponse? response; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final LoginCall callback = PhpGroup.loginCall; AppState().deviceDescription = randomString( 10, diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart index ab310d6f..046448b1 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart @@ -1,4 +1,4 @@ -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -6,7 +6,7 @@ import 'view_visit_detail_widget.dart' show ViewVisitDetailWidget; import 'package:flutter/material.dart'; class ViewVisitDetailModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart index ef420f06..f1efb91a 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart @@ -3,11 +3,11 @@ import 'package:hub/components/templates_components/visitor_search_modal_templat import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:flutter/material.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/main.dart b/lib/main.dart index 270f2dc9..b75c9dda 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,7 +15,9 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; +import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:provider/provider.dart'; import 'package:responsive_framework/responsive_framework.dart'; @@ -23,17 +25,20 @@ final GlobalKey navigatorKey = GlobalKey(); Future initializeApp() async { WidgetsFlutterBinding.ensureInitialized(); - await DatabaseHelper().database; + await SQLiteStorageHelper().database; + final sharedPreferencesHelper = SharedPreferencesStorageHelper(); + final SecureStorageHelper secureStorageHelper = SecureStorageHelper(); + + await sharedPreferencesHelper.initialize(); + + if (sharedPreferencesHelper.isFirstRun) { + // Execute actions for the first run + sharedPreferencesHelper.isFirstRun = false; + secureStorageHelper.deleteAll(); + } final status = await AppTrackingTransparency.requestTrackingAuthorization(); - final appState = AppState(); - await appState.initializePersistedState(); - - if (AppState().firstRun == true) { - AppState().deleteAll(); - } - await Firebase.initializeApp(); await NotificationService.initialize(); @@ -56,8 +61,8 @@ Future initializeApp() async { Future foregroundHandleMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - AppState().haveLocal = true; - AppState().context!.go('/homePage'); + SecureStorageHelper().set('haveLocal', 'true'); + SecureStorageHelper().context?.go('/homePage'); } if (!Platform.isIOS) { NotificationService.show( @@ -69,8 +74,8 @@ Future foregroundHandleMessage(RemoteMessage message) async { Future _backgroundHandleMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - AppState().haveLocal = true; - AppState().context!.go('/homePage'); + SecureStorageHelper().set('haveLocal', 'true'); + SecureStorageHelper().context?.go('/homePage'); } } @@ -135,9 +140,9 @@ class _AppState extends State { @override Widget build(BuildContext context) { return MultiProvider( - providers: [ - ChangeNotifierProvider(create: (_) => AppState()), - ], + providers: const [], + // ChangeNotifierProvider(create: (_) => {AppState()}), + child: MaterialApp.router( title: 'FRE ACCESS HUB', builder: (context, widget) => ResponsiveBreakpoints.builder( diff --git a/lib/pages/acess_history_page/acess_history_page_model.dart b/lib/pages/acess_history_page/acess_history_page_model.dart index ca9a17ad..db3be583 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -4,10 +4,10 @@ import 'package:hub/components/molecular_components/message_opt_modal/opt_modal_ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/acess_history_page/acess_history_page_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class AcessHistoryPageModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/pages/fast_pass_page/fast_pass_page_widget.dart b/lib/pages/fast_pass_page/fast_pass_page_widget.dart index 816f4ca7..448b7219 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -5,7 +5,7 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -18,7 +18,7 @@ class FastPassPageWidget extends StatefulWidget { class _FastPassPageWidgetState extends State { late InAppWebViewController _controllerIOS; late WebViewController _controllerAll; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); Future> initVariables() async { final email = AppState().email; diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index 1f989aa3..242aa1d8 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -5,11 +5,11 @@ import 'package:hub/components/organism_components/menu_component/menu_component import 'package:hub/components/organism_components/message_well_component/message_well_component_model.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/home_page/home_page_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class HomePageModel extends FlutterFlowModel { bool isGrid = false; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String cliUUID; late final String userUUID; diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index be2f828b..dc634217 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -11,7 +11,7 @@ import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/home_page/home_page_model.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart'; class HomePageWidget extends StatefulWidget { @@ -25,7 +25,7 @@ class _HomePageWidgetState extends State { late HomePageModel _model; final scaffoldKey = GlobalKey(); late LocalProfileComponentWidget _localProfileComponentWidget; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); _HomePageWidgetState() { _localProfileComponentWidget = LocalProfileComponentWidget(); diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index 493b34e9..23db4207 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -5,10 +5,10 @@ import 'package:hub/flutter_flow/request_manager.dart'; import 'package:flutter/material.dart'; import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class LiberationHistoryModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/pages/message_history_page/message_history_page_model.dart b/lib/pages/message_history_page/message_history_page_model.dart index 8c410e87..49857b82 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -5,11 +5,11 @@ import 'package:hub/flutter_flow/request_manager.dart'; import 'package:flutter/material.dart'; import 'package:hub/pages/message_history_page/message_history_page_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class MessageHistoryPageModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index b9746a13..a4d9898d 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -9,7 +9,7 @@ import 'package:hub/components/templates_components/details_component/details_co import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; @@ -28,7 +28,7 @@ class _PackageOrderPage extends State { final int _pageSize = 10; bool _hasData = false; bool _loading = false; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String cliUUID; late Future _orderFuture; diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index 7ab0c732..bee6cf74 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -6,7 +6,7 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/liberation_history/liberation_history_model.dart'; import 'package:hub/pages/pets_page/pets_page_model.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; @@ -243,7 +243,7 @@ class _PetsHistoryScreenState extends State } ], onTapCardItemAction: () async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final cliUUID = await db .get(key: 'cliUUID', field: 'value') .then((value) => value.toString()); diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index 06b9806f..927333aa 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -12,14 +12,14 @@ import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/form_field_controller.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/pets_page/pets_page_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/image_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; class PetsPageModel extends FlutterFlowModel { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 6df152e5..7fa32d78 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -6,13 +6,13 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:share_plus/share_plus.dart'; import 'package:sqflite/sqflite.dart'; class PreferencesPageModel with ChangeNotifier { final unfocusNode = FocusNode(); - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); bool fingerprint = false; bool person = false; bool notify = false; diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index 47a17c81..12a3fedb 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -6,7 +6,7 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/preferences_settings_page/preferences_settings_model.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:provider/provider.dart'; class PreferencesPageWidget extends StatefulWidget { @@ -17,7 +17,7 @@ class PreferencesPageWidget extends StatefulWidget { } class _PreferencesPageWidgetState extends State { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); @override void initState() { diff --git a/lib/pages/qr_code_page/qr_code_page_model.dart b/lib/pages/qr_code_page/qr_code_page_model.dart index bfe62ece..bff5e830 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -3,7 +3,7 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/qr_code_page/qr_code_page_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:qr_flutter/qr_flutter.dart'; class QrCodePageModel extends FlutterFlowModel { @@ -14,7 +14,7 @@ class QrCodePageModel extends FlutterFlowModel { String? key = null; DateTime? time; - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final bool isFingerprint; late final String userDevUUID; diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index c2aae8b3..438f6e84 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -15,7 +15,7 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/qr_code_page/qr_code_page_model.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:percent_indicator/circular_percent_indicator.dart'; // import 'package:percent_indicator/percent_indicator.dart'; diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index 93bd6ae6..ffac852c 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); final String userDevUUID = await db .get(key: 'userDevUUID', field: 'value') .then((value) => value.toString()); diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index ea7f37fb..755f4e0f 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -5,7 +5,7 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:sqflite/sqflite.dart'; import 'package:url_launcher/url_launcher_string.dart'; @@ -17,7 +17,7 @@ class ReservationPageWidget extends StatefulWidget { } class _ReservationPageWidgetState extends State { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late InAppWebViewController _controllerIOS; late WebViewController _controllerAll; 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 dadb8b1b..0e6c97e8 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 @@ -15,7 +15,7 @@ import 'package:hub/flutter_flow/request_manager.dart'; import 'package:flutter/material.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart'; import 'package:hub/pages/schedule_complete_visit_page/visit_history_page_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/mixins/status_mixin.dart'; import 'package:hub/shared/utils/validator_util.dart'; import 'package:intl/intl.dart'; @@ -26,7 +26,7 @@ class ScheduleCompleteVisitPageModel late VoidCallback safeSetState; late Function(Function) updateState; final _visitHistoryManager = FutureRequestManager(); - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String cliUUID; late final String userUUID; diff --git a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart index 208d701d..292f212b 100644 --- a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart @@ -5,7 +5,7 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart'; -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/mixins/status_mixin.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; @@ -20,7 +20,7 @@ class VisitHistoryWidget extends ScheduleComplete { class _VisitHistoryWidgetState extends State with TickerProviderStateMixin, Status { - final DatabaseHelper db = DatabaseHelper(); + final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -35,15 +35,9 @@ class _VisitHistoryWidgetState extends State List _visitWrap = []; Future _initVariables() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = await db.get('devUUID').then((value) => value.toString()); + userUUID = await db.get('userUUID').then((value) => value.toString()); + cliUUID = await db.get('cliUUID').then((value) => value.toString()); } @override @@ -252,19 +246,15 @@ class _VisitHistoryWidgetState extends State }, ], onTapCardItemAction: () async { - final DatabaseHelper db = DatabaseHelper(); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - final cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + final SQLiteStorageHelper db = SQLiteStorageHelper(); + final cliUUID = + await db.get('cliUUID').then((value) => value.toString()); + final cliName = + await db.get('cliName').then((value) => value.toString()); + final devUUID = + await db.get('devUUID').then((value) => value.toString()); + final userUUID = + await db.get('userUUID').then((value) => value.toString()); await showDialog( useSafeArea: true, context: context, diff --git a/lib/pages/welcome_page/welcome_page_widget.dart b/lib/pages/welcome_page/welcome_page_widget.dart index 6b74a753..63bf188c 100644 --- a/lib/pages/welcome_page/welcome_page_widget.dart +++ b/lib/pages/welcome_page/welcome_page_widget.dart @@ -1,3 +1,4 @@ +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/mixins/switcher_mixin.dart'; import '/components/templates_components/welcome_template_component/welcome_template_component_widget.dart'; @@ -29,13 +30,13 @@ class _WelcomePageWidgetState extends State { // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { if (isAndroid == true) { - AppState().deviceType = 'Android'; + SecureStorageHelper().deviceType = 'Android'; setState(() {}); } else if (isiOS == true) { - AppState().deviceType = 'iOS'; + SecureStorageHelper().deviceType = 'iOS'; setState(() {}); } else { - AppState().deviceType = 'Web'; + SecureStorageHelper().deviceType = 'Web'; setState(() {}); } }); @@ -50,8 +51,6 @@ class _WelcomePageWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); - return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/shared/extensions/flutter_secure_storage_extensions.dart b/lib/shared/extensions/flutter_secure_storage_extensions.dart new file mode 100644 index 00000000..8bba2507 --- /dev/null +++ b/lib/shared/extensions/flutter_secure_storage_extensions.dart @@ -0,0 +1,56 @@ +import 'package:csv/csv.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:synchronized/synchronized.dart'; + +extension FlutterSecureStorageExtensions on FlutterSecureStorage { + static final _lock = Lock(); + + Future writeSync({required String key, String? value}) async => + await _lock.synchronized(() async { + await write(key: key, value: value); + }); + + void remove(String key) => delete(key: key); + + Future getString(String key) async => await read(key: key); + Future setString(String key, String value) async => + await writeSync(key: key, value: value); + + Future getBool(String key) async => (await read(key: key)) == 'true'; + Future setBool(String key, bool? value) async => + await writeSync(key: key, value: value.toString()); + + Future getInt(String key) async => + int.tryParse(await read(key: key) ?? ''); + Future setInt(String key, int value) async => + await writeSync(key: key, value: value.toString()); + + Future getDouble(String key) async => + double.tryParse(await read(key: key) ?? ''); + Future setDouble(String key, double value) async => + await writeSync(key: key, value: value.toString()); + + Future getObject(String key) async { + final value = await read(key: key); + if (value == null || value.isEmpty) { + return null; + } + return value as BuildContext; + } + + Future?> getStringList(String key) async => + await read(key: key).then((result) { + if (result == null || result.isEmpty) { + return null; + } + return const CsvToListConverter() + .convert(result) + .first + .map((e) => e.toString()) + .toList(); + }); + Future setStringList(String key, List value) async => + await writeSync( + key: key, value: const ListToCsvConverter().convert([value])); +} diff --git a/lib/shared/helpers/secure_storage_helper.dart b/lib/shared/helpers/secure_storage_helper.dart new file mode 100644 index 00000000..629b3f4e --- /dev/null +++ b/lib/shared/helpers/secure_storage_helper.dart @@ -0,0 +1,140 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:hub/shared/utils/storage_util.dart'; +import 'package:synchronized/synchronized.dart'; + +class SecureStorageHelper extends ChangeNotifier implements Storage { + static final SecureStorageHelper _instance = SecureStorageHelper._internal(); + final FlutterSecureStorage _secureStorage = const FlutterSecureStorage(); + static final _lock = Lock(); + + factory SecureStorageHelper() => _instance; + + SecureStorageHelper._internal(); + + Future initializePersistedState() async { + await _safeInitAsync(() async { + _email = await _getString('ff_email'); + _passwd = await _getString('ff_passwd'); + _deviceType = await _getString('ff_deviceType'); + _isLogged = await _getBool('ff_isLogged'); + _tokenAPNS = await _getString('ff_tokenAPNS'); + _accessPass = await _getString('accessPass'); + _panicPass = await _getString('panicPass'); + _fingerprintPass = await _getString('fingerprintPass'); + _context = await _getObject('ff_context'); + _haveLocal = await _getBool('ff_have_local'); + _deviceDescription = await _getString('deviceDescription'); + }); + } + + Future _safeInitAsync(Future Function() initFunction) async { + await _lock.synchronized(() async { + try { + await initFunction(); + } catch (e) { + // Log or handle the error + } + }); + } + + Future _getString(String key) async { + return await _secureStorage.read(key: key) ?? ''; + } + + Future _getBool(String key) async { + return (await _secureStorage.read(key: key))?.toLowerCase() == 'true'; + } + + Future _getObject(String key) async { + // Implement your object retrieval logic here + return null; + } + + void update(VoidCallback callback) { + callback(); + notifyListeners(); + } + + String _deviceDescription = ''; + String get deviceDescription => _deviceDescription; + set deviceDescription(String value) => _setString('deviceDescription', value); + + BuildContext? _context; + BuildContext? get context => _context; + set context(BuildContext? value) => + _setString('ff_context', value.toString()); + + bool? _haveLocal; + bool? get haveLocal => _haveLocal; + set haveLocal(bool? value) => _setBool('ff_have_local', value); + + String _fingerprintPass = ''; + String get fingerprintPass => _fingerprintPass; + set fingerprintPass(String value) => _setString('fingerprintPass', value); + + String _accessPass = ''; + String get accessPass => _accessPass; + set accessPass(String value) => _setString('accessPass', value); + + String _panicPass = ''; + String get panicPass => _panicPass; + set panicPass(String value) => _setString('panicPass', value); + + String? _tokenAPNS = ''; + String? get tokenAPNS => _tokenAPNS; + set tokenAPNS(String? value) => _setString('ff_tokenAPNS', value ?? ''); + + String _email = ''; + String get email => _email; + set email(String value) => _setString('ff_email', value); + + String _passwd = ''; + String get passwd => _passwd; + set passwd(String value) => _setString('ff_passwd', value); + + String _deviceType = ''; + String get deviceType => _deviceType; + set deviceType(String value) => _setString('ff_deviceType', value); + + bool _isLogged = false; + bool get isLogged => _isLogged; + set isLogged(bool value) => _setBool('ff_isLogged', value); + + String _token = ''; + String get token => _token; + set token(String value) => _setString('ff_token', value); + + Future _setString(String key, String value) async { + await _secureStorage.write(key: key, value: value); + } + + Future _setBool(String key, bool? value) async { + await _secureStorage.write(key: key, value: value.toString()); + } + + void deleteAll() { + _secureStorage.deleteAll(); + } + + @override + Future set(String key, dynamic value) async { + if (value is String) { + await _setString(key, value); + } else if (value is bool) { + await _setBool(key, value); + } else if (value is int || value is double) { + await _setString(key, value.toString()); + } + } + + @override + Future get(String key) async { + return await _secureStorage.read(key: key); + } + + @override + Future delete(String key) async { + await _secureStorage.delete(key: key); + } +} diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart new file mode 100644 index 00000000..901f5ad9 --- /dev/null +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -0,0 +1,61 @@ +import 'package:hub/shared/utils/storage_util.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class SharedPreferencesStorageHelper implements Storage { + late SharedPreferences _prefs; + + static final SharedPreferencesStorageHelper _instance = + SharedPreferencesStorageHelper._internal(); + + factory SharedPreferencesStorageHelper() { + return _instance; + } + + SharedPreferencesStorageHelper._internal(); + + Future initialize() async { + _prefs = await SharedPreferences.getInstance(); + _isFirstRun = _prefs.getBool('first_run') ?? true; + } + + bool _isFirstRun = true; + bool get isFirstRun => _isFirstRun; + set isFirstRun(bool value) { + _isFirstRun = value; + set('first_run', value); + } + + @override + Future set(String key, dynamic value) async { + if (value is bool) { + await _prefs.setBool(key, value); + } else if (value is String) { + await _prefs.setString(key, value); + } else if (value is int) { + await _prefs.setInt(key, value); + } else if (value is double) { + await _prefs.setDouble(key, value); + } else if (value is List) { + await _prefs.setStringList(key, value); + } + } + + @override + Future get(String key) async { + try { + return _prefs.get(key); + } catch (e) { + // Log or handle the error + return null; + } + } + + @override + Future delete(String key) async { + try { + await _prefs.remove(key); + } catch (e) { + // Log or handle the error + } + } +} diff --git a/lib/shared/helpers/db_helper.dart b/lib/shared/helpers/sqlite_storage_helper.dart similarity index 85% rename from lib/shared/helpers/db_helper.dart rename to lib/shared/helpers/sqlite_storage_helper.dart index 3e82a013..d32e745c 100644 --- a/lib/shared/helpers/db_helper.dart +++ b/lib/shared/helpers/sqlite_storage_helper.dart @@ -16,13 +16,13 @@ class DatabaseConfig { static const String columnCreatedAt = 'createdAt'; } -class DatabaseHelper { - static final DatabaseHelper _instance = DatabaseHelper._internal(); +class SQLiteStorageHelper { + static final SQLiteStorageHelper _instance = SQLiteStorageHelper._internal(); static Database? _database; - factory DatabaseHelper() => _instance; + factory SQLiteStorageHelper() => _instance; - DatabaseHelper._internal(); + SQLiteStorageHelper._internal(); Future get database async { if (_database != null) return _database!; @@ -130,7 +130,7 @@ class DatabaseHelper { _database = null; } - Future get({String? key, String? field}) async { + Future getByField({String? key, String? field}) async { try { final db = await database; List> queryResult; @@ -172,6 +172,39 @@ class DatabaseHelper { } } + Future get(String? key) async { + try { + final db = await database; + List> queryResult; + const String field = DatabaseConfig.columnValue; + + if (key != null) { + queryResult = await db.query( + DatabaseConfig.tableKeychain, + columns: [field], + where: '${DatabaseConfig.columnKey} = ?', + whereArgs: [key], + ); + } else { + queryResult = await db.query( + DatabaseConfig.tableKeychain, + columns: [field], + ); + } + + log('Query result for key: $key, field: $field -> $queryResult'); + + if (queryResult.isNotEmpty) { + return queryResult.first[field]; + } else { + return null; + } + } catch (error) { + log('Error getting: $error'); + return null; + } + } + Future insert(String key, dynamic value, String? type) async { final db = await database; @@ -188,13 +221,13 @@ class DatabaseHelper { return await db.insert(DatabaseConfig.tableKeychain, data); } - Future update(String key, dynamic value, String? type) async { + Future set(String key, dynamic value) async { final db = await database; final Map data = { DatabaseConfig.columnKey: key, if (value != null) DatabaseConfig.columnValue: value.toString(), - if (type != null) DatabaseConfig.columnType: type, + // if (type != null) DatabaseConfig.columnType: type, DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), DatabaseConfig.columnResolvedAt: null, DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), diff --git a/lib/shared/utils/biometric_util.dart b/lib/shared/utils/biometric_util.dart new file mode 100644 index 00000000..e9b2c7f9 --- /dev/null +++ b/lib/shared/utils/biometric_util.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; +import 'package:local_auth/local_auth.dart'; + +class BiometricHelper { + final LocalAuthentication auth = LocalAuthentication(); + + Future checkBiometrics() async { + try { + return await auth.canCheckBiometrics; + } catch (e) { + // Log or handle the error + return false; + } + } + + Future authenticateBiometric() async { + try { + return await auth.authenticate( + localizedReason: 'Scan your fingerprint to authenticate', + options: const AuthenticationOptions( + biometricOnly: true, + stickyAuth: true, + useErrorDialogs: true, + sensitiveTransaction: true, + ), + ); + } catch (e) { + // Log or handle the error + return false; + } + } +} diff --git a/lib/shared/utils/cache_util.dart b/lib/shared/utils/cache_util.dart new file mode 100644 index 00000000..01855fd2 --- /dev/null +++ b/lib/shared/utils/cache_util.dart @@ -0,0 +1,21 @@ +class CacheManager {} + +class CacheUtil { + static final Map _cache = {}; + + static void set(String key, dynamic value) { + _cache[key] = value; + } + + static dynamic get(String key) { + return _cache[key]; + } + + static void delete(String key) { + _cache.remove(key); + } + + static void clear() { + _cache.clear(); + } +} diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index bfcb1cec..5d095261 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -1,15 +1,11 @@ -import 'package:hub/shared/helpers/db_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final DatabaseHelper db = DatabaseHelper(); - final cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + final SQLiteStorageHelper db = SQLiteStorageHelper(); + final cliName = await db.get('cliName').then((value) => value.toString()); + final cliUUID = await db.get('cliUUID').then((value) => value.toString()); for (var i = 0; i < payload['convites'].length; i++) { await Share.share(''' diff --git a/lib/shared/utils/storage_util.dart b/lib/shared/utils/storage_util.dart new file mode 100644 index 00000000..ec55a336 --- /dev/null +++ b/lib/shared/utils/storage_util.dart @@ -0,0 +1,78 @@ +import 'package:hub/shared/helpers/secure_storage_helper.dart'; +import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/cache_util.dart'; + +abstract class Storage { + Future set(String key, dynamic value); + Future get(String key); + Future delete(String key); +} + +class StorageData { + final String key; + final dynamic value; + final StorageType type; + + StorageData(this.key, this.value, this.type); +} + +enum StorageType { SecureStorage, SharedPreferences, SQLite3 } + +class StorageManager { + final SecureStorageHelper _secureStorage = SecureStorageHelper(); + final SharedPreferencesStorageHelper _sharedPreferences = + SharedPreferencesStorageHelper(); + final SQLiteStorageHelper _sqliteStorage = SQLiteStorageHelper(); + + Future set(StorageData data) async { + switch (data.type) { + case StorageType.SecureStorage: + CacheUtil.set(data.key, data.value); + await _secureStorage.set(data.key, data.value); + break; + case StorageType.SharedPreferences: + await _sharedPreferences.set(data.key, data.value); + break; + case StorageType.SQLite3: + await _sqliteStorage.set(data.key, data.value); + break; + } + } + + Future get(StorageData data) async { + var value = CacheUtil.get(data.key); + if (value == null) { + switch (data.type) { + case StorageType.SecureStorage: + value = await _secureStorage.get(data.key); + break; + case StorageType.SharedPreferences: + value = await _sharedPreferences.get(data.key); + break; + case StorageType.SQLite3: + value = await _sqliteStorage.get(data.key); + break; + } + CacheUtil.set(data.key, value); + } + return value; + } + + Future delete(StorageData data) async { + switch (data.type) { + case StorageType.SecureStorage: + CacheUtil.delete(data.key); + await _secureStorage.delete(data.key); + break; + case StorageType.SharedPreferences: + await _sharedPreferences.delete(data.key); + break; + case StorageType.SQLite3: + await _sqliteStorage.delete(data.key); + break; + } + } +} + +class StorageUtil {} From d82617c7e15e31e3a9796d543c9583e0526cb9a3 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 24 Sep 2024 11:12:36 -0300 Subject: [PATCH 2/6] WIP --- .../qr_code_page/qr_code_page_model.dart | 9 ++---- .../qr_code_page/qr_code_page_widget.dart | 9 +++--- .../reception_page/reception_page_model.dart | 5 ++- .../reception_page/reception_page_widget.dart | 8 +++-- .../register_visitor_page_widget.dart | 1 - .../reservation_page_widget.dart | 31 ++++++++----------- .../schedule_complete_visit_page_model.dart | 12 ++----- .../schedule_complete_visit_page_widget.dart | 2 -- lib/shared/helpers/secure_storage_helper.dart | 2 +- .../shared_preferences_storage_helper.dart | 4 +++ lib/shared/utils/biometric_util.dart | 6 ++-- lib/shared/utils/storage_util.dart | 19 ++++++++---- 12 files changed, 53 insertions(+), 55 deletions(-) diff --git a/lib/pages/qr_code_page/qr_code_page_model.dart b/lib/pages/qr_code_page/qr_code_page_model.dart index bff5e830..af6298d5 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -28,12 +28,9 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = await db - .get(key: 'fingerprint', field: 'value') - .then((value) => value.toString() == 'true'); - userDevUUID = await db - .get(key: 'userDevUUID', field: 'value') - .then((value) => value.toString()); + isFingerprint = + await db.get('fingerprint').then((value) => value.toString() == 'true'); + userDevUUID = await db.get('userDevUUID').then((value) => value.toString()); } @override diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index 438f6e84..7b98bf8f 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -15,7 +15,9 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/qr_code_page/qr_code_page_model.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/biometric_util.dart'; import 'package:percent_indicator/circular_percent_indicator.dart'; // import 'package:percent_indicator/percent_indicator.dart'; @@ -358,9 +360,8 @@ class _QrCodePageWidgetState extends State } Future _showBiometricsAuth(BuildContext context) async { - AppState() - .checkBiometrics() - .then((value) => AppState().authenticateBiometric().then((value) { + BiometricHelper.checkBiometrics() + .then((value) => BiometricHelper.authenticateBiometric().then((value) { safeSetState(() { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { animationsMap['barcodeOnActionTriggerAnimation']! @@ -371,7 +372,7 @@ class _QrCodePageWidgetState extends State .reverse(); } _model.isAccess = !_model.isAccess; - _model.key = AppState().fingerprintPass; + _model.key = SecureStorageHelper().fingerprintPass; }); })) .onError((error, StackTrace) { diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index ffac852c..89343a1c 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -7,9 +7,8 @@ import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { final SQLiteStorageHelper db = SQLiteStorageHelper(); - final String userDevUUID = await db - .get(key: 'userDevUUID', field: 'value') - .then((value) => value.toString()); + final String userDevUUID = + await db.get('userDevUUID').then((value) => value.toString()); notifyListeners(); Share.share( diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 19eef6ed..62132754 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -8,6 +8,9 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/reception_page/reception_page_model.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; +import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; class ReceptionPageWidget extends StatefulWidget { @@ -26,7 +29,7 @@ class _ReceptionPageWidgetState extends State { @override Widget build(BuildContext context) { - AppState().context = context; + SecureStorageHelper().context = context; return ChangeNotifierProvider( create: (context) => ReceptionPageModel(), child: Scaffold( @@ -151,7 +154,8 @@ class _ReceptionPageWidgetState extends State { child: FFButtonWidget( onPressed: () async { PhpGroup.unregisterDevice(); - AppState().deleteAll(); + + StorageManager.purge(); setState(() {}); context.go( diff --git a/lib/pages/register_visitor_page/register_visitor_page_widget.dart b/lib/pages/register_visitor_page/register_visitor_page_widget.dart index 6b9ec906..e7a84c33 100644 --- a/lib/pages/register_visitor_page/register_visitor_page_widget.dart +++ b/lib/pages/register_visitor_page/register_visitor_page_widget.dart @@ -39,7 +39,6 @@ class _RegisterVisitorPageWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); return Scaffold( appBar: AppBar( backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index 755f4e0f..e9e87ed6 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/app_state.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; @@ -22,24 +23,14 @@ class _ReservationPageWidgetState extends State { late WebViewController _controllerAll; Future> initVariables() async { - final email = await db - .get(key: 'email', field: 'value') - .then((value) => value.toString()); - final name = await db - .get(key: 'userName', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); + final email = await db.get('email').then((value) => value.toString()); + final name = await db.get('userName').then((value) => value.toString()); + final userUUID = await db.get('userUUID').then((value) => value.toString()); + final devUUID = await db.get('devUUID').then((value) => value.toString()); final createdAt = await db - .get(key: 'devUUID', field: 'createdAt') - .then((value) => value.toString()); - final clientId = await db - .get(key: 'cliUUID', field: 'value') + .getByField(key: 'devUUID', field: 'createdAt') .then((value) => value.toString()); + final clientId = await db.get('cliUUID').then((value) => value.toString()); final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; @@ -71,8 +62,12 @@ class _ReservationPageWidgetState extends State { builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return Center(child: CircularProgressIndicator()); - } else if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); + } else if (snapshot.hasError || + snapshot.hasData == false || + snapshot.data!.isEmpty) { + return Center( + child: Text(FFLocalizations.of(context).getVariableText( + enText: 'Unexpected error', ptText: 'Erro inesperado'))); } else if (snapshot.hasData) { final data = snapshot.data!; final url = data['url']!; 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 0e6c97e8..50ed979b 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 @@ -184,15 +184,9 @@ class ScheduleCompleteVisitPageModel } Future _initVariables() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + devUUID = await db.get('devUUID').then((value) => value.toString()); + cliUUID = await db.get('cliUUID').then((value) => value.toString()); + userUUID = await db.get('userUUID').then((value) => value.toString()); } @override diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart index 4d036e82..65d624ba 100644 --- a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart @@ -109,8 +109,6 @@ class _ScheduleCompleteVisitPageWidgetState @override Widget build(BuildContext context) { - context.watch(); - return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/shared/helpers/secure_storage_helper.dart b/lib/shared/helpers/secure_storage_helper.dart index 629b3f4e..c46ce274 100644 --- a/lib/shared/helpers/secure_storage_helper.dart +++ b/lib/shared/helpers/secure_storage_helper.dart @@ -113,7 +113,7 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { await _secureStorage.write(key: key, value: value.toString()); } - void deleteAll() { + Future purge() async { _secureStorage.deleteAll(); } diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart index 901f5ad9..99cacead 100644 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -58,4 +58,8 @@ class SharedPreferencesStorageHelper implements Storage { // Log or handle the error } } + + Future purge() async { + await _prefs.clear(); + } } diff --git a/lib/shared/utils/biometric_util.dart b/lib/shared/utils/biometric_util.dart index e9b2c7f9..5a3faeb0 100644 --- a/lib/shared/utils/biometric_util.dart +++ b/lib/shared/utils/biometric_util.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:local_auth/local_auth.dart'; class BiometricHelper { - final LocalAuthentication auth = LocalAuthentication(); + static final LocalAuthentication auth = LocalAuthentication(); - Future checkBiometrics() async { + static Future checkBiometrics() async { try { return await auth.canCheckBiometrics; } catch (e) { @@ -13,7 +13,7 @@ class BiometricHelper { } } - Future authenticateBiometric() async { + static Future authenticateBiometric() async { try { return await auth.authenticate( localizedReason: 'Scan your fingerprint to authenticate', diff --git a/lib/shared/utils/storage_util.dart b/lib/shared/utils/storage_util.dart index ec55a336..dd08b5fe 100644 --- a/lib/shared/utils/storage_util.dart +++ b/lib/shared/utils/storage_util.dart @@ -20,12 +20,12 @@ class StorageData { enum StorageType { SecureStorage, SharedPreferences, SQLite3 } class StorageManager { - final SecureStorageHelper _secureStorage = SecureStorageHelper(); - final SharedPreferencesStorageHelper _sharedPreferences = + static final SecureStorageHelper _secureStorage = SecureStorageHelper(); + static final SharedPreferencesStorageHelper _sharedPreferences = SharedPreferencesStorageHelper(); - final SQLiteStorageHelper _sqliteStorage = SQLiteStorageHelper(); + static final SQLiteStorageHelper _sqliteStorage = SQLiteStorageHelper(); - Future set(StorageData data) async { + static Future set(StorageData data) async { switch (data.type) { case StorageType.SecureStorage: CacheUtil.set(data.key, data.value); @@ -40,7 +40,7 @@ class StorageManager { } } - Future get(StorageData data) async { + static Future get(StorageData data) async { var value = CacheUtil.get(data.key); if (value == null) { switch (data.type) { @@ -59,7 +59,7 @@ class StorageManager { return value; } - Future delete(StorageData data) async { + static Future delete(StorageData data) async { switch (data.type) { case StorageType.SecureStorage: CacheUtil.delete(data.key); @@ -73,6 +73,13 @@ class StorageManager { break; } } + + static Future purge() async { + // CacheUtil.purge(); + await _secureStorage.purge(); + await _sharedPreferences.purge(); + await _sqliteStorage.purge(); + } } class StorageUtil {} From 43f5839db00c05d65bf9e917e56fed04e1bab1f8 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 25 Sep 2024 09:30:58 -0300 Subject: [PATCH 3/6] wip --- lib/backend/api_requests/api_calls.dart | 181 ++++---- lib/backend/api_requests/api_manager.dart | 22 +- .../firebase_messaging_service.dart | 3 +- .../notifications/notification_service.dart | 25 +- .../menu_button_item_widget.dart | 5 +- .../order_filter_modal_widget.dart | 12 +- ..._arrow_linked_locals_component_widget.dart | 20 +- .../local_profile_component_model.dart | 10 +- .../local_profile_component_widget.dart | 23 +- .../menu_component/menu_component_model.dart | 40 +- .../message_well_component_widget.dart | 1 - .../schedule_visit_detail_model.dart | 7 +- .../schedule_visit_detail_widget.dart | 1 - ...p_arrow_linked_locals_component_model.dart | 17 +- ..._arrow_linked_locals_component_widget.dart | 2 - ...cation_modal_template_component_model.dart | 13 +- ...ation_modal_template_component_widget.dart | 2 - .../card_item_template_component_widget.dart | 2 - .../change_pass_widget.dart | 12 +- .../details_component_widget.dart | 1 - ...item_details_template_component_model.dart | 13 +- ...tem_details_template_component_widget.dart | 2 - .../message_notification_widget.dart | 2 - .../provisional_schedule_template_model.dart | 11 +- .../provisional_shcedule_template_widget.dart | 2 - ...siter_vistor_template_component_model.dart | 7 +- ...iter_vistor_template_component_widget.dart | 1 - .../sign_in_template_component_model.dart | 26 +- .../sign_up_template_component_widget.dart | 6 +- .../view_visit_detail_model.dart | 13 +- .../view_visit_detail_widget.dart | 2 - ...search_modal_template_component_model.dart | 13 +- ...earch_modal_template_component_widget.dart | 2 - lib/flutter_flow/nav/nav.dart | 5 +- lib/main.dart | 129 +++--- .../acess_history_page_model.dart | 13 +- .../delivery_schedule_widget.dart | 1 - .../fast_pass_page/fast_pass_page_widget.dart | 26 +- lib/pages/home_page/home_page_model.dart | 20 +- lib/pages/home_page/home_page_widget.dart | 4 +- .../liberation_history_model.dart | 13 +- .../liberation_history_widget.dart | 1 - .../message_history_page_model.dart | 13 +- .../message_history_page_widget.dart | 1 - .../package_order_page.dart | 5 +- .../people_on_the_property_page_widget.dart | 2 - lib/pages/pets_page/pets_history_screen.dart | 17 +- lib/pages/pets_page/pets_page_model.dart | 17 +- .../preferences_settings_model.dart | 30 +- .../preferences_settings_widget.dart | 5 +- .../provisional_schedule_widget.dart | 1 - .../qr_code_page/qr_code_page_model.dart | 6 +- .../reception_page/reception_page_model.dart | 4 +- .../reservation_page_widget.dart | 18 +- .../schedule_complete_visit_page_model.dart | 9 +- .../visit_history_page_widget.dart | 21 +- lib/shared/helpers/secure_storage_helper.dart | 137 +++--- .../shared_preferences_storage_helper.dart | 3 +- lib/shared/helpers/sqlite_storage_helper.dart | 391 ++++++++++-------- lib/shared/utils/cache_util.dart | 2 - lib/shared/utils/share_util.dart | 5 +- 61 files changed, 640 insertions(+), 758 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index b66aeb0f..71181fe7 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -4,6 +4,7 @@ import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:hub/backend/notifications/firebase_messaging_service.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/utils/cache_util.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; @@ -61,8 +62,8 @@ class UnregisterDevice { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; return ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -92,9 +93,9 @@ class DeletePet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'excluirPet'; return ApiManager.instance.makeApiCall( @@ -137,9 +138,9 @@ class UpdatePet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'atualizarPet'; return ApiManager.instance.makeApiCall( @@ -185,9 +186,9 @@ class GetPets { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'consultaPets'; return ApiManager.instance.makeApiCall( @@ -221,9 +222,9 @@ class GetPetPhoto { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'consultaFotoPet'; return ApiManager.instance.makeApiCall( @@ -264,9 +265,9 @@ class RegisterPet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'cadastrarPet'; return ApiManager.instance.makeApiCall( @@ -311,9 +312,9 @@ class BuscaEnconcomendas { String? adresseeType = '', String? status = '', }) async { - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getEncomendas'; final baseUrl = PhpGroup.getBaseUrl(); @@ -355,9 +356,9 @@ class CancelaVisita { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -389,8 +390,8 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; final baseUrl = PhpGroup.getBaseUrl(); return ApiManager.instance.makeApiCall( @@ -421,9 +422,9 @@ class ChangePanic { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -457,9 +458,9 @@ class ChangePass { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -494,8 +495,8 @@ class RespondeVinculo { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; return ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -527,9 +528,9 @@ class ChangeNotifica { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); - final cliID = CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -561,9 +562,9 @@ class UpdToken { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final token = AppState().token; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final token = SecureStorageHelper().token; return ApiManager.instance.makeApiCall( callName: 'updToken', @@ -590,12 +591,12 @@ class UpdToken { class LoginCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = CacheUtil.get('devUUID'); + final devUUID = SQLiteStorageHelper().devUUID; - final email = AppState().email; - final password = AppState().passwd; - final type = AppState().deviceType; - final description = AppState().deviceDescription; + final email = SecureStorageHelper().email; + final password = SecureStorageHelper().passwd; + final type = SecureStorageHelper().deviceType; + final description = SecureStorageHelper().deviceDescription; final token = FirebaseMessagingService.getToken(); return ApiManager.instance.makeApiCall( @@ -694,8 +695,8 @@ class GetLocalsCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; return ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -734,9 +735,9 @@ class PostScheduleVisitorCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'putVisitante'; return ApiManager.instance.makeApiCall( @@ -789,9 +790,9 @@ class PostScheduleVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'putVisita'; return ApiManager.instance.makeApiCall( @@ -843,9 +844,9 @@ class GetScheduleVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1117,9 +1118,9 @@ class GetDadosCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getDados'; return ApiManager.instance.makeApiCall( @@ -1360,9 +1361,9 @@ class GetVisitorByDocCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getVisitante'; return ApiManager.instance.makeApiCall( @@ -1414,9 +1415,9 @@ class GetFotoVisitanteCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getFotoVisitante'; return ApiManager.instance.makeApiCall( @@ -1453,9 +1454,9 @@ class PostProvVisitSchedulingCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'putAgendamentoProv'; return ApiManager.instance.makeApiCall( @@ -1502,9 +1503,9 @@ class GetVisitsCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1765,9 +1766,9 @@ class DeleteVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -1808,10 +1809,10 @@ class GetPessoasLocalCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final ownerUUID = await CacheUtil.get('ownerUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final ownerUUID = SQLiteStorageHelper().ownerUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; return ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -1874,9 +1875,9 @@ class RespondeSolicitacaoCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'respondeSolicitacao'; return ApiManager.instance.makeApiCall( @@ -1924,9 +1925,9 @@ class GetAccessCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getAcessos'; return ApiManager.instance.makeApiCall( @@ -2173,10 +2174,10 @@ class GetLiberationsCall { final StreamController controller = StreamController(); Future.microtask(() async { - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); - final cliUUID = CacheUtil.get('cliUUID'); - const atividade = 'getLiberacoes'; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; + const atividade = 'getSolicitacoes'; try { final response = await ApiManager.instance.makeApiCall( @@ -2365,9 +2366,9 @@ class GetMessagesCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); - final cliUUID = CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getMensagens'; return ApiManager.instance.makeApiCall( diff --git a/lib/backend/api_requests/api_manager.dart b/lib/backend/api_requests/api_manager.dart index aaaef549..00e12f5e 100644 --- a/lib/backend/api_requests/api_manager.dart +++ b/lib/backend/api_requests/api_manager.dart @@ -1,5 +1,3 @@ -// ignore_for_file: constant_identifier_names, depend_on_referenced_packages, prefer_final_fields - import 'dart:convert'; import 'dart:core'; import 'dart:developer'; @@ -107,11 +105,8 @@ class ApiCallResponse { final http.Response? response; final http.StreamedResponse? streamedResponse; final Object? exception; - // Whether we received a 2xx status (which generally marks success). bool get succeeded => statusCode >= 200 && statusCode < 300; String getHeader(String headerName) => headers[headerName] ?? ''; - // Return the raw body from the response, or if this came from a cloud call - // and the body is not a string, then the json encoded body. String get bodyText => response?.body ?? (jsonBody is String ? jsonBody as String : jsonEncode(jsonBody)); @@ -126,7 +121,7 @@ class ApiCallResponse { dynamic jsonBody; try { if (bodyType == BodyType.BLOB) { - jsonBody = response.bodyBytes; // Armazenar os bytes diretamente + jsonBody = response.bodyBytes; } else { final responseBody = decodeUtf8 && returnBody ? const Utf8Decoder().convert(response.bodyBytes) @@ -153,19 +148,13 @@ class ApiCallResponse { class ApiManager { ApiManager._(); - // Cache that will ensure identical calls are not repeatedly made. static Map _apiCache = {}; static ApiManager? _instance; static ApiManager get instance => _instance ??= ApiManager._(); - // If your API calls need authentication, populate this field once - // the user has authenticated. Alter this as needed. static String? _accessToken; - // You may want to call this if, for example, you make a change to the - // database and no longer want the cached result of a call that may - // have changed. static void clearCache(String callName) => _apiCache.keys .toSet() .forEach((k) => k.callName == callName ? _apiCache.remove(k) : null); @@ -187,7 +176,7 @@ class ApiManager { bool decodeUtf8, bool isStreamingApi, { http.Client? client, - BodyType? bodyType, // Adicionado para verificar o tipo de corpo + BodyType? bodyType, }) async { if (params.isNotEmpty) { final specifier = @@ -213,7 +202,7 @@ class ApiManager { final response = await makeRequest(Uri.parse(apiUrl), headers: toStringMap(headers)); return ApiCallResponse.fromHttpResponse( - response, returnBody, decodeUtf8, bodyType); // Passar bodyType + response, returnBody, decodeUtf8, bodyType); } static Future requestWithBody( @@ -368,7 +357,6 @@ class ApiManager { case null: break; } - // Set "Content-Type" header if it was previously unset. if (contentType != null && !headers.keys.any((h) => h.toLowerCase() == 'content-type')) { headers['Content-Type'] = contentType; @@ -428,7 +416,6 @@ class ApiManager { cache: cache, isStreamingApi: isStreamingApi, ); - // Modify for your specific needs if this differs from your API. if (_accessToken != null) { headers[HttpHeaders.authorizationHeader] = 'Bearer $_accessToken'; } @@ -436,8 +423,6 @@ class ApiManager { apiUrl = 'https://$apiUrl'; } - // If we've already made this exact call before and caching is on, - // return the cached result. if (cache && _apiCache.containsKey(callOptions)) { return _apiCache[callOptions]!; } @@ -504,7 +489,6 @@ class ApiManager { break; } - // If caching is on, cache the result (if present). if (cache) { _apiCache[callOptions] = result; } diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index e8492f5a..963caef3 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -4,6 +4,7 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:hub/app_state.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/log_util.dart'; @@ -64,7 +65,7 @@ class FirebaseMessagingService { final String? deviceToken = await _firebaseMessaging.getToken(); if (deviceToken != null) { - AppState().token = deviceToken; + SecureStorageHelper().token = deviceToken; final ApiCallResponse? response; response = await PhpGroup.updToken.call(); diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index 448760dc..95a587f4 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -13,6 +13,7 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:sqflite/sqflite.dart'; @@ -20,10 +21,8 @@ import 'package:sqflite/sqflite.dart'; Future onMessageReceived( Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final cliUUID = SQLiteStorageHelper().cliUUID; answersRequest( {required BuildContext context, required String? ref, @@ -50,7 +49,7 @@ Future onMessageReceived( switch (handleClick) { case 'visit_request': showDialog( - context: AppState().context!, + context: SecureStorageHelper().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -173,7 +172,7 @@ Future onMessageReceived( break; case 'access': showDialog( - context: AppState().context!, + context: SecureStorageHelper().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -232,7 +231,7 @@ Future onMessageReceived( break; case 'mensagem': showDialog( - context: AppState().context!, + context: SecureStorageHelper().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -255,8 +254,8 @@ Future onMessageReceived( break; case 'enroll_cond': - AppState().haveLocal = true; - AppState().context!.go('/homePage'); + SecureStorageHelper().haveLocal = true; + SecureStorageHelper().context!.go('/homePage'); break; default: break; @@ -292,14 +291,12 @@ class NotificationService { await AwesomeNotifications() .isNotificationAllowed() .then((isAllowed) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final bool requestOSnotification = await db - .get(key: 'requestOSnotification', field: 'value') - .then((value) => value.toString() == 'true'); + final bool requestOSnotification = + SQLiteStorageHelper().requestOSnotification; if (!requestOSnotification) { if (!isAllowed) { - await db.update('requestOSnotification', 'true', 'util'); + SQLiteStorageHelper().requestOSnotification = true; await AwesomeNotifications().requestPermissionToSendNotifications(); } } diff --git a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart index c9e0c559..7f1a787b 100644 --- a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart +++ b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart @@ -34,10 +34,7 @@ class _MenuButtonWidgetState extends State { hoverColor: Colors.transparent, highlightColor: Colors.transparent, onTap: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; if (cliUUID.isEmpty) { return DialogUtil.warningDefault(context); diff --git a/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart b/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart index ddd13a38..ebae1e35 100644 --- a/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart +++ b/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart @@ -4,6 +4,7 @@ import 'package:hub/components/molecular_components/order_filter_modal/order_fil import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; class OrderFilterModalWidget extends StatefulWidget { final String defaultAdresseeType; @@ -25,24 +26,25 @@ class _OrderFilterModalWidgetState extends State { late Map selected; final List> adresseeTypeOptions = [ { - 'title': FFLocalizations.of(AppState().context!) + 'title': FFLocalizations.of(SecureStorageHelper().context!) .getVariableText(enText: 'Resident', ptText: 'Morador'), 'value': 'MOR' }, { - 'title': FFLocalizations.of(AppState().context!) + 'title': FFLocalizations.of(SecureStorageHelper().context!) .getVariableText(enText: 'Property', ptText: 'Propriedade'), 'value': 'PRO' }, ]; final List> statusOptions = [ { - 'title': FFLocalizations.of(AppState().context!).getVariableText( - ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'), + 'title': FFLocalizations.of(SecureStorageHelper().context!) + .getVariableText( + ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'), 'value': 'notPickedUp' }, { - 'title': FFLocalizations.of(AppState().context!) + 'title': FFLocalizations.of(SecureStorageHelper().context!) .getVariableText(ptText: 'Retirado', enText: 'Picked Up'), 'value': 'pickedUp' }, diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index a6b10092..322184b3 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -65,10 +65,6 @@ class _BottomArrowLinkedLocalsComponentWidgetState Future _fetchLocals() async { try { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final devUUID = await db.get(key: 'devUUID', field: 'value'); - final userUUID = await db.get(key: 'userUUID', field: 'value'); - setState(() => _loading = true); var response = await PhpGroup.getLocalsCall.call(); @@ -84,9 +80,9 @@ class _BottomArrowLinkedLocalsComponentWidgetState // Verifica se há apenas um local e se o status é 'A' if (locals.length == 1 && locals[0]['CLU_STATUS'] == 'A') { final local = locals[0]; - db.update('cliUUID', local['CLI_ID'], 'local'); - db.update('cliName', local['CLI_NOME'], 'local'); - db.update('ownerUUID', local['CLU_OWNER_ID'], 'local'); + SQLiteStorageHelper().cliName = local['CLI_NOME']; + SQLiteStorageHelper().cliUUID = local['CLI_ID']; + SQLiteStorageHelper().ownerUUID = local['CLU_OWNER_ID']; context.pop(); } @@ -173,12 +169,10 @@ class _BottomArrowLinkedLocalsComponentWidgetState labelsHashMap: _labelsHashMap(local), statusHashMap: [_statusHashMap(local)], onTapCardItemAction: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - if (local['CLU_STATUS'] == 'A') { - db.update('cliUUID', local['CLI_ID'], 'local'); - db.update('cliName', local['CLI_NOME'], 'local'); - db.update('ownerUUID', local['CLU_OWNER_ID'], 'local'); + SQLiteStorageHelper().cliUUID = local['CLI_ID']; + SQLiteStorageHelper().cliName = local['CLI_NOME']; + SQLiteStorageHelper().ownerUUID = local['CLU_OWNER_ID']; context.pop(); } else if (local['CLU_STATUS'] == 'B') { @@ -247,8 +241,6 @@ class _BottomArrowLinkedLocalsComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - double height = MediaQuery.sizeOf(context).height; return Align( diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart index c5517351..efd60746 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart +++ b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart @@ -1,4 +1,3 @@ -import 'dart:ffi'; import 'dart:math'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; @@ -11,7 +10,6 @@ import 'package:flutter/material.dart'; class LocalProfileComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); String cliName = ''; String cliUUID = ''; VoidCallback? setStateCallback; @@ -22,12 +20,8 @@ class LocalProfileComponentModel } Future getData() async { - cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + cliName = SQLiteStorageHelper().cliName; + cliUUID = SQLiteStorageHelper().cliUUID; setStateCallback?.call(); } 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 a5a164b3..5f0717b3 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 @@ -16,8 +16,6 @@ import 'local_profile_component_model.dart'; export 'local_profile_component_model.dart'; -//// - class LocalProfileComponentWidget extends StatefulWidget { LocalProfileComponentWidget({Key? key}) : super(key: key); @@ -29,7 +27,6 @@ class LocalProfileComponentWidget extends StatefulWidget { class _LocalProfileComponentWidgetState extends State { late LocalProfileComponentModel _model; - final SQLiteStorageHelper db = SQLiteStorageHelper(); @override void setState(VoidCallback callback) { @@ -45,9 +42,7 @@ class _LocalProfileComponentWidgetState _model.setStateCallback = () => safeSetState(() {}); () async { - _model.cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + _model.cliUUID = SQLiteStorageHelper().cliUUID; if (_model.cliUUID.isEmpty) { await processLocals(); @@ -78,11 +73,11 @@ class _LocalProfileComponentWidgetState final petAmountRegister = response.jsonBody['petAmountRegister'] ?? '0'; final name = response.jsonBody['visitado']['VDO_NOME']; - await db.update('whatsapp', whatsapp.toString(), 'local'); - await db.update('provisional', provisional.toString(), 'local'); - await db.update('pets', pets.toString(), 'local'); - await db.update('petAmountRegister', petAmountRegister, 'local'); - await db.update('name', name, 'local'); + SQLiteStorageHelper().whatsapp = whatsapp; + SQLiteStorageHelper().provisional = provisional; + SQLiteStorageHelper().pets = pets; + SQLiteStorageHelper().petAmountRegister = petAmountRegister; + SQLiteStorageHelper().cliName = name; safeSetState(() {}); return; @@ -100,9 +95,7 @@ class _LocalProfileComponentWidgetState try { final GetLocalsCall callback = PhpGroup.getLocalsCall; - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; var response = await callback.call(); List locals = response.jsonBody['locais'] ?? []; @@ -146,8 +139,6 @@ class _LocalProfileComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Container( decoration: const BoxDecoration(), child: Align( diff --git a/lib/components/organism_components/menu_component/menu_component_model.dart b/lib/components/organism_components/menu_component/menu_component_model.dart index 31e6e01a..0d61b860 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -3,7 +3,9 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:sqflite/sqflite.dart'; import '/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart'; @@ -70,11 +72,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future deliverySchedule(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - - final bool isProvisional = await db - .get(key: 'provisional', field: 'value') - .then((value) => value.toString() == 'true') as bool; + final bool isProvisional = SQLiteStorageHelper().provisional; if (isProvisional == true) { context.push( @@ -93,11 +91,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future provisionalSchedule(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - - final isProvisional = await db - .get(key: 'provisional', field: 'value') - .then((value) => value.toString() == 'true') as bool; + final isProvisional = SQLiteStorageHelper().provisional; if (isProvisional == true) { context.push( '/provisionalSchedule', @@ -115,10 +109,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future fastPassAction(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + final isWpp = SQLiteStorageHelper().whatsapp; if (isWpp) { context.push( '/fastPassPage', @@ -202,8 +193,6 @@ class MenuComponentModel extends FlutterFlowModel { } Future signOut(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - showAlertDialog( context, 'Logout', @@ -212,7 +201,7 @@ class MenuComponentModel extends FlutterFlowModel { ptText: 'Tem certeza', ), () async { PhpGroup.unregisterDevice.call(); - AppState().deleteAll(); + StorageManager.purge(); context.go( '/welcomePage', @@ -224,7 +213,7 @@ class MenuComponentModel extends FlutterFlowModel { ), }, ); - await db.purge(); + await SQLiteStorageHelper().purge(); }); } @@ -242,10 +231,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future packageOrder(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + final isWpp = SQLiteStorageHelper().whatsapp; if (isWpp) { context.push( @@ -264,10 +250,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future reservation(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + final isWpp = SQLiteStorageHelper().whatsapp; if (isWpp) { context.push( '/reservation', @@ -383,10 +366,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future petsAction(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - bool isPet = await db.get(key: 'pets', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + bool isPet = SQLiteStorageHelper().pets; if (isPet) { context.push( '/petsPage', diff --git a/lib/components/organism_components/message_well_component/message_well_component_widget.dart b/lib/components/organism_components/message_well_component/message_well_component_widget.dart index 1965a718..81de018c 100644 --- a/lib/components/organism_components/message_well_component/message_well_component_widget.dart +++ b/lib/components/organism_components/message_well_component/message_well_component_widget.dart @@ -339,7 +339,6 @@ class MessageWellState { class MessageWellNotifier extends StateNotifier { var _totalPageNumber = 1; int get totalPageNumber => _totalPageNumber; - final SQLiteStorageHelper db = SQLiteStorageHelper(); set totalPageNumber(int value) { _totalPageNumber = value; diff --git a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart index 86911a2b..1edff6aa 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart @@ -10,7 +10,6 @@ import 'package:intl/intl.dart'; class ScheduleVisitDetailModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -60,9 +59,9 @@ class ScheduleVisitDetailModel } Future initDB() async { - devUUID = await db.get(key: 'devUUID', field: 'value'); - userUUID = await db.get(key: 'userUUID', field: 'value'); - cliUUID = await db.get(key: 'cliUUID', field: 'value'); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart index b347c157..9051c4d5 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart @@ -94,7 +94,6 @@ class _ScheduleVisitDetailWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); final visitorsData = widget.visitorJsonList!.toList().take(2).toList(); final visitorsDataItem = visitorsData[0]; diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart index bbfbdbda..fff98ee1 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart @@ -6,7 +6,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -18,18 +17,10 @@ class UpArrowLinkedLocalsComponentModel } Future initDB() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + cliName = SQLiteStorageHelper().cliName; } @override diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart index 85ca7b2c..d2a448e5 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart @@ -42,8 +42,6 @@ class _UpArrowLinkedLocalsComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Align( alignment: const AlignmentDirectional(0.0, -1.0), child: Container( diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart index 267e858b..a24124ac 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart @@ -9,7 +9,6 @@ import 'access_notification_modal_template_component_widget.dart' class AccessNotificationModalTemplateComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -33,15 +32,9 @@ class AccessNotificationModalTemplateComponentModel } Future initDB() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart index ffb2bd97..999fcf5b 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart @@ -67,8 +67,6 @@ class _AccessNotificationModalTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - String labelTypeResident = FFLocalizations.of(context) .getVariableText(enText: 'Resident', ptText: 'Morador'); diff --git a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart index 01386be5..80be7d12 100644 --- a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart +++ b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart @@ -208,8 +208,6 @@ class _CardItemTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return InkWell( splashColor: Colors.transparent, focusColor: Colors.transparent, diff --git a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart index 36f51006..832f2cd6 100644 --- a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart +++ b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -129,7 +130,7 @@ class _PassKeyTemplateWidgetState extends State { child: Text( FFLocalizations.of(context).getVariableText( enText: 'INSERT PASSWORD', - ptText: AppState().accessPass != '' + ptText: SecureStorageHelper().accessPass != '' ? 'ALTERAR SENHA' : 'ADICIONAR SENHA', ), @@ -316,9 +317,12 @@ class _PassKeyTemplateWidgetState extends State { context.pop(true); }, text: FFLocalizations.of(context).getVariableText( - ptText: - AppState().accessPass != '' ? 'Alterar' : 'Adicionar', - enText: AppState().accessPass != '' ? 'Change' : 'Add', + ptText: SecureStorageHelper().accessPass != '' + ? 'Alterar' + : 'Adicionar', + enText: SecureStorageHelper().accessPass != '' + ? 'Change' + : 'Add', ), options: FFButtonOptions( width: 270.0, diff --git a/lib/components/templates_components/details_component/details_component_widget.dart b/lib/components/templates_components/details_component/details_component_widget.dart index 48bf6691..ee959e7f 100644 --- a/lib/components/templates_components/details_component/details_component_widget.dart +++ b/lib/components/templates_components/details_component/details_component_widget.dart @@ -64,7 +64,6 @@ class _DetailsComponentWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); // CachedNetworkImage.evictFromCache(widget.imagePath ?? ''); return Container( diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart index 928bcbd4..e6653c0b 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart @@ -9,7 +9,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class LiberationHistoryItemDetailsTemplateComponentModel extends FlutterFlowModel< LiberationHistoryItemDetailsTemplateComponentWidget> { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -31,15 +30,9 @@ class LiberationHistoryItemDetailsTemplateComponentModel void initState(BuildContext context) {} Future initDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart index 23c6a71e..23a0d124 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart @@ -68,8 +68,6 @@ class _LiberationHistoryItemDetailsTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Align( alignment: const AlignmentDirectional(0.0, 0.0), child: Padding( diff --git a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart index 31b859f5..303780ca 100644 --- a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart +++ b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart @@ -59,8 +59,6 @@ class _MessageNotificationModalTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart index 0f3ad802..d62becb1 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart @@ -7,7 +7,6 @@ import 'package:sqflite/sqflite.dart'; class ScheduleProvisionalVisitPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); String cliUUID = ''; String devUUID = ''; String userUUID = ''; @@ -125,11 +124,11 @@ class ScheduleProvisionalVisitPageModel } Future init() async { - cliUUID = await db.get(key: 'cliUUID', field: 'value'); - devUUID = await db.get(key: 'devUUID', field: 'value'); - userUUID = await db.get(key: 'userUUID', field: 'value'); - cliName = await db.get(key: 'cliName', field: 'value'); - ownerUUID = await db.get(key: 'ownerUUID', field: 'value'); + cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliName = SQLiteStorageHelper().cliName; + ownerUUID = SQLiteStorageHelper().ownerUUID; setState?.call(); } diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart index b2b1b4cd..d3041fa1 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart @@ -42,8 +42,6 @@ class _ScheduleProvisionalVisitPageWidgetState @override Widget build(BuildContext context) { - context.watch(); - return GestureDetector( onTap: () => FocusScope.of(context).unfocus(), child: SingleChildScrollView( diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart index 9328aa5b..cd667c8e 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart @@ -12,7 +12,6 @@ import 'regisiter_vistor_template_component_widget.dart'; class RegisiterVistorTemplateComponentModel extends FlutterFlowModel { Timer? _debounceTimer; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -135,9 +134,9 @@ class RegisiterVistorTemplateComponentModel } Future initializeDatabase() async { - devUUID = await db.get(key: 'devUUID', field: 'value'); - userUUID = await db.get(key: 'userUUID', field: 'value'); - cliUUID = await db.get(key: 'cliUUID', field: 'value'); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart index eeb79823..3bd63a0e 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart @@ -121,7 +121,6 @@ class _RegisiterVistorTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); return Align( alignment: const AlignmentDirectional(0.0, 1.0), child: Container( diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart index 1a2eb353..677dac66 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart @@ -3,6 +3,7 @@ import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/flutter_flow/random_data_util.dart'; import 'package:hub/pages/home_page/home_page_model.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/device_util.dart'; import 'package:hub/shared/utils/dialog_util.dart'; @@ -86,9 +87,8 @@ class SignInTemplateComponentModel }) async { try { final ApiCallResponse? response; - final SQLiteStorageHelper db = SQLiteStorageHelper(); final LoginCall callback = PhpGroup.loginCall; - AppState().deviceDescription = randomString( + SecureStorageHelper().deviceDescription = randomString( 10, 10, true, @@ -111,8 +111,8 @@ class SignInTemplateComponentModel devUUID = await DeviceUtil.getDevUUID(); if ((email != '') && (passwd != '')) { - AppState().email = email; - AppState().passwd = passwd; + SecureStorageHelper().email = email; + SecureStorageHelper().passwd = passwd; response = await callback.call(); if (response.jsonBody['error'] == false) { @@ -122,17 +122,17 @@ class SignInTemplateComponentModel userDevUUID = response.jsonBody['user']['dev_id']; userName = response.jsonBody['user']['name']; - db.update('devUUID', devUUID, 'user'); - db.update('userUUID', userUUID, 'user'); - db.update('userDevUUID', userDevUUID, 'user'); - db.update('status', status, 'user'); - db.update('userName', userName, 'user'); + SQLiteStorageHelper().devUUID = devUUID!; + SQLiteStorageHelper().userUUID = userUUID; + SQLiteStorageHelper().userDevUUID = userDevUUID; + SQLiteStorageHelper().status = status; + SQLiteStorageHelper().userName = userName; isLogged = true; await checkLocals(context: context, model: model).then((value) { - AppState().haveLocal = value; - AppState().isLogged = isLogged; - AppState().update(() {}); + SecureStorageHelper().haveLocal = value; + SecureStorageHelper().isLogged = isLogged; + SecureStorageHelper().update(() {}); toggleApp(context); }); } else { @@ -154,7 +154,7 @@ class SignInTemplateComponentModel } Future toggleApp(BuildContext context) async { - final haveLocal = AppState().haveLocal; + final haveLocal = SecureStorageHelper().haveLocal; if (haveLocal == true) { context.go('/homePage'); } else if (haveLocal == false) { diff --git a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart index fe35911d..59fc1cc5 100644 --- a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart +++ b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter_animate/flutter_animate.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/atom_image_svg_theme.dart'; import 'package:hub/shared/components/atoms/atom_terms_of_use.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import 'package:provider/provider.dart'; @@ -124,8 +125,6 @@ class _SignUpTemplateComponentWidgetState return false; } - context.watch(); - return Row( mainAxisSize: MainAxisSize.max, children: [ @@ -702,7 +701,8 @@ class _SignUpTemplateComponentWidgetState .emailRegisterFormTextController .text, device: - AppState().deviceType, + SecureStorageHelper() + .deviceType, ); shouldSetState = true; if (_model.signUp == true) { diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart index 046448b1..8bb70b0d 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart @@ -6,7 +6,6 @@ import 'view_visit_detail_widget.dart' show ViewVisitDetailWidget; import 'package:flutter/material.dart'; class ViewVisitDetailModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -37,15 +36,9 @@ class ViewVisitDetailModel extends FlutterFlowModel { } Future initializeDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart index 65c992c0..d58b7043 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart @@ -121,8 +121,6 @@ class _ViewVisitDetailWidgetState extends State { var filteredVisitorJsonList = findVisitorById(widget.visitorJsonList, widget.visitIdStr) ?? 'null'; - context.watch(); - return Padding( padding: const EdgeInsetsDirectional.fromSTEB(0.0, 200.0, 0.0, 0.0), child: Container( diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart index f1efb91a..7c06018b 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart @@ -7,7 +7,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -40,15 +39,9 @@ class VisitorSearchModalTemplateComponentModel } Future initDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart index e1982ac3..713cc6f8 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart @@ -59,8 +59,6 @@ class _VisitorSearchModalTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Padding( padding: const EdgeInsetsDirectional.fromSTEB(0.0, 10.0, 0.0, 0.0), child: Container( diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 3947cd2b..013fcb8f 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -10,6 +10,7 @@ import 'package:hub/pages/pets_page/pets_page_widget.dart'; import 'package:hub/pages/provisional_schedule_page/provisional_schedule_widget.dart'; import 'package:hub/pages/reception_page/reception_page_widget.dart'; import 'package:hub/pages/reservation_page/reservation_page_widget.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:provider/provider.dart'; import '/backend/schema/structs/index.dart'; @@ -72,8 +73,8 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter( FFRoute( name: '_initialize', path: '/', - builder: (context, _) => AppState().isLogged - ? AppState().haveLocal == true + builder: (context, _) => SecureStorageHelper().isLogged + ? SecureStorageHelper().haveLocal == true ? const HomePageWidget() : const ReceptionPageWidget() : const WelcomePageWidget(), diff --git a/lib/main.dart b/lib/main.dart index b75c9dda..bb8f1ff7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -26,18 +26,20 @@ final GlobalKey navigatorKey = GlobalKey(); Future initializeApp() async { WidgetsFlutterBinding.ensureInitialized(); await SQLiteStorageHelper().database; - final sharedPreferencesHelper = SharedPreferencesStorageHelper(); + SQLiteStorageHelper().deleteDatabaseDB(); + final SharedPreferencesStorageHelper sharedPreferencesHelper = + SharedPreferencesStorageHelper(); final SecureStorageHelper secureStorageHelper = SecureStorageHelper(); - await sharedPreferencesHelper.initialize(); + await sharedPreferencesHelper.ensureInitialization(); + await secureStorageHelper.ensureInitilization(); if (sharedPreferencesHelper.isFirstRun) { - // Execute actions for the first run sharedPreferencesHelper.isFirstRun = false; - secureStorageHelper.deleteAll(); + secureStorageHelper.purge(); } - final status = await AppTrackingTransparency.requestTrackingAuthorization(); + await AppTrackingTransparency.requestTrackingAuthorization(); await Firebase.initializeApp(); await NotificationService.initialize(); @@ -61,7 +63,7 @@ Future initializeApp() async { Future foregroundHandleMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - SecureStorageHelper().set('haveLocal', 'true'); + SecureStorageHelper().haveLocal = true; SecureStorageHelper().context?.go('/homePage'); } if (!Platform.isIOS) { @@ -123,6 +125,8 @@ class _AppState extends State { _backgroundHandleMessage(message); } }); + + // SecureStorageHelper().isLogged = false; } void setLocale(String language) { @@ -139,67 +143,62 @@ class _AppState extends State { @override Widget build(BuildContext context) { - return MultiProvider( - providers: const [], - // ChangeNotifierProvider(create: (_) => {AppState()}), - - child: MaterialApp.router( - title: 'FRE ACCESS HUB', - builder: (context, widget) => ResponsiveBreakpoints.builder( - child: BouncingScrollWrapper.builder(context, widget!), - breakpoints: [ - const Breakpoint(start: 0, end: 450, name: MOBILE), - const Breakpoint(start: 451, end: 800, name: TABLET), - const Breakpoint(start: 801, end: 1920, name: DESKTOP), - const Breakpoint(start: 1921, end: double.infinity, name: '4K'), - ], - ), - localizationsDelegates: const [ - FFLocalizationsDelegate(), - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, + return MaterialApp.router( + title: 'FRE ACCESS HUB', + builder: (context, widget) => ResponsiveBreakpoints.builder( + child: BouncingScrollWrapper.builder(context, widget!), + breakpoints: [ + const Breakpoint(start: 0, end: 450, name: MOBILE), + const Breakpoint(start: 451, end: 800, name: TABLET), + const Breakpoint(start: 801, end: 1920, name: DESKTOP), + const Breakpoint(start: 1921, end: double.infinity, name: '4K'), ], - locale: _locale, - supportedLocales: const [ - Locale('pt'), - Locale('en'), - ], - theme: ThemeData( - brightness: Brightness.light, - scrollbarTheme: ScrollbarThemeData( - thumbVisibility: WidgetStateProperty.all(false), - interactive: false, - thumbColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.dragged)) { - return const Color(0xff1aab5f); - } - if (states.contains(WidgetState.hovered)) { - return const Color(0xff1aab5f); - } - return const Color(0xff1aab5f); - }), - ), - ), - darkTheme: ThemeData( - brightness: Brightness.dark, - scrollbarTheme: ScrollbarThemeData( - thumbVisibility: WidgetStateProperty.all(false), - interactive: false, - thumbColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.dragged)) { - return const Color(0xff1aab5f); - } - if (states.contains(WidgetState.hovered)) { - return const Color(0xff1aab5f); - } - return const Color(0xff1aab5f); - }), - ), - ), - themeMode: _themeMode, - routerConfig: _router, ), + localizationsDelegates: const [ + FFLocalizationsDelegate(), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + locale: _locale, + supportedLocales: const [ + Locale('pt'), + Locale('en'), + ], + theme: ThemeData( + brightness: Brightness.light, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: WidgetStateProperty.all(false), + interactive: false, + thumbColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.dragged)) { + return const Color(0xff1aab5f); + } + if (states.contains(WidgetState.hovered)) { + return const Color(0xff1aab5f); + } + return const Color(0xff1aab5f); + }), + ), + ), + darkTheme: ThemeData( + brightness: Brightness.dark, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: WidgetStateProperty.all(false), + interactive: false, + thumbColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.dragged)) { + return const Color(0xff1aab5f); + } + if (states.contains(WidgetState.hovered)) { + return const Color(0xff1aab5f); + } + return const Color(0xff1aab5f); + }), + ), + ), + themeMode: _themeMode, + routerConfig: _router, ); } } diff --git a/lib/pages/acess_history_page/acess_history_page_model.dart b/lib/pages/acess_history_page/acess_history_page_model.dart index db3be583..93e9de78 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -7,7 +7,6 @@ import 'package:hub/pages/acess_history_page/acess_history_page_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class AcessHistoryPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -34,15 +33,9 @@ class AcessHistoryPageModel extends FlutterFlowModel { } Future initDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart b/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart index cfe5ef5e..357b751f 100644 --- a/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart +++ b/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart @@ -31,7 +31,6 @@ class _DeliveryScheduleState extends State { @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/fast_pass_page/fast_pass_page_widget.dart b/lib/pages/fast_pass_page/fast_pass_page_widget.dart index 448b7219..1a732254 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -5,6 +5,7 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:url_launcher/url_launcher_string.dart'; @@ -18,30 +19,19 @@ class FastPassPageWidget extends StatefulWidget { class _FastPassPageWidgetState extends State { late InAppWebViewController _controllerIOS; late WebViewController _controllerAll; - final SQLiteStorageHelper db = SQLiteStorageHelper(); Future> initVariables() async { - final email = AppState().email; - final name = await db - .get(key: 'userName', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - final createdAt = await db - .get(key: 'devUUID', field: 'createdAt') - .then((value) => value.toString()); + final email = SecureStorageHelper().email; + final name = SQLiteStorageHelper().userName; + final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = SQLiteStorageHelper().devUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; + final createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; final freUserData = "{\"name\": \"$name\", " + "\"email\": \"$email\"," + "\"dev_id\": \"$devUUID\"," + - "\"created_at\": \"$createdAt\"," + + "\"created_at\":\"$createdAt\"," + "\"updated_at\": \"0000-00-00 00:00:00\"," + "\"status\": \"A\" }"; diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index 242aa1d8..99505b0e 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -5,11 +5,11 @@ import 'package:hub/components/organism_components/menu_component/menu_component import 'package:hub/components/organism_components/message_well_component/message_well_component_model.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/home_page/home_page_widget.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class HomePageModel extends FlutterFlowModel { bool isGrid = false; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String cliUUID; late final String userUUID; @@ -25,19 +25,11 @@ class HomePageModel extends FlutterFlowModel { late MessageWellComponentModel messageWellComponentModel; Future _initVariable() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - userName = await db - .get(key: 'userName', field: 'value') - .then((value) => value.toString()); - userEmail = AppState().email; + devUUID = SQLiteStorageHelper().devUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + userUUID = SQLiteStorageHelper().userUUID; + userName = SQLiteStorageHelper().cliName; + userEmail = SecureStorageHelper().email; } @override diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index dc634217..949e94d0 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -11,6 +11,7 @@ import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/home_page/home_page_model.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart'; @@ -25,7 +26,6 @@ class _HomePageWidgetState extends State { late HomePageModel _model; final scaffoldKey = GlobalKey(); late LocalProfileComponentWidget _localProfileComponentWidget; - final SQLiteStorageHelper db = SQLiteStorageHelper(); _HomePageWidgetState() { _localProfileComponentWidget = LocalProfileComponentWidget(); @@ -52,7 +52,7 @@ class _HomePageWidgetState extends State { @override Widget build(BuildContext context) { - AppState().context = context; + SecureStorageHelper().context = context; return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index 23db4207..e0d075ed 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -8,7 +8,6 @@ import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class LiberationHistoryModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -39,15 +38,9 @@ class LiberationHistoryModel extends FlutterFlowModel { } Future init() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliName; } Future answersRequest( diff --git a/lib/pages/liberation_history/liberation_history_widget.dart b/lib/pages/liberation_history/liberation_history_widget.dart index 42bda80d..65811564 100644 --- a/lib/pages/liberation_history/liberation_history_widget.dart +++ b/lib/pages/liberation_history/liberation_history_widget.dart @@ -90,7 +90,6 @@ class _LiberationHistoryWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/message_history_page/message_history_page_model.dart b/lib/pages/message_history_page/message_history_page_model.dart index 49857b82..f2b8300b 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -9,7 +9,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class MessageHistoryPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -44,15 +43,9 @@ class MessageHistoryPageModel } Future init() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/pages/message_history_page/message_history_page_widget.dart b/lib/pages/message_history_page/message_history_page_widget.dart index 12407eed..625d274c 100644 --- a/lib/pages/message_history_page/message_history_page_widget.dart +++ b/lib/pages/message_history_page/message_history_page_widget.dart @@ -85,7 +85,6 @@ class _MessageHistoryPageWidgetState extends State @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index a4d9898d..fae8194d 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -28,7 +28,6 @@ class _PackageOrderPage extends State { final int _pageSize = 10; bool _hasData = false; bool _loading = false; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String cliUUID; late Future _orderFuture; @@ -64,9 +63,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart b/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart index 04097a0d..f2f8ceac 100644 --- a/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart +++ b/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart @@ -41,8 +41,6 @@ class _PeopleOnThePropertyPageWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index bee6cf74..8bbff0a5 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -243,19 +243,10 @@ class _PetsHistoryScreenState extends State } ], onTapCardItemAction: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - final cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; + final cliName = SQLiteStorageHelper().cliName; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; await showDialog( useSafeArea: true, context: context, diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index 927333aa..c024e854 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -19,7 +19,6 @@ import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; class PetsPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -103,18 +102,10 @@ class PetsPageModel extends FlutterFlowModel { String? Function(BuildContext, String?)? textControllerObservationValidator; Future initAsync() async { - devUUID = await db.get(key: 'devUUID', field: 'value').then((value) { - return value.toString(); - }); - userUUID = await db.get(key: 'userUUID', field: 'value').then((value) { - return value.toString(); - }); - cliUUID = await db.get(key: 'cliUUID', field: 'value').then((value) { - return value.toString(); - }); - petAmountRegister = await db - .get(key: 'petAmountRegister', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + petAmountRegister = SQLiteStorageHelper().petAmountRegister.toString(); safeSetState?.call(); } diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 7fa32d78..443c28b0 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -6,13 +6,14 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:share_plus/share_plus.dart'; import 'package:sqflite/sqflite.dart'; class PreferencesPageModel with ChangeNotifier { final unfocusNode = FocusNode(); - final SQLiteStorageHelper db = SQLiteStorageHelper(); bool fingerprint = false; bool person = false; bool notify = false; @@ -24,7 +25,7 @@ class PreferencesPageModel with ChangeNotifier { } Future enablePerson(BuildContext context) async { - final String userDevUUID = await db.get(key: 'userDevUUID', field: 'value'); + final String userDevUUID = SQLiteStorageHelper().userDevUUID; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( @@ -69,7 +70,7 @@ class PreferencesPageModel with ChangeNotifier { Future toggleAccess(BuildContext context) async { onChange(String key) async { - AppState().accessPass = key; + SecureStorageHelper().accessPass = key; await PhpGroup.changePass .call( newSenha: key, @@ -105,10 +106,10 @@ class PreferencesPageModel with ChangeNotifier { Future togglePanic(BuildContext context) async { onChange(String key) async { - AppState().panicPass = key; + SecureStorageHelper().panicPass = key; await PhpGroup.changePanic .call( - newSenhaPanico: AppState().panicPass, + newSenhaPanico: SecureStorageHelper().panicPass, ) .then((value) async { final String content; @@ -146,8 +147,8 @@ class PreferencesPageModel with ChangeNotifier { ); onChange(String? key) async { - if (!fingerprint) AppState().fingerprintPass = key ?? ''; - if (fingerprint) AppState().deleteFingerprintPass(); + if (!fingerprint) SecureStorageHelper().fingerprintPass = key ?? ''; + if (fingerprint) SecureStorageHelper().delete('fingerprintPass'); fingerprint = await _toggleBoolInDb('fingerprint'); notifyListeners(); @@ -177,7 +178,7 @@ class PreferencesPageModel with ChangeNotifier { ptText: 'Conta deletada com sucesso', ); - AppState().deleteAll(); + StorageManager.purge(); context.pop(); context.go( @@ -223,7 +224,7 @@ class PreferencesPageModel with ChangeNotifier { ptText: 'Tem certeza que deseja sair?', ); onConfirm() async { - AppState().deleteAll(); + StorageManager.purge(); context.go( '/welcomePage', @@ -259,9 +260,9 @@ class PreferencesPageModel with ChangeNotifier { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) { if (value.jsonBody['error'] == false) { - db.clear('cliName'); - db.clear('cliUUID'); - db.clear('ownerUUID'); + SQLiteStorageHelper().cliName = ''; + SQLiteStorageHelper().cliUUID = ''; + SQLiteStorageHelper().ownerUUID = ''; context.pop(); @@ -310,14 +311,15 @@ class PreferencesPageModel with ChangeNotifier { } Future _getBoolFromDb(String key) async { - final value = await db.get(key: key, field: 'value'); + final value = SQLiteStorageHelper().get(key); return value.toString() == 'true'; } Future _toggleBoolInDb(String key) async { final currentValue = await _getBoolFromDb(key); final newValue = !currentValue; - await db.update(key, newValue.toString(), 'util'); + await SQLiteStorageHelper().set(key, newValue.toString()); + return newValue; } diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index 12a3fedb..e58d1dd8 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -7,6 +7,7 @@ import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/preferences_settings_page/preferences_settings_model.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; class PreferencesPageWidget extends StatefulWidget { @@ -17,8 +18,6 @@ class PreferencesPageWidget extends StatefulWidget { } class _PreferencesPageWidgetState extends State { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - @override void initState() { super.initState(); @@ -240,7 +239,7 @@ class _PreferencesPageWidgetState extends State { enText: 'Are you sure you want to logout?', ptText: 'Tem certeza', ), () async { - AppState().deleteAll(); + StorageManager.purge(); // setState(() {}); context.go( diff --git a/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart b/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart index 42afd259..d7a11ba3 100644 --- a/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart +++ b/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart @@ -31,7 +31,6 @@ class _ProvisionalScheduleState extends State { @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/qr_code_page/qr_code_page_model.dart b/lib/pages/qr_code_page/qr_code_page_model.dart index af6298d5..eca74dac 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -14,7 +14,6 @@ class QrCodePageModel extends FlutterFlowModel { String? key = null; DateTime? time; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final bool isFingerprint; late final String userDevUUID; @@ -28,9 +27,8 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = - await db.get('fingerprint').then((value) => value.toString() == 'true'); - userDevUUID = await db.get('userDevUUID').then((value) => value.toString()); + isFingerprint = SQLiteStorageHelper().fingerprint; + userDevUUID = SQLiteStorageHelper().userDevUUID; } @override diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index 89343a1c..a1c9f048 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -6,9 +6,7 @@ import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final String userDevUUID = - await db.get('userDevUUID').then((value) => value.toString()); + final String userDevUUID = SQLiteStorageHelper().userDevUUID; notifyListeners(); Share.share( diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index e9e87ed6..6d47a096 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -6,6 +6,7 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:sqflite/sqflite.dart'; @@ -18,26 +19,23 @@ class ReservationPageWidget extends StatefulWidget { } class _ReservationPageWidgetState extends State { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late InAppWebViewController _controllerIOS; late WebViewController _controllerAll; Future> initVariables() async { - final email = await db.get('email').then((value) => value.toString()); - final name = await db.get('userName').then((value) => value.toString()); - final userUUID = await db.get('userUUID').then((value) => value.toString()); - final devUUID = await db.get('devUUID').then((value) => value.toString()); - final createdAt = await db - .getByField(key: 'devUUID', field: 'createdAt') - .then((value) => value.toString()); - final clientId = await db.get('cliUUID').then((value) => value.toString()); + final email = SecureStorageHelper().email; + final name = SQLiteStorageHelper().cliName; + final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = SQLiteStorageHelper().devUUID; + final createdAt = SQLiteStorageHelper().createdAt; + final clientId = SQLiteStorageHelper().cliUUID; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; final freUserData = "{\"name\": \"$name\", " + "\"email\": \"$email\"," + "\"dev_id\": \"$devUUID\"," + - "\"created_at\": \"$createdAt\"," + + "\"created_at\": \"0000-00-00 00:00:00\"," + "\"updated_at\": \"0000-00-00 00:00:00\"," + "\"status\": \"A\" }"; 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 50ed979b..3c0aafd5 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,5 +1,3 @@ -import 'dart:ffi'; - 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'; @@ -26,7 +24,6 @@ class ScheduleCompleteVisitPageModel late VoidCallback safeSetState; late Function(Function) updateState; final _visitHistoryManager = FutureRequestManager(); - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String cliUUID; late final String userUUID; @@ -184,9 +181,9 @@ class ScheduleCompleteVisitPageModel } Future _initVariables() async { - devUUID = await db.get('devUUID').then((value) => value.toString()); - cliUUID = await db.get('cliUUID').then((value) => value.toString()); - userUUID = await db.get('userUUID').then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + userUUID = SQLiteStorageHelper().userUUID; } @override diff --git a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart index 292f212b..d07f5759 100644 --- a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart @@ -20,7 +20,6 @@ class VisitHistoryWidget extends ScheduleComplete { class _VisitHistoryWidgetState extends State with TickerProviderStateMixin, Status { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -35,9 +34,9 @@ class _VisitHistoryWidgetState extends State List _visitWrap = []; Future _initVariables() async { - devUUID = await db.get('devUUID').then((value) => value.toString()); - userUUID = await db.get('userUUID').then((value) => value.toString()); - cliUUID = await db.get('cliUUID').then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override @@ -246,15 +245,11 @@ class _VisitHistoryWidgetState extends State }, ], onTapCardItemAction: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = - await db.get('cliUUID').then((value) => value.toString()); - final cliName = - await db.get('cliName').then((value) => value.toString()); - final devUUID = - await db.get('devUUID').then((value) => value.toString()); - final userUUID = - await db.get('userUUID').then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; + final cliName = SQLiteStorageHelper().cliName; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + await showDialog( useSafeArea: true, context: context, diff --git a/lib/shared/helpers/secure_storage_helper.dart b/lib/shared/helpers/secure_storage_helper.dart index c46ce274..d01ece8e 100644 --- a/lib/shared/helpers/secure_storage_helper.dart +++ b/lib/shared/helpers/secure_storage_helper.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/utils/storage_util.dart'; import 'package:synchronized/synchronized.dart'; @@ -12,7 +13,91 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { SecureStorageHelper._internal(); - Future initializePersistedState() async { + String _deviceDescription = ''; + String get deviceDescription => _deviceDescription; + set deviceDescription(String value) { + _setString('deviceDescription', value); + _deviceDescription = value; + } + + BuildContext? _context; + BuildContext? get context => _context; + set context(BuildContext? value) { + _setString('ff_context', value.toString()); + _context = value; + } + + bool? _haveLocal; + bool? get haveLocal => _haveLocal; + set haveLocal(bool? value) { + _setBool('ff_have_local', value); + _haveLocal = value; + } + + String _fingerprintPass = ''; + String get fingerprintPass => _fingerprintPass; + set fingerprintPass(String value) { + _setString('fingerprintPass', value); + _fingerprintPass = value; + } + + String _accessPass = ''; + String get accessPass => _accessPass; + set accessPass(String value) { + _setString('accessPass', value); + _accessPass = value; + } + + String _panicPass = ''; + String get panicPass => _panicPass; + set panicPass(String value) { + _setString('panicPass', value); + _panicPass = value; + } + + String? _tokenAPNS = ''; + String? get tokenAPNS => _tokenAPNS; + set tokenAPNS(String? value) { + _setString('ff_tokenAPNS', value ?? ''); + _tokenAPNS = value; + } + + String _email = ''; + String get email => _email; + set email(String value) { + _setString('ff_email', value); + _email = value; + } + + String _passwd = ''; + String get passwd => _passwd; + set passwd(String value) { + _setString('ff_passwd', value); + _passwd = value; + } + + String _deviceType = ''; + String get deviceType => _deviceType; + set deviceType(String value) { + _setString('ff_deviceType', value); + _deviceType = value; + } + + bool _isLogged = false; + bool get isLogged => _isLogged; + set isLogged(bool value) { + _setBool('ff_isLogged', value); + _isLogged = value; + } + + String _token = ''; + String get token => _token; + set token(String value) { + _setString('ff_token', value); + _token = value; + } + + Future ensureInitilization() async { await _safeInitAsync(() async { _email = await _getString('ff_email'); _passwd = await _getString('ff_passwd'); @@ -56,55 +141,6 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { notifyListeners(); } - String _deviceDescription = ''; - String get deviceDescription => _deviceDescription; - set deviceDescription(String value) => _setString('deviceDescription', value); - - BuildContext? _context; - BuildContext? get context => _context; - set context(BuildContext? value) => - _setString('ff_context', value.toString()); - - bool? _haveLocal; - bool? get haveLocal => _haveLocal; - set haveLocal(bool? value) => _setBool('ff_have_local', value); - - String _fingerprintPass = ''; - String get fingerprintPass => _fingerprintPass; - set fingerprintPass(String value) => _setString('fingerprintPass', value); - - String _accessPass = ''; - String get accessPass => _accessPass; - set accessPass(String value) => _setString('accessPass', value); - - String _panicPass = ''; - String get panicPass => _panicPass; - set panicPass(String value) => _setString('panicPass', value); - - String? _tokenAPNS = ''; - String? get tokenAPNS => _tokenAPNS; - set tokenAPNS(String? value) => _setString('ff_tokenAPNS', value ?? ''); - - String _email = ''; - String get email => _email; - set email(String value) => _setString('ff_email', value); - - String _passwd = ''; - String get passwd => _passwd; - set passwd(String value) => _setString('ff_passwd', value); - - String _deviceType = ''; - String get deviceType => _deviceType; - set deviceType(String value) => _setString('ff_deviceType', value); - - bool _isLogged = false; - bool get isLogged => _isLogged; - set isLogged(bool value) => _setBool('ff_isLogged', value); - - String _token = ''; - String get token => _token; - set token(String value) => _setString('ff_token', value); - Future _setString(String key, String value) async { await _secureStorage.write(key: key, value: value); } @@ -115,6 +151,7 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { Future purge() async { _secureStorage.deleteAll(); + await ensureInitilization(); } @override diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart index 99cacead..3fa85748 100644 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -13,7 +13,7 @@ class SharedPreferencesStorageHelper implements Storage { SharedPreferencesStorageHelper._internal(); - Future initialize() async { + Future ensureInitialization() async { _prefs = await SharedPreferences.getInstance(); _isFirstRun = _prefs.getBool('first_run') ?? true; } @@ -61,5 +61,6 @@ class SharedPreferencesStorageHelper implements Storage { Future purge() async { await _prefs.clear(); + await ensureInitialization(); } } diff --git a/lib/shared/helpers/sqlite_storage_helper.dart b/lib/shared/helpers/sqlite_storage_helper.dart index d32e745c..57847414 100644 --- a/lib/shared/helpers/sqlite_storage_helper.dart +++ b/lib/shared/helpers/sqlite_storage_helper.dart @@ -1,3 +1,9 @@ +import 'package:hub/shared/utils/cache_util.dart'; +import 'package:sqflite/sqflite.dart'; +import 'dart:developer'; +import 'package:flutter/foundation.dart'; +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:path/path.dart'; @@ -14,11 +20,34 @@ class DatabaseConfig { static const String columnUpdateAt = 'updateAt'; static const String columnResolvedAt = 'resolvedAt'; static const String columnCreatedAt = 'createdAt'; + + static const List> initialData = [ + {'key': 'devUUID', 'value': '', 'type': 'user'}, + {'key': 'userUUID', 'value': '', 'type': 'user'}, + {'key': 'userDevUUID', 'value': '', 'type': 'user'}, + {'key': 'status', 'value': '', 'type': 'user'}, + {'key': 'userName', 'value': '', 'type': 'user'}, + {'key': 'cliUUID', 'value': '', 'type': 'local'}, + {'key': 'ownerUUID', 'value': '', 'type': 'local'}, + {'key': 'cliName', 'value': '', 'type': 'local'}, + {'key': 'whatsapp', 'value': 'false', 'type': 'util'}, + {'key': 'provisional', 'value': 'false', 'type': 'util'}, + {'key': 'pets', 'value': 'false', 'type': 'util'}, + {'key': 'local', 'value': 'false', 'type': 'util'}, + {'key': 'notify', 'value': 'false', 'type': 'util'}, + {'key': 'fingerprint', 'value': 'false', 'type': 'util'}, + {'key': 'access', 'value': 'false', 'type': 'util'}, + {'key': 'panic', 'value': 'false', 'type': 'util'}, + {'key': 'person', 'value': 'false', 'type': 'util'}, + {'key': 'requestOSnotification', 'value': 'false', 'type': 'util'}, + {'key': 'petAmountRegister', 'value': '', 'type': 'local'}, + ]; } class SQLiteStorageHelper { static final SQLiteStorageHelper _instance = SQLiteStorageHelper._internal(); static Database? _database; + static String? _databasePath; factory SQLiteStorageHelper() => _instance; @@ -30,9 +59,16 @@ class SQLiteStorageHelper { return _database!; } + Future _getDatabasePath() async { + if (_databasePath != null) return _databasePath!; + final databasesPath = await getDatabasesPath(); + _databasePath = join(databasesPath, DatabaseConfig.dbName); + log('Database path: $_databasePath'); + return _databasePath!; + } + Future _initDatabase() async { final path = await _getDatabasePath(); - log('Database path: $path'); return await openDatabase( path, version: DatabaseConfig.dbVersion, @@ -42,15 +78,9 @@ class SQLiteStorageHelper { onDowngrade: _onDowngrade, onConfigure: _onConfigure, ).catchError((error) { + log('Error initializing database: $error'); throw error; - }).whenComplete(() => log('Database initialized')); - } - - Future _getDatabasePath() async { - final databasesPath = await getDatabasesPath(); - final path = join(databasesPath, DatabaseConfig.dbName); - log('Database path: $path'); - return path; + }).whenComplete(() async => await setupLocalVariables()); } Future _onCreate(Database db, int version) async { @@ -70,31 +100,11 @@ class SQLiteStorageHelper { } Future _insertInitialData(Database db) async { - final initialData = [ - {'key': 'devUUID', 'value': '', 'type': 'user'}, - {'key': 'userUUID', 'value': '', 'type': 'user'}, - {'key': 'userDevUUID', 'value': '', 'type': 'user'}, - {'key': 'status', 'value': '', 'type': 'user'}, - {'key': 'userName', 'value': '', 'type': 'user'}, - {'key': 'cliUUID', 'value': '', 'type': 'local'}, - {'key': 'ownerUUID', 'value': '', 'type': 'local'}, - {'key': 'cliName', 'value': '', 'type': 'local'}, - {'key': 'whatsapp', 'value': 'false', 'type': 'util'}, - {'key': 'provisional', 'value': 'false', 'type': 'util'}, - {'key': 'pets', 'value': 'false', 'type': 'util'}, - {'key': 'local', 'value': 'false', 'type': 'util'}, - {'key': 'notify', 'value': 'false', 'type': 'util'}, - {'key': 'fingerprint', 'value': 'false', 'type': 'util'}, - {'key': 'access', 'value': 'false', 'type': 'util'}, - {'key': 'panic', 'value': 'false', 'type': 'util'}, - {'key': 'person', 'value': 'false', 'type': 'util'}, - {'key': 'requestOSnotification', 'value': 'false', 'type': 'util'}, - {'key': 'petAmountRegister', 'value': '', 'type': 'local'}, - ]; - - for (var data in initialData) { - await db.insert(DatabaseConfig.tableKeychain, data); + final batch = db.batch(); + for (var data in DatabaseConfig.initialData) { + batch.insert(DatabaseConfig.tableKeychain, data); } + await batch.commit(noResult: true); } Future _onOpen(Database db) async { @@ -123,151 +133,184 @@ class SQLiteStorageHelper { } } + String _devUUID = ''; + String _userUUID = ''; + String _userDevUUID = ''; + String _status = ''; + String _userName = ''; + String _cliUUID = ''; + String _ownerUUID = ''; + String _cliName = ''; + String _petAmountRegister = ''; + bool _whatsapp = false; + bool _provisional = false; + bool _pets = false; + bool _local = false; + bool _notify = false; + bool _fingerprint = false; + bool _access = false; + bool _panic = false; + bool _person = false; + bool _requestOSnotification = false; + + String get createdAt => '0000-00-00 00:00:00'; + String get devUUID => _devUUID; + String get userUUID => _userUUID; + String get userDevUUID => _userDevUUID; + String get status => _status; + String get userName => _userName; + String get cliUUID => _cliUUID; + String get ownerUUID => _ownerUUID; + String get cliName => _cliName; + String get petAmountRegister => _petAmountRegister; + bool get whatsapp => _whatsapp; + bool get provisional => _provisional; + bool get pets => _pets; + bool get local => _local; + bool get notify => _notify; + bool get fingerprint => _fingerprint; + bool get access => _access; + bool get panic => _panic; + bool get person => _person; + bool get requestOSnotification => _requestOSnotification; + + set devUUID(String value) => set('devUUID', value); + set userUUID(String value) => set('userUUID', value); + set userDevUUID(String value) => set('userDevUUID', value); + set status(String value) => set('status', value); + set userName(String value) => set('userName', value); + set cliUUID(String value) => set('cliUUID', value); + set ownerUUID(String value) => set('ownerUUID', value); + set cliName(String value) => set('cliName', value); + set petAmountRegister(String value) => set('petAmountRegister', value); + set whatsapp(bool value) => set('whatsapp', value); + set provisional(bool value) => set('provisional', value); + set pets(bool value) => set('pets', value); + set local(bool value) => set('local', value); + set notify(bool value) => set('notify', value); + set fingerprint(bool value) => set('fingerprint', value); + set access(bool value) => set('access', value); + set panic(bool value) => set('panic', value); + set person(bool value) => set('person', value); + set requestOSnotification(bool value) => set('requestOSnotification', value); + + Future setupLocalVariables() async { + log('Setting up local variables...'); + await _database?.transaction((txn) async { + final keys = [ + 'devUUID', + 'userUUID', + 'userDevUUID', + 'status', + 'userName', + 'cliUUID', + 'ownerUUID', + 'cliName', + 'whatsapp', + 'provisional', + 'pets', + 'local', + 'notify', + 'fingerprint', + 'access', + 'panic', + 'person', + 'requestOSnotification' + ]; + + final results = await Future.wait(keys.map((key) => get(key))); + + _devUUID = results[0]?.toString() ?? ''; + _userUUID = results[1]?.toString() ?? ''; + _userDevUUID = results[2]?.toString() ?? ''; + _status = results[3]?.toString() ?? ''; + _userName = results[4]?.toString() ?? ''; + _cliUUID = results[5]?.toString() ?? ''; + _ownerUUID = results[6]?.toString() ?? ''; + _cliName = results[7]?.toString() ?? ''; + _whatsapp = results[8] == 'true'; + _provisional = results[9] == 'true'; + _pets = results[10] == 'true'; + _local = results[11] == 'true'; + _notify = results[12] == 'true'; + _fingerprint = results[13] == 'true'; + _access = results[14] == 'true'; + _panic = results[15] == 'true'; + _person = results[16] == 'true'; + _requestOSnotification = results[17] == 'true'; + }); + } + + Future getBoolean(String key) async { + final value = await get(key); + return value == 'true'; + } + + Future get(String key) async { + final cachedValue = CacheUtil.get(key); + if (cachedValue != null) { + return cachedValue; + } + + try { + final db = await database; + final result = await db.query( + DatabaseConfig.tableKeychain, + columns: [DatabaseConfig.columnValue], + where: '${DatabaseConfig.columnKey} = ?', + whereArgs: [key], + ); + + if (result.isNotEmpty) { + final value = result.first[DatabaseConfig.columnValue]; + CacheUtil.set(key, value); + return value; + } + return null; + } catch (error) { + log('Error getting value for key $key: $error'); + return null; + } + } + + Future set(String key, dynamic value) async { + CacheUtil.set(key, value); + final db = await database; + final data = { + DatabaseConfig.columnKey: key, + DatabaseConfig.columnValue: value.toString(), + DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), + DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), + }; + + return await db.insert( + DatabaseConfig.tableKeychain, + data, + conflictAlgorithm: ConflictAlgorithm.replace, + ); + } + + Future delete(String key) async { + final db = await database; + return await db.transaction((txn) async { + return await txn.delete( + DatabaseConfig.tableKeychain, + where: '${DatabaseConfig.columnKey} = ?', + whereArgs: [key], + ); + }); + } + + Future purge() async { + await deleteDatabaseDB(); + await database; + log('Database purged'); + } + Future deleteDatabaseDB() async { final path = await _getDatabasePath(); await deleteDatabase(path); log('Database deleted'); _database = null; } - - Future getByField({String? key, String? field}) async { - try { - final db = await database; - List> queryResult; - - if (field != null && key != null) { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } else if (field != null) { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - ); - } else if (key != null) { - field = DatabaseConfig.columnValue; - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } else { - queryResult = await db.query(DatabaseConfig.tableKeychain); - } - - log('Query result for key: $key, field: $field -> $queryResult'); - - if (queryResult.isNotEmpty) { - return queryResult.first[field]; - } else { - return null; - } - } catch (error) { - log('Error getting: $error'); - return null; - } - } - - Future get(String? key) async { - try { - final db = await database; - List> queryResult; - const String field = DatabaseConfig.columnValue; - - if (key != null) { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } else { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - ); - } - - log('Query result for key: $key, field: $field -> $queryResult'); - - if (queryResult.isNotEmpty) { - return queryResult.first[field]; - } else { - return null; - } - } catch (error) { - log('Error getting: $error'); - return null; - } - } - - Future insert(String key, dynamic value, String? type) async { - final db = await database; - - final Map data = { - DatabaseConfig.columnKey: key, - DatabaseConfig.columnValue: value.toString(), - DatabaseConfig.columnType: type, - DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), - DatabaseConfig.columnResolvedAt: null, - DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), - }; - - log('Inserting: $data'); - return await db.insert(DatabaseConfig.tableKeychain, data); - } - - Future set(String key, dynamic value) async { - final db = await database; - - final Map data = { - DatabaseConfig.columnKey: key, - if (value != null) DatabaseConfig.columnValue: value.toString(), - // if (type != null) DatabaseConfig.columnType: type, - DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), - DatabaseConfig.columnResolvedAt: null, - DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), - }; - - log('Updating: $data'); - return await db.update( - DatabaseConfig.tableKeychain, - data, - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } - - Future clear(String key) async { - final db = await database; - - log('Setting value of key: $key to empty string'); - return await db.update( - DatabaseConfig.tableKeychain, - {DatabaseConfig.columnValue: ''}, - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } - - Future delete(String key) async { - final db = await database; - - log('Deleting key: $key'); - return await db.delete( - DatabaseConfig.tableKeychain, - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } - - Future purge() async { - await deleteDatabaseDB(); - await database; - log('Purge'); - } } diff --git a/lib/shared/utils/cache_util.dart b/lib/shared/utils/cache_util.dart index 01855fd2..548c56c1 100644 --- a/lib/shared/utils/cache_util.dart +++ b/lib/shared/utils/cache_util.dart @@ -1,5 +1,3 @@ -class CacheManager {} - class CacheUtil { static final Map _cache = {}; diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index 5d095261..61729bfc 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -3,9 +3,8 @@ import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliName = await db.get('cliName').then((value) => value.toString()); - final cliUUID = await db.get('cliUUID').then((value) => value.toString()); + final cliName = SQLiteStorageHelper().cliName; + final cliUUID = SQLiteStorageHelper().cliUUID; for (var i = 0; i < payload['convites'].length; i++) { await Share.share(''' From 12535eb7e8b1dc6925eea8496504e566a4bc4bcd Mon Sep 17 00:00:00 2001 From: jantunesmessias Date: Wed, 25 Sep 2024 15:23:23 -0300 Subject: [PATCH 4/6] WIP --- .../sign_in_template_component_model.dart | 1 - lib/main.dart | 185 +++++---- lib/shared/helpers/secure_storage_helper.dart | 252 ++++++------ .../shared_preferences_storage_helper.dart | 115 ++++-- lib/shared/helpers/sqlite_storage_helper.dart | 383 +++++++++++++----- lib/shared/utils/cache_util.dart | 25 +- lib/shared/utils/storage_util.dart | 103 +++-- 7 files changed, 686 insertions(+), 378 deletions(-) diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart index 677dac66..1415d199 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart @@ -132,7 +132,6 @@ class SignInTemplateComponentModel await checkLocals(context: context, model: model).then((value) { SecureStorageHelper().haveLocal = value; SecureStorageHelper().isLogged = isLogged; - SecureStorageHelper().update(() {}); toggleApp(context); }); } else { diff --git a/lib/main.dart b/lib/main.dart index bb8f1ff7..dee73e96 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,33 +18,63 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; -import 'package:provider/provider.dart'; import 'package:responsive_framework/responsive_framework.dart'; final GlobalKey navigatorKey = GlobalKey(); -Future initializeApp() async { - WidgetsFlutterBinding.ensureInitialized(); - await SQLiteStorageHelper().database; - SQLiteStorageHelper().deleteDatabaseDB(); - final SharedPreferencesStorageHelper sharedPreferencesHelper = - SharedPreferencesStorageHelper(); - final SecureStorageHelper secureStorageHelper = SecureStorageHelper(); + +void main() async { + await _initializeApp(); + runApp(const App()); +} + + +Future _initializeApp() async { + WidgetsFlutterBinding.ensureInitialized(); + await _initializeStorageHelpers(); + await _initializeTracking(); + await _initializeFirebase(); + await _initializeNotificationService(); + _initializeUrlStrategy(); + _initializeSystemSettings(); + await _initializeFlutterFlow(); +} + + + +Future _initializeStorageHelpers() async { + final SharedPreferencesStorageHelper sharedPreferencesHelper = SharedPreferencesStorageHelper(); + final SecureStorageHelper secureStorageHelper = SecureStorageHelper(); + final SQLiteStorageHelper sqLiteStorageHelper = SQLiteStorageHelper(); + + await sqLiteStorageHelper.ensureInitialization(); await sharedPreferencesHelper.ensureInitialization(); - await secureStorageHelper.ensureInitilization(); + await secureStorageHelper.ensureInitialization(); if (sharedPreferencesHelper.isFirstRun) { sharedPreferencesHelper.isFirstRun = false; secureStorageHelper.purge(); } +} +Future _initializeTracking() async { await AppTrackingTransparency.requestTrackingAuthorization(); +} +Future _initializeFirebase() async { await Firebase.initializeApp(); - await NotificationService.initialize(); +} +Future _initializeNotificationService() async { + await NotificationService.initialize(); +} + +void _initializeUrlStrategy() { setUrlStrategy(const PathUrlStrategy()); +} + +void _initializeSystemSettings() { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); if (kDebugMode) { log("Aplicativo em Debug Mode, crashlytics desabilitado!"); @@ -54,14 +84,16 @@ Future initializeApp() async { FlutterError.onError = crashlyticsInstance.recordFlutterError; } } +} +Future _initializeFlutterFlow() async { await FlutterFlowTheme.initialize(); await FFLocalizations.initialize(); GoRouter.optionURLReflectsImperativeAPIs = true; usePathUrlStrategy(); } -Future foregroundHandleMessage(RemoteMessage message) async { +Future _foregroundHandleMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { SecureStorageHelper().haveLocal = true; SecureStorageHelper().context?.go('/homePage'); @@ -81,15 +113,12 @@ Future _backgroundHandleMessage(RemoteMessage message) async { } } -void main() async { - await initializeApp(); - runApp(const App()); -} - class App extends StatefulWidget { const App({super.key}); + @override State createState() => _AppState(); + static _AppState of(BuildContext context) => context.findAncestorStateOfType<_AppState>()!; } @@ -101,32 +130,86 @@ class _AppState extends State { late GoRouter _router; bool displaySplashImage = true; + final ThemeData _darkTheme = ThemeData( + brightness: Brightness.dark, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: WidgetStateProperty.all(false), + interactive: false, + thumbColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.dragged)) { + return const Color(0xff1aab5f); + } + if (states.contains(WidgetState.hovered)) { + return const Color(0xff1aab5f); + } + return const Color(0xff1aab5f); + }), + ), + ); + + final ThemeData _theme = ThemeData( + brightness: Brightness.light, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: WidgetStateProperty.all(false), + interactive: false, + thumbColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.dragged)) { + return const Color(0xff1aab5f); + } + if (states.contains(WidgetState.hovered)) { + return const Color(0xff1aab5f); + } + return const Color(0xff1aab5f); + }), + ), + ); + + final Iterable>? localizationsDelegates = const [ + FFLocalizationsDelegate(), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ]; + + final Iterable supportedLocales = const [ + Locale('pt'), + Locale('en'), + ]; + + Widget Function(BuildContext, Widget?)? builder = (context, widget) { + final breakpoints = [ + const Breakpoint(start: 0, end: 450, name: MOBILE), + const Breakpoint(start: 451, end: 800, name: TABLET), + const Breakpoint(start: 801, end: 1920, name: DESKTOP), + const Breakpoint(start: 1921, end: double.infinity, name: '4K'), + ]; + return ResponsiveBreakpoints.builder( + child: BouncingScrollWrapper.builder(context, widget!), + breakpoints: breakpoints, + ); + }; + + @override void initState() { super.initState(); - FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); - // WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((_) => initializeTracking()); - _appStateNotifier = AppStateNotifier.instance; _router = createRouter(_appStateNotifier); Future.delayed(const Duration(milliseconds: 1000), () => setState(() => _appStateNotifier.stopShowingSplashImage())); - - FirebaseMessaging.onMessage.listen(foregroundHandleMessage); + FirebaseMessaging.onMessage.listen(_foregroundHandleMessage); FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { onMessageReceived(message.data, message.notification!.body, message.data['click_action']); }); FirebaseMessaging.onBackgroundMessage(_backgroundHandleMessage); - FirebaseMessaging.instance.getInitialMessage().then((message) { if (message != null) { _backgroundHandleMessage(message); } }); - // SecureStorageHelper().isLogged = false; } void setLocale(String language) { @@ -145,58 +228,12 @@ class _AppState extends State { Widget build(BuildContext context) { return MaterialApp.router( title: 'FRE ACCESS HUB', - builder: (context, widget) => ResponsiveBreakpoints.builder( - child: BouncingScrollWrapper.builder(context, widget!), - breakpoints: [ - const Breakpoint(start: 0, end: 450, name: MOBILE), - const Breakpoint(start: 451, end: 800, name: TABLET), - const Breakpoint(start: 801, end: 1920, name: DESKTOP), - const Breakpoint(start: 1921, end: double.infinity, name: '4K'), - ], - ), - localizationsDelegates: const [ - FFLocalizationsDelegate(), - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], + builder: builder, + localizationsDelegates: localizationsDelegates, locale: _locale, - supportedLocales: const [ - Locale('pt'), - Locale('en'), - ], - theme: ThemeData( - brightness: Brightness.light, - scrollbarTheme: ScrollbarThemeData( - thumbVisibility: WidgetStateProperty.all(false), - interactive: false, - thumbColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.dragged)) { - return const Color(0xff1aab5f); - } - if (states.contains(WidgetState.hovered)) { - return const Color(0xff1aab5f); - } - return const Color(0xff1aab5f); - }), - ), - ), - darkTheme: ThemeData( - brightness: Brightness.dark, - scrollbarTheme: ScrollbarThemeData( - thumbVisibility: WidgetStateProperty.all(false), - interactive: false, - thumbColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.dragged)) { - return const Color(0xff1aab5f); - } - if (states.contains(WidgetState.hovered)) { - return const Color(0xff1aab5f); - } - return const Color(0xff1aab5f); - }), - ), - ), + supportedLocales: supportedLocales, + theme: _theme, + darkTheme: _darkTheme, themeMode: _themeMode, routerConfig: _router, ); diff --git a/lib/shared/helpers/secure_storage_helper.dart b/lib/shared/helpers/secure_storage_helper.dart index d01ece8e..106964dc 100644 --- a/lib/shared/helpers/secure_storage_helper.dart +++ b/lib/shared/helpers/secure_storage_helper.dart @@ -1,7 +1,9 @@ +import 'dart:convert'; +import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/utils/cache_util.dart'; import 'package:synchronized/synchronized.dart'; class SecureStorageHelper extends ChangeNotifier implements Storage { @@ -13,165 +15,185 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { SecureStorageHelper._internal(); - String _deviceDescription = ''; - String get deviceDescription => _deviceDescription; - set deviceDescription(String value) { - _setString('deviceDescription', value); - _deviceDescription = value; - } + static SecureStorageHelper get instance => _instance; + + String? _deviceDescription; + String get deviceDescription => _deviceDescription ?? ''; + set deviceDescription(String value) => _setAndCacheString('deviceDescription', value, (v) => _deviceDescription = v); BuildContext? _context; BuildContext? get context => _context; - set context(BuildContext? value) { - _setString('ff_context', value.toString()); - _context = value; - } + set context(BuildContext? value) => _setAndCacheObject('ff_context', value.toString(), (v) => _context = value); bool? _haveLocal; bool? get haveLocal => _haveLocal; - set haveLocal(bool? value) { - _setBool('ff_have_local', value); - _haveLocal = value; - } + set haveLocal(bool? value) => _setAndCacheBool('ff_have_local', value ?? false, (v) => _haveLocal = value); - String _fingerprintPass = ''; - String get fingerprintPass => _fingerprintPass; - set fingerprintPass(String value) { - _setString('fingerprintPass', value); - _fingerprintPass = value; - } + String? _fingerprintPass; + String get fingerprintPass => _fingerprintPass ?? ''; + set fingerprintPass(String value) => _setAndCacheString('fingerprintPass', value, (v) => _fingerprintPass = v); - String _accessPass = ''; - String get accessPass => _accessPass; - set accessPass(String value) { - _setString('accessPass', value); - _accessPass = value; - } + String? _accessPass; + String get accessPass => _accessPass ?? ''; + set accessPass(String value) => _setAndCacheString('accessPass', value, (v) => _accessPass = v); - String _panicPass = ''; - String get panicPass => _panicPass; - set panicPass(String value) { - _setString('panicPass', value); - _panicPass = value; - } + String? _panicPass; + String get panicPass => _panicPass ?? ''; + set panicPass(String value) => _setAndCacheString('panicPass', value, (v) => _panicPass = v); - String? _tokenAPNS = ''; + String? _tokenAPNS; String? get tokenAPNS => _tokenAPNS; - set tokenAPNS(String? value) { - _setString('ff_tokenAPNS', value ?? ''); - _tokenAPNS = value; - } + set tokenAPNS(String? value) => _setAndCacheString('ff_tokenAPNS', value ?? '', (v) => _tokenAPNS = v); - String _email = ''; - String get email => _email; - set email(String value) { - _setString('ff_email', value); - _email = value; - } + String? _email; + String get email => _email ?? ''; + set email(String value) => _setAndCacheString('ff_email', value, (v) => _email = v); - String _passwd = ''; - String get passwd => _passwd; - set passwd(String value) { - _setString('ff_passwd', value); - _passwd = value; - } + String? _passwd; + String get passwd => _passwd ?? ''; + set passwd(String value) => _setAndCacheString('ff_passwd', value, (v) => _passwd = v); - String _deviceType = ''; - String get deviceType => _deviceType; - set deviceType(String value) { - _setString('ff_deviceType', value); - _deviceType = value; - } + String? _deviceType; + String get deviceType => _deviceType ?? ''; + set deviceType(String value) => _setAndCacheString('ff_deviceType', value, (v) => _deviceType = v); - bool _isLogged = false; - bool get isLogged => _isLogged; - set isLogged(bool value) { - _setBool('ff_isLogged', value); - _isLogged = value; - } + bool? _isLogged; + bool get isLogged => _isLogged ?? false; + set isLogged(bool value) => _setAndCacheBool('ff_isLogged', value, (v) => _isLogged = v); - String _token = ''; - String get token => _token; - set token(String value) { - _setString('ff_token', value); - _token = value; - } + String? _token; + String get token => _token ?? ''; + set token(String value) => _setAndCacheString('ff_token', value, (v) => _token = v); - Future ensureInitilization() async { - await _safeInitAsync(() async { - _email = await _getString('ff_email'); - _passwd = await _getString('ff_passwd'); - _deviceType = await _getString('ff_deviceType'); - _isLogged = await _getBool('ff_isLogged'); - _tokenAPNS = await _getString('ff_tokenAPNS'); - _accessPass = await _getString('accessPass'); - _panicPass = await _getString('panicPass'); - _fingerprintPass = await _getString('fingerprintPass'); - _context = await _getObject('ff_context'); - _haveLocal = await _getBool('ff_have_local'); - _deviceDescription = await _getString('deviceDescription'); - }); - } - - Future _safeInitAsync(Future Function() initFunction) async { + Future ensureInitialization() async { + log('SecureStorageHelper: Starting initialization'); await _lock.synchronized(() async { try { - await initFunction(); + log('SecureStorageHelper: Calling initFunction'); + _email = await _getString('ff_email'); + log('SecureStorageHelper: _email = $_email'); + _passwd = await _getString('ff_passwd'); + log('SecureStorageHelper: _passwd = $_passwd'); + _deviceType = await _getString('ff_deviceType'); + log('SecureStorageHelper: _deviceType = $_deviceType'); + _isLogged = await _getBool('ff_isLogged'); + log('SecureStorageHelper: _isLogged = $_isLogged'); + _tokenAPNS = await _getString('ff_tokenAPNS'); + log('SecureStorageHelper: _tokenAPNS = $_tokenAPNS'); + _accessPass = await _getString('accessPass'); + log('SecureStorageHelper: _accessPass = $_accessPass'); + _panicPass = await _getString('panicPass'); + log('SecureStorageHelper: _panicPass = $_panicPass'); + _fingerprintPass = await _getString('fingerprintPass'); + log('SecureStorageHelper: _fingerprintPass = $_fingerprintPass'); + _context = await _getObject('ff_context'); + log('SecureStorageHelper: _context = $_context'); + _haveLocal = await _getBool('ff_have_local'); + log('SecureStorageHelper: _haveLocal = $_haveLocal'); + _deviceDescription = await _getString('deviceDescription'); + log('SecureStorageHelper: _deviceDescription = $_deviceDescription'); + log('SecureStorageHelper: initFunction completed successfully'); } catch (e) { - // Log or handle the error + log('SecureStorageHelper: Error during initialization: $e'); } }); + log('SecureStorageHelper: Initialization complete'); + } + + Future _setAndCacheString(String key, String value, Function(String) cacheSetter) async { + await _lock.synchronized(() async { + await _secureStorage.write(key: key, value: value); + CacheUtil.instance.set(key, value); + cacheSetter(value); + }); } - Future _getString(String key) async { - return await _secureStorage.read(key: key) ?? ''; + Future _setAndCacheBool(String key, bool value, Function(bool) cacheSetter) async { + await _lock.synchronized(() async { + await _secureStorage.write(key: key, value: value.toString()); + CacheUtil.instance.set(key, value); + cacheSetter(value); + }); } - Future _getBool(String key) async { - return (await _secureStorage.read(key: key))?.toLowerCase() == 'true'; + Future _setAndCacheObject(String key, String value, Function(String) cacheSetter) async { + await _lock.synchronized(() async { + await _secureStorage.write(key: key, value: value); + CacheUtil.instance.set(key, value); + cacheSetter(value); + }); } - Future _getObject(String key) async { - // Implement your object retrieval logic here - return null; + Future _getString(String key) async { + return await _lock.synchronized(() async { + var value = CacheUtil.instance.get(key); + if (value == null) { + value = await _secureStorage.read(key: key); + CacheUtil.instance.set(key, value); + } + return value; + }); } - void update(VoidCallback callback) { - callback(); - notifyListeners(); + Future _getBool(String key) async { + return await _lock.synchronized(() async { + var value = CacheUtil.instance.get(key); + if (value == null) { + value = await _secureStorage.read(key: key); + CacheUtil.instance.set(key, value == 'true'); + } + return value == 'true'; + }); } - Future _setString(String key, String value) async { - await _secureStorage.write(key: key, value: value); - } - - Future _setBool(String key, bool? value) async { - await _secureStorage.write(key: key, value: value.toString()); - } - - Future purge() async { - _secureStorage.deleteAll(); - await ensureInitilization(); + Future _getObject(String key) async { + return await _lock.synchronized(() async { + var value = CacheUtil.instance.get(key); + if (value == null) { + value = await _secureStorage.read(key: key); + CacheUtil.instance.set(key, value); + } + return value as BuildContext?; + }); } @override Future set(String key, dynamic value) async { if (value is String) { - await _setString(key, value); + await _setAndCacheString(key, value, (v) {}); } else if (value is bool) { - await _setBool(key, value); - } else if (value is int || value is double) { - await _setString(key, value.toString()); + await _setAndCacheBool(key, value, (v) {}); + } else if (value is BuildContext) { + await _setAndCacheObject(key, value.toString(), (v) {}); } } @override Future get(String key) async { - return await _secureStorage.read(key: key); + var stringValue = await _getString(key); + if (stringValue != null) return stringValue; + + var boolValue = await _getBool(key); + if (boolValue != null) return boolValue; + + var objectValue = await _getObject(key); + if (objectValue != null) return objectValue; + + return null; } @override Future delete(String key) async { - await _secureStorage.delete(key: key); + await _lock.synchronized(() async { + await _secureStorage.delete(key: key); + CacheUtil.instance.delete(key); + }); } -} + + Future purge() async { + await _lock.synchronized(() async { + await _secureStorage.deleteAll(); + CacheUtil.instance.clear(); + }); + } +} \ No newline at end of file diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart index 3fa85748..0fdc632b 100644 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -1,66 +1,103 @@ import 'package:hub/shared/utils/storage_util.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:hub/shared/utils/cache_util.dart'; +import 'package:synchronized/synchronized.dart'; class SharedPreferencesStorageHelper implements Storage { - late SharedPreferences _prefs; + static final SharedPreferencesStorageHelper _instance = SharedPreferencesStorageHelper._internal(); + static final _lock = Lock(); + SharedPreferences? _prefs; - static final SharedPreferencesStorageHelper _instance = - SharedPreferencesStorageHelper._internal(); - - factory SharedPreferencesStorageHelper() { - return _instance; - } + factory SharedPreferencesStorageHelper() => _instance; SharedPreferencesStorageHelper._internal(); - Future ensureInitialization() async { - _prefs = await SharedPreferences.getInstance(); - _isFirstRun = _prefs.getBool('first_run') ?? true; - } + static SharedPreferencesStorageHelper get instance => _instance; bool _isFirstRun = true; bool get isFirstRun => _isFirstRun; - set isFirstRun(bool value) { - _isFirstRun = value; - set('first_run', value); + set isFirstRun(bool value) => _setAndCacheBool('first_run', value, (v) => _isFirstRun = v); + + Future ensureInitialization() async { + await _lock.synchronized(() async { + if (_prefs == null) { + _prefs = await SharedPreferences.getInstance(); + _isFirstRun = _prefs?.getBool('first_run') ?? true; + } + }); + } + + Future _setAndCache(String key, T value, Function(T) cacheSetter, Future Function(String, T) setFunc) async { + await _lock.synchronized(() async { + await setFunc(key, value); + CacheUtil.instance.set(key, value); + cacheSetter(value); + }); + } + + Future _setAndCacheString(String key, String value, Function(String) cacheSetter) async { + await _setAndCache(key, value, cacheSetter, _prefs!.setString); + } + + Future _setAndCacheBool(String key, bool value, Function(bool) cacheSetter) async { + await _setAndCache(key, value, cacheSetter, _prefs!.setBool); + } + + Future _setAndCacheInt(String key, int value, Function(int) cacheSetter) async { + await _setAndCache(key, value, cacheSetter, _prefs!.setInt); + } + + Future _setAndCacheDouble(String key, double value, Function(double) cacheSetter) async { + await _setAndCache(key, value, cacheSetter, _prefs!.setDouble); + } + + Future _setAndCacheStringList(String key, List value, Function(List) cacheSetter) async { + await _setAndCache(key, value, cacheSetter, _prefs!.setStringList); } @override Future set(String key, dynamic value) async { - if (value is bool) { - await _prefs.setBool(key, value); - } else if (value is String) { - await _prefs.setString(key, value); - } else if (value is int) { - await _prefs.setInt(key, value); - } else if (value is double) { - await _prefs.setDouble(key, value); - } else if (value is List) { - await _prefs.setStringList(key, value); - } + await _lock.synchronized(() async { + if (value is bool) { + await _prefs?.setBool(key, value); + } else if (value is String) { + await _prefs?.setString(key, value); + } else if (value is int) { + await _prefs?.setInt(key, value); + } else if (value is double) { + await _prefs?.setDouble(key, value); + } else if (value is List) { + await _prefs?.setStringList(key, value); + } + CacheUtil.instance.set(key, value); + }); } @override Future get(String key) async { - try { - return _prefs.get(key); - } catch (e) { - // Log or handle the error - return null; - } + return await _lock.synchronized(() async { + var value = CacheUtil.instance.get(key); + if (value == null) { + value = _prefs?.get(key); + CacheUtil.instance.set(key, value); + } + return value; + }); } @override Future delete(String key) async { - try { - await _prefs.remove(key); - } catch (e) { - // Log or handle the error - } + await _lock.synchronized(() async { + await _prefs?.remove(key); + CacheUtil.instance.delete(key); + }); } Future purge() async { - await _prefs.clear(); - await ensureInitialization(); + await _lock.synchronized(() async { + await _prefs?.clear(); + CacheUtil.instance.clear(); + await ensureInitialization(); + }); } -} +} \ No newline at end of file diff --git a/lib/shared/helpers/sqlite_storage_helper.dart b/lib/shared/helpers/sqlite_storage_helper.dart index 57847414..7e481f34 100644 --- a/lib/shared/helpers/sqlite_storage_helper.dart +++ b/lib/shared/helpers/sqlite_storage_helper.dart @@ -1,13 +1,7 @@ import 'package:hub/shared/utils/cache_util.dart'; import 'package:sqflite/sqflite.dart'; import 'dart:developer'; -import 'package:flutter/foundation.dart'; import 'package:path/path.dart'; -import 'package:sqflite/sqflite.dart'; -import 'dart:developer'; -import 'package:flutter/foundation.dart'; -import 'package:path/path.dart'; -import 'package:sqflite/sqflite.dart'; class DatabaseConfig { static const String dbName = 'database.db'; @@ -53,13 +47,19 @@ class SQLiteStorageHelper { SQLiteStorageHelper._internal(); - Future get database async { + static SQLiteStorageHelper get instance => _instance; + + + + Future ensureInitialization() async { + log('Getting database instance'); if (_database != null) return _database!; _database = await _initDatabase(); return _database!; } Future _getDatabasePath() async { + log('Getting database path'); if (_databasePath != null) return _databasePath!; final databasesPath = await getDatabasesPath(); _databasePath = join(databasesPath, DatabaseConfig.dbName); @@ -68,6 +68,7 @@ class SQLiteStorageHelper { } Future _initDatabase() async { + log('Initializing database'); final path = await _getDatabasePath(); return await openDatabase( path, @@ -80,7 +81,10 @@ class SQLiteStorageHelper { ).catchError((error) { log('Error initializing database: $error'); throw error; - }).whenComplete(() async => await setupLocalVariables()); + }).whenComplete(() async { + log('Database initialization complete'); + await setupLocalVariables(); + }); } Future _onCreate(Database db, int version) async { @@ -100,15 +104,17 @@ class SQLiteStorageHelper { } Future _insertInitialData(Database db) async { + log('Inserting initial data'); final batch = db.batch(); for (var data in DatabaseConfig.initialData) { batch.insert(DatabaseConfig.tableKeychain, data); } await batch.commit(noResult: true); + log('Initial data inserted'); } Future _onOpen(Database db) async { - log('Checking existing data...'); + log('Opening database'); await _checkExistingData(db); } @@ -121,10 +127,11 @@ class SQLiteStorageHelper { } Future _onConfigure(Database db) async { - log('Configuring database...'); + log('Configuring database'); } Future _checkExistingData(Database db) async { + log('Checking existing data'); try { final maps = await db.query(DatabaseConfig.tableKeychain); log('Existing data: $maps'); @@ -153,107 +160,259 @@ class SQLiteStorageHelper { bool _person = false; bool _requestOSnotification = false; - String get createdAt => '0000-00-00 00:00:00'; - String get devUUID => _devUUID; - String get userUUID => _userUUID; - String get userDevUUID => _userDevUUID; - String get status => _status; - String get userName => _userName; - String get cliUUID => _cliUUID; - String get ownerUUID => _ownerUUID; - String get cliName => _cliName; - String get petAmountRegister => _petAmountRegister; - bool get whatsapp => _whatsapp; - bool get provisional => _provisional; - bool get pets => _pets; - bool get local => _local; - bool get notify => _notify; - bool get fingerprint => _fingerprint; - bool get access => _access; - bool get panic => _panic; - bool get person => _person; - bool get requestOSnotification => _requestOSnotification; + String get createdAt { + log('Getting createdAt'); + return '0000-00-00 00:00:00'; + } - set devUUID(String value) => set('devUUID', value); - set userUUID(String value) => set('userUUID', value); - set userDevUUID(String value) => set('userDevUUID', value); - set status(String value) => set('status', value); - set userName(String value) => set('userName', value); - set cliUUID(String value) => set('cliUUID', value); - set ownerUUID(String value) => set('ownerUUID', value); - set cliName(String value) => set('cliName', value); - set petAmountRegister(String value) => set('petAmountRegister', value); - set whatsapp(bool value) => set('whatsapp', value); - set provisional(bool value) => set('provisional', value); - set pets(bool value) => set('pets', value); - set local(bool value) => set('local', value); - set notify(bool value) => set('notify', value); - set fingerprint(bool value) => set('fingerprint', value); - set access(bool value) => set('access', value); - set panic(bool value) => set('panic', value); - set person(bool value) => set('person', value); - set requestOSnotification(bool value) => set('requestOSnotification', value); + String get devUUID { + log('Getting devUUID'); + return _devUUID; + } + + String get userUUID { + log('Getting userUUID'); + return _userUUID; + } + + String get userDevUUID { + log('Getting userDevUUID'); + return _userDevUUID; + } + + String get status { + log('Getting status'); + return _status; + } + + String get userName { + log('Getting userName'); + return _userName; + } + + String get cliUUID { + log('Getting cliUUID'); + return _cliUUID; + } + + String get ownerUUID { + log('Getting ownerUUID'); + return _ownerUUID; + } + + String get cliName { + log('Getting cliName'); + return _cliName; + } + + String get petAmountRegister { + log('Getting petAmountRegister'); + return _petAmountRegister; + } + + bool get whatsapp { + log('Getting whatsapp'); + return _whatsapp; + } + + bool get provisional { + log('Getting provisional'); + return _provisional; + } + + bool get pets { + log('Getting pets'); + return _pets; + } + + bool get local { + log('Getting local'); + return _local; + } + + bool get notify { + log('Getting notify'); + return _notify; + } + + bool get fingerprint { + log('Getting fingerprint'); + return _fingerprint; + } + + bool get access { + log('Getting access'); + return _access; + } + + bool get panic { + log('Getting panic'); + return _panic; + } + + bool get person { + log('Getting person'); + return _person; + } + + bool get requestOSnotification { + log('Getting requestOSnotification'); + return _requestOSnotification; + } + + set devUUID(String value) { + log('Setting devUUID to $value'); + set('devUUID', value); + } + + set userUUID(String value) { + log('Setting userUUID to $value'); + set('userUUID', value); + } + + set userDevUUID(String value) { + log('Setting userDevUUID to $value'); + set('userDevUUID', value); + } + + set status(String value) { + log('Setting status to $value'); + set('status', value); + } + + set userName(String value) { + log('Setting userName to $value'); + set('userName', value); + } + + set cliUUID(String value) { + log('Setting cliUUID to $value'); + set('cliUUID', value); + } + + set ownerUUID(String value) { + log('Setting ownerUUID to $value'); + set('ownerUUID', value); + } + + set cliName(String value) { + log('Setting cliName to $value'); + set('cliName', value); + } + + set petAmountRegister(String value) { + log('Setting petAmountRegister to $value'); + set('petAmountRegister', value); + } + + set whatsapp(bool value) { + log('Setting whatsapp to $value'); + set('whatsapp', value); + } + + set provisional(bool value) { + log('Setting provisional to $value'); + set('provisional', value); + } + + set pets(bool value) { + log('Setting pets to $value'); + set('pets', value); + } + + set local(bool value) { + log('Setting local to $value'); + set('local', value); + } + + set notify(bool value) { + log('Setting notify to $value'); + set('notify', value); + } + + set fingerprint(bool value) { + log('Setting fingerprint to $value'); + set('fingerprint', value); + } + + set access(bool value) { + log('Setting access to $value'); + set('access', value); + } + + set panic(bool value) { + log('Setting panic to $value'); + set('panic', value); + } + + set person(bool value) { + log('Setting person to $value'); + set('person', value); + } + + set requestOSnotification(bool value) { + log('Setting requestOSnotification to $value'); + set('requestOSnotification', value); + } Future setupLocalVariables() async { - log('Setting up local variables...'); - await _database?.transaction((txn) async { - final keys = [ - 'devUUID', - 'userUUID', - 'userDevUUID', - 'status', - 'userName', - 'cliUUID', - 'ownerUUID', - 'cliName', - 'whatsapp', - 'provisional', - 'pets', - 'local', - 'notify', - 'fingerprint', - 'access', - 'panic', - 'person', - 'requestOSnotification' - ]; + log('Setting up local variables'); + try { + await _database?.transaction((txn) async { + final keys = [ + 'devUUID', + 'userUUID', + 'userDevUUID', + 'status', + 'userName', + 'cliUUID', + 'ownerUUID', + 'cliName', + 'petAmountRegister', + 'whatsapp', + 'provisional', + 'pets', + 'local', + 'notify', + 'fingerprint', + 'access', + 'panic', + 'person', + 'requestOSnotification' + ]; - final results = await Future.wait(keys.map((key) => get(key))); - - _devUUID = results[0]?.toString() ?? ''; - _userUUID = results[1]?.toString() ?? ''; - _userDevUUID = results[2]?.toString() ?? ''; - _status = results[3]?.toString() ?? ''; - _userName = results[4]?.toString() ?? ''; - _cliUUID = results[5]?.toString() ?? ''; - _ownerUUID = results[6]?.toString() ?? ''; - _cliName = results[7]?.toString() ?? ''; - _whatsapp = results[8] == 'true'; - _provisional = results[9] == 'true'; - _pets = results[10] == 'true'; - _local = results[11] == 'true'; - _notify = results[12] == 'true'; - _fingerprint = results[13] == 'true'; - _access = results[14] == 'true'; - _panic = results[15] == 'true'; - _person = results[16] == 'true'; - _requestOSnotification = results[17] == 'true'; - }); + for (var key in keys) { + log('Fetching value for key: $key'); + final result = await txn.query( + DatabaseConfig.tableKeychain, + where: '${DatabaseConfig.columnKey} = ?', + whereArgs: [key], + ); + log('Result for key $key: $result'); + } + }); + log('Local variables setup complete'); + } catch (error) { + log('Error setting up local variables: $error'); + } } Future getBoolean(String key) async { + log('Getting boolean value for key: $key'); final value = await get(key); return value == 'true'; } Future get(String key) async { - final cachedValue = CacheUtil.get(key); + log('Getting value for key: $key'); + final cachedValue = CacheUtil().get(key); if (cachedValue != null) { + log('Found cached value for key: $key'); return cachedValue; } try { - final db = await database; + final db = await ensureInitialization(); final result = await db.query( DatabaseConfig.tableKeychain, columns: [DatabaseConfig.columnValue], @@ -263,9 +422,11 @@ class SQLiteStorageHelper { if (result.isNotEmpty) { final value = result.first[DatabaseConfig.columnValue]; - CacheUtil.set(key, value); + CacheUtil().set(key, value); + log('Value for key $key: $value'); return value; } + log('No value found for key: $key'); return null; } catch (error) { log('Error getting value for key $key: $error'); @@ -274,8 +435,9 @@ class SQLiteStorageHelper { } Future set(String key, dynamic value) async { - CacheUtil.set(key, value); - final db = await database; + log('Setting value for key: $key to $value'); + CacheUtil().set(key, value); + final db = await ensureInitialization(); final data = { DatabaseConfig.columnKey: key, DatabaseConfig.columnValue: value.toString(), @@ -283,34 +445,53 @@ class SQLiteStorageHelper { DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), }; - return await db.insert( + final result = await db.insert( DatabaseConfig.tableKeychain, data, conflictAlgorithm: ConflictAlgorithm.replace, ); + log('Value set for key: $key'); + return result; } Future delete(String key) async { - final db = await database; - return await db.transaction((txn) async { + log('Deleting value for key: $key'); + final db = await ensureInitialization(); + final result = await db.transaction((txn) async { return await txn.delete( DatabaseConfig.tableKeychain, where: '${DatabaseConfig.columnKey} = ?', whereArgs: [key], ); }); + log('Value deleted for key: $key'); + return result; } Future purge() async { + log('Purging database'); await deleteDatabaseDB(); - await database; + await ensureInitialization(); log('Database purged'); } Future deleteDatabaseDB() async { + log('Deleting database'); final path = await _getDatabasePath(); await deleteDatabase(path); log('Database deleted'); _database = null; } } + + + + + + + + + + + + diff --git a/lib/shared/utils/cache_util.dart b/lib/shared/utils/cache_util.dart index 548c56c1..4baf2128 100644 --- a/lib/shared/utils/cache_util.dart +++ b/lib/shared/utils/cache_util.dart @@ -1,19 +1,34 @@ class CacheUtil { + static final CacheUtil _instance = CacheUtil._internal(); static final Map _cache = {}; - static void set(String key, dynamic value) { + CacheUtil._internal(); + + factory CacheUtil() => _instance; + + static CacheUtil get instance => _instance; + + void set(String key, dynamic value) { _cache[key] = value; } - static dynamic get(String key) { + dynamic get(String key) { return _cache[key]; } - static void delete(String key) { + bool containsKey(String key) { + return _cache.containsKey(key); + } + + dynamic getOrElse(String key, dynamic fallback) { + return _cache.containsKey(key) ? _cache[key] : fallback; + } + + void delete(String key) { _cache.remove(key); } - static void clear() { + void clear() { _cache.clear(); } -} +} \ No newline at end of file diff --git a/lib/shared/utils/storage_util.dart b/lib/shared/utils/storage_util.dart index dd08b5fe..a801c513 100644 --- a/lib/shared/utils/storage_util.dart +++ b/lib/shared/utils/storage_util.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; @@ -21,65 +23,80 @@ enum StorageType { SecureStorage, SharedPreferences, SQLite3 } class StorageManager { static final SecureStorageHelper _secureStorage = SecureStorageHelper(); - static final SharedPreferencesStorageHelper _sharedPreferences = - SharedPreferencesStorageHelper(); + static final SharedPreferencesStorageHelper _sharedPreferences = SharedPreferencesStorageHelper(); static final SQLiteStorageHelper _sqliteStorage = SQLiteStorageHelper(); static Future set(StorageData data) async { - switch (data.type) { - case StorageType.SecureStorage: - CacheUtil.set(data.key, data.value); - await _secureStorage.set(data.key, data.value); - break; - case StorageType.SharedPreferences: - await _sharedPreferences.set(data.key, data.value); - break; - case StorageType.SQLite3: - await _sqliteStorage.set(data.key, data.value); - break; + try { + switch (data.type) { + case StorageType.SecureStorage: + await _secureStorage.set(data.key, data.value); + break; + case StorageType.SharedPreferences: + await _sharedPreferences.set(data.key, data.value); + break; + case StorageType.SQLite3: + await _sqliteStorage.set(data.key, data.value); + + break; + } + } catch (e) { + log('Error setting data: $e'); } } static Future get(StorageData data) async { - var value = CacheUtil.get(data.key); - if (value == null) { - switch (data.type) { - case StorageType.SecureStorage: - value = await _secureStorage.get(data.key); - break; - case StorageType.SharedPreferences: - value = await _sharedPreferences.get(data.key); - break; - case StorageType.SQLite3: - value = await _sqliteStorage.get(data.key); - break; + try { + var value = CacheUtil().get(data.key); + if (value == null) { + switch (data.type) { + case StorageType.SecureStorage: + value = await _secureStorage.get(data.key); + break; + case StorageType.SharedPreferences: + value = await _sharedPreferences.get(data.key); + break; + case StorageType.SQLite3: + value = await _sqliteStorage.get(data.key); + break; + } + CacheUtil().set(data.key, value); } - CacheUtil.set(data.key, value); + return value; + } catch (e) { + log('Error getting data: $e'); + return null; } - return value; } static Future delete(StorageData data) async { - switch (data.type) { - case StorageType.SecureStorage: - CacheUtil.delete(data.key); - await _secureStorage.delete(data.key); - break; - case StorageType.SharedPreferences: - await _sharedPreferences.delete(data.key); - break; - case StorageType.SQLite3: - await _sqliteStorage.delete(data.key); - break; + try { + switch (data.type) { + case StorageType.SecureStorage: + CacheUtil().delete(data.key); + await _secureStorage.delete(data.key); + break; + case StorageType.SharedPreferences: + await _sharedPreferences.delete(data.key); + break; + case StorageType.SQLite3: + await _sqliteStorage.delete(data.key); + break; + } + } catch (e) { + log('Error deleting data: $e'); } } static Future purge() async { - // CacheUtil.purge(); - await _secureStorage.purge(); - await _sharedPreferences.purge(); - await _sqliteStorage.purge(); + try { + await _secureStorage.purge(); + await _sharedPreferences.purge(); + await _sqliteStorage.purge(); + } catch (e) { + log('Error purging data: $e'); + } } } -class StorageUtil {} +class StorageUtil {} \ No newline at end of file From e10ff71b1397aa21f84b02918e16fbc32f590953 Mon Sep 17 00:00:00 2001 From: jantunesmessias Date: Thu, 26 Sep 2024 12:45:29 -0300 Subject: [PATCH 5/6] fix --- ios/Runner/AppDelegate.swift | 11 +- lib/backend/api_requests/api_calls.dart | 182 +++++++------ lib/backend/api_requests/api_manager.dart | 2 +- .../firebase_messaging_service.dart | 6 +- .../notifications/notification_service.dart | 19 +- .../menu_button_item_widget.dart | 10 +- .../menu_card_item/menu_card_item.dart | 7 +- .../shared_components_atoms/appbar.dart | 4 +- .../custom_datepicker.dart | 4 +- .../shared_components_atoms/custom_input.dart | 5 +- .../custom_select.dart | 4 +- .../media_upload_button.dart | 4 +- .../submit_button.dart | 2 +- .../shared_components_atoms/tabview.dart | 1 - .../menu_item/menu_item.dart | 4 +- .../message_opt_modal/opt_modal_widget.dart | 4 +- .../opt_modal/opt_modal_widget.dart | 8 +- .../order_filter_modal_widget.dart | 13 +- .../visitor_not_found_component_widget.dart | 2 +- ..._arrow_linked_locals_component_widget.dart | 18 +- .../local_profile_component_model.dart | 6 +- .../local_profile_component_widget.dart | 19 +- .../menu_component/menu_component_model.dart | 18 +- .../message_well_component_model.dart | 3 - .../message_well_component_widget.dart | 2 +- .../schedule_visit_detail_model.dart | 8 +- .../schedule_visit_detail_widget.dart | 1 - ...p_arrow_linked_locals_component_model.dart | 9 +- ..._arrow_linked_locals_component_widget.dart | 1 - ...cation_modal_template_component_model.dart | 7 +- ...ation_modal_template_component_widget.dart | 1 - .../card_item_template_component_widget.dart | 4 +- .../change_pass_model.dart | 4 +- .../change_pass_widget.dart | 7 +- ...ot_password_template_component_widget.dart | 2 - ...item_details_template_component_model.dart | 10 +- ...tem_details_template_component_widget.dart | 3 - .../message_notification_model.dart | 3 - .../message_notification_widget.dart | 1 - .../provisional_schedule_template_model.dart | 12 +- .../provisional_shcedule_template_widget.dart | 2 - ...ode_pass_key_template_component_model.dart | 4 +- ...siter_vistor_template_component_model.dart | 7 +- ...iter_vistor_template_component_widget.dart | 2 +- .../sign_in_template_component_model.dart | 27 +- .../sign_up_template_component_model.dart | 1 - .../sign_up_template_component_widget.dart | 7 +- .../view_visit_detail_model.dart | 7 +- .../view_visit_detail_widget.dart | 1 - ...tails_modal_template_component_widget.dart | 1 - ...search_modal_template_component_model.dart | 7 +- ...earch_modal_template_component_widget.dart | 2 +- .../welcome_template_component_widget.dart | 1 - lib/flutter_flow/flutter_flow_drop_down.dart | 1 - lib/flutter_flow/nav/nav.dart | 5 +- lib/flutter_flow/nav/serialization_util.dart | 1 - lib/flutter_flow/permissions_util.dart | 1 - lib/main.dart | 26 +- .../acess_history_page_model.dart | 7 +- .../acess_history_page_widget.dart | 3 +- .../delivery_schedule_widget.dart | 2 - .../fast_pass_page/fast_pass_page_widget.dart | 26 +- lib/pages/home_page/home_page_model.dart | 12 +- lib/pages/home_page/home_page_widget.dart | 5 +- .../liberation_history_model.dart | 8 +- .../liberation_history_widget.dart | 3 +- .../message_history_page_model.dart | 8 +- .../message_history_page_widget.dart | 3 +- .../package_order_page.dart | 8 +- .../people_on_the_property_page_widget.dart | 1 - lib/pages/pets_page/pets_history_screen.dart | 20 +- lib/pages/pets_page/pets_page_model.dart | 17 +- lib/pages/pets_page/pets_page_widget.dart | 11 - .../preferences_settings_model.dart | 22 +- .../preferences_settings_widget.dart | 6 +- .../provisional_schedule_widget.dart | 2 - .../qr_code_page/qr_code_page_model.dart | 7 +- .../qr_code_page/qr_code_page_widget.dart | 7 +- .../reception_page/reception_page_model.dart | 7 +- .../reception_page/reception_page_widget.dart | 5 +- .../register_visitor_page_model.dart | 2 - .../register_visitor_page_widget.dart | 1 - .../reservation_page_widget.dart | 26 +- .../schedule_complete_visit_page_model.dart | 15 +- .../schedule_complete_visit_page_widget.dart | 162 ++++++------ .../visit_history_page_widget.dart | 20 +- .../welcome_page/welcome_page_widget.dart | 8 +- lib/shared/helpers/secure_storage_helper.dart | 208 +++++---------- .../shared_preferences_storage_helper.dart | 90 ++++--- lib/shared/helpers/sqlite_storage_helper.dart | 240 ++---------------- lib/shared/utils/biometric_util.dart | 1 - lib/shared/utils/device_util.dart | 2 + lib/shared/utils/image_util.dart | 1 + lib/shared/utils/log_util.dart | 1 - lib/shared/utils/share_util.dart | 7 +- lib/shared/utils/storage_util.dart | 232 +++++++++++++++-- lib/shared/utils/validator_util.dart | 6 +- .../widgets/drawer_widget/drawer_widget.dart | 2 +- 98 files changed, 805 insertions(+), 943 deletions(-) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 5dbf2dbf..4f2d7865 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,19 +1,14 @@ import UIKit -import Flutter -import flutter_secure_storage -@main +import Flutter + +@UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) - - // Configurar o Keychain para remover dados quando o app for desinstalado - let secureStorage = FlutterSecureStoragePlugin() - secureStorage.setAccessibility(.whenPasscodeSetThisDeviceOnly) - return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } \ No newline at end of file diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 71181fe7..17989ffc 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -1,12 +1,11 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:hub/backend/notifications/firebase_messaging_service.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; -import 'package:hub/shared/utils/cache_util.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -62,8 +61,8 @@ class UnregisterDevice { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; return ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -93,9 +92,9 @@ class DeletePet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'excluirPet'; return ApiManager.instance.makeApiCall( @@ -138,9 +137,9 @@ class UpdatePet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'atualizarPet'; return ApiManager.instance.makeApiCall( @@ -186,9 +185,9 @@ class GetPets { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'consultaPets'; return ApiManager.instance.makeApiCall( @@ -222,9 +221,9 @@ class GetPetPhoto { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'consultaFotoPet'; return ApiManager.instance.makeApiCall( @@ -265,9 +264,9 @@ class RegisterPet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'cadastrarPet'; return ApiManager.instance.makeApiCall( @@ -312,9 +311,9 @@ class BuscaEnconcomendas { String? adresseeType = '', String? status = '', }) async { - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'getEncomendas'; final baseUrl = PhpGroup.getBaseUrl(); @@ -356,9 +355,9 @@ class CancelaVisita { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -390,8 +389,8 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; final baseUrl = PhpGroup.getBaseUrl(); return ApiManager.instance.makeApiCall( @@ -422,9 +421,9 @@ class ChangePanic { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -458,9 +457,9 @@ class ChangePass { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -495,8 +494,8 @@ class RespondeVinculo { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; return ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -528,9 +527,9 @@ class ChangeNotifica { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -562,9 +561,9 @@ class UpdToken { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final token = SecureStorageHelper().token; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final token = StorageUtil().token; return ApiManager.instance.makeApiCall( callName: 'updToken', @@ -591,12 +590,11 @@ class UpdToken { class LoginCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - - final email = SecureStorageHelper().email; - final password = SecureStorageHelper().passwd; - final type = SecureStorageHelper().deviceType; - final description = SecureStorageHelper().deviceDescription; + final devUUID = StorageUtil().devUUID; + final email = StorageUtil().email; + final password = StorageUtil().passwd; + final type = StorageUtil().deviceType; + final description = StorageUtil().deviceDescription; final token = FirebaseMessagingService.getToken(); return ApiManager.instance.makeApiCall( @@ -695,8 +693,8 @@ class GetLocalsCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; return ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -735,9 +733,9 @@ class PostScheduleVisitorCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'putVisitante'; return ApiManager.instance.makeApiCall( @@ -790,9 +788,9 @@ class PostScheduleVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'putVisita'; return ApiManager.instance.makeApiCall( @@ -844,9 +842,9 @@ class GetScheduleVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliUUID = StorageUtil().cliUUID; const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1118,9 +1116,9 @@ class GetDadosCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliUUID = StorageUtil().cliUUID; const atividade = 'getDados'; return ApiManager.instance.makeApiCall( @@ -1361,9 +1359,9 @@ class GetVisitorByDocCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'getVisitante'; return ApiManager.instance.makeApiCall( @@ -1415,9 +1413,9 @@ class GetFotoVisitanteCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'getFotoVisitante'; return ApiManager.instance.makeApiCall( @@ -1454,9 +1452,9 @@ class PostProvVisitSchedulingCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'putAgendamentoProv'; return ApiManager.instance.makeApiCall( @@ -1503,9 +1501,9 @@ class GetVisitsCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1766,9 +1764,9 @@ class DeleteVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliID = StorageUtil().cliUUID; const atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -1809,10 +1807,10 @@ class GetPessoasLocalCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final ownerUUID = SQLiteStorageHelper().ownerUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final ownerUUID = StorageUtil().ownerUUID; + final userUUID = StorageUtil().userUUID; + final cliUUID = StorageUtil().cliUUID; return ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -1875,9 +1873,9 @@ class RespondeSolicitacaoCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliUUID = StorageUtil().cliUUID; const atividade = 'respondeSolicitacao'; return ApiManager.instance.makeApiCall( @@ -1925,9 +1923,9 @@ class GetAccessCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliUUID = StorageUtil().cliUUID; const atividade = 'getAcessos'; return ApiManager.instance.makeApiCall( @@ -2174,9 +2172,9 @@ class GetLiberationsCall { final StreamController controller = StreamController(); Future.microtask(() async { - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliUUID = StorageUtil().cliUUID; const atividade = 'getSolicitacoes'; try { @@ -2366,9 +2364,9 @@ class GetMessagesCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; + final cliUUID = StorageUtil().cliUUID; const atividade = 'getMensagens'; return ApiManager.instance.makeApiCall( diff --git a/lib/backend/api_requests/api_manager.dart b/lib/backend/api_requests/api_manager.dart index 00e12f5e..72087153 100644 --- a/lib/backend/api_requests/api_manager.dart +++ b/lib/backend/api_requests/api_manager.dart @@ -148,7 +148,7 @@ class ApiCallResponse { class ApiManager { ApiManager._(); - static Map _apiCache = {}; + static final Map _apiCache = {}; static ApiManager? _instance; static ApiManager get instance => _instance ??= ApiManager._(); diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index 963caef3..ff259a39 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -1,12 +1,10 @@ import 'dart:developer'; -import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; -import 'package:hub/app_state.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; -import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'notification_service.dart'; @@ -65,7 +63,7 @@ class FirebaseMessagingService { final String? deviceToken = await _firebaseMessaging.getToken(); if (deviceToken != null) { - SecureStorageHelper().token = deviceToken; + StorageUtil().token = deviceToken; final ApiCallResponse? response; response = await PhpGroup.updToken.call(); diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index 95a587f4..2b761b8c 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -16,13 +16,14 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:sqflite/sqflite.dart'; Future onMessageReceived( Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final cliUUID = SQLiteStorageHelper().cliUUID; + final cliUUID = StorageUtil().cliUUID; answersRequest( {required BuildContext context, required String? ref, @@ -49,7 +50,7 @@ Future onMessageReceived( switch (handleClick) { case 'visit_request': showDialog( - context: SecureStorageHelper().context!, + context: StorageUtil().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -172,7 +173,7 @@ Future onMessageReceived( break; case 'access': showDialog( - context: SecureStorageHelper().context!, + context: StorageUtil().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -224,14 +225,14 @@ Future onMessageReceived( } ], // onTapCardItemAction: () {}, - buttons: [], + buttons: const [], ), ); }); break; case 'mensagem': showDialog( - context: SecureStorageHelper().context!, + context: StorageUtil().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -254,8 +255,8 @@ Future onMessageReceived( break; case 'enroll_cond': - SecureStorageHelper().haveLocal = true; - SecureStorageHelper().context!.go('/homePage'); + StorageUtil().haveLocal = true; + StorageUtil().context!.go('/homePage'); break; default: break; @@ -292,11 +293,11 @@ class NotificationService { .isNotificationAllowed() .then((isAllowed) async { final bool requestOSnotification = - SQLiteStorageHelper().requestOSnotification; + StorageUtil().requestOSnotification; if (!requestOSnotification) { if (!isAllowed) { - SQLiteStorageHelper().requestOSnotification = true; + StorageUtil().requestOSnotification = true; await AwesomeNotifications().requestPermissionToSendNotifications(); } } diff --git a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart index 7f1a787b..317a3bfa 100644 --- a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart +++ b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart @@ -4,19 +4,23 @@ import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import '../../../app_state.dart'; class MenuButtonWidget extends MenuEntry { const MenuButtonWidget({ - Key? key, + super.key, this.action, this.title, this.icon, - }) : super(key: key); + }); + @override final Function()? action; + @override final String? title; + @override final IconData? icon; @override @@ -34,7 +38,7 @@ class _MenuButtonWidgetState extends State { hoverColor: Colors.transparent, highlightColor: Colors.transparent, onTap: () async { - final cliUUID = SQLiteStorageHelper().cliUUID; + final cliUUID = StorageUtil().cliUUID; if (cliUUID.isEmpty) { return DialogUtil.warningDefault(context); diff --git a/lib/components/atomic_components/menu_card_item/menu_card_item.dart b/lib/components/atomic_components/menu_card_item/menu_card_item.dart index f4544500..4c68066e 100644 --- a/lib/components/atomic_components/menu_card_item/menu_card_item.dart +++ b/lib/components/atomic_components/menu_card_item/menu_card_item.dart @@ -5,14 +5,17 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; class MenuCardItem extends MenuEntry { const MenuCardItem({ - Key? key, + super.key, this.action, this.title, this.icon, - }) : super(key: key); + }); + @override final Function()? action; + @override final String? title; + @override final IconData? icon; @override diff --git a/lib/components/atomic_components/shared_components_atoms/appbar.dart b/lib/components/atomic_components/shared_components_atoms/appbar.dart index d8be68d9..6fe9a824 100644 --- a/lib/components/atomic_components/shared_components_atoms/appbar.dart +++ b/lib/components/atomic_components/shared_components_atoms/appbar.dart @@ -9,11 +9,11 @@ class AppBarUtil extends StatelessWidget implements PreferredSizeWidget { final Widget? actionButton; const AppBarUtil({ - Key? key, + super.key, required this.title, this.onBackButtonPressed, this.actionButton, - }) : super(key: key); + }); @override Widget build(BuildContext context) { diff --git a/lib/components/atomic_components/shared_components_atoms/custom_datepicker.dart b/lib/components/atomic_components/shared_components_atoms/custom_datepicker.dart index 78732aa3..596f50ce 100644 --- a/lib/components/atomic_components/shared_components_atoms/custom_datepicker.dart +++ b/lib/components/atomic_components/shared_components_atoms/custom_datepicker.dart @@ -18,7 +18,7 @@ class CustomDatePickerUtil extends StatefulWidget { final FormFieldValidator? validator; CustomDatePickerUtil({ - Key? key, + super.key, this.controller, this.focusNode, required this.hintText, @@ -29,7 +29,7 @@ class CustomDatePickerUtil extends StatefulWidget { required this.firstDate, this.lastDate, this.validator, - }) : super(key: key); + }); @override _CustomDatePickerState createState() => _CustomDatePickerState(); diff --git a/lib/components/atomic_components/shared_components_atoms/custom_input.dart b/lib/components/atomic_components/shared_components_atoms/custom_input.dart index b9878f1c..748448b9 100644 --- a/lib/components/atomic_components/shared_components_atoms/custom_input.dart +++ b/lib/components/atomic_components/shared_components_atoms/custom_input.dart @@ -22,7 +22,7 @@ class CustomInputUtil extends StatefulWidget { final void Function(String)? onChanged; CustomInputUtil( - {Key? key, + {super.key, this.controller, required this.labelText, required this.hintText, @@ -35,8 +35,7 @@ class CustomInputUtil extends StatefulWidget { this.maxLength = 80, this.validator, this.obscureText, - required this.haveMaxLength}) - : super(key: key); + required this.haveMaxLength}); @override State createState() => _CustomInputUtilState(); diff --git a/lib/components/atomic_components/shared_components_atoms/custom_select.dart b/lib/components/atomic_components/shared_components_atoms/custom_select.dart index 89396d14..950d43de 100644 --- a/lib/components/atomic_components/shared_components_atoms/custom_select.dart +++ b/lib/components/atomic_components/shared_components_atoms/custom_select.dart @@ -21,7 +21,7 @@ class CustomSelect extends StatefulWidget { bool isRequired; CustomSelect({ - Key? key, + super.key, required this.options, required this.optionsLabel, required this.hintText, @@ -30,7 +30,7 @@ class CustomSelect extends StatefulWidget { this.isRequired = false, this.dropDownValue, this.isMultiSelect = false, - }) : super(key: key); + }); @override _CustomSelectState createState() => _CustomSelectState(); diff --git a/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart b/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart index 7946e9b7..1dadacc9 100644 --- a/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart +++ b/lib/components/atomic_components/shared_components_atoms/media_upload_button.dart @@ -15,12 +15,12 @@ class MediaUploadButtonUtil extends StatefulWidget { FFUploadedFile? uploadedFiles; MediaUploadButtonUtil({ - Key? key, + super.key, required this.onUploadComplete, required this.isUploading, required this.labelText, this.uploadedFiles, - }) : super(key: key); + }); @override State createState() => _MediaUploadButtonUtilState(); diff --git a/lib/components/atomic_components/shared_components_atoms/submit_button.dart b/lib/components/atomic_components/shared_components_atoms/submit_button.dart index 1ca6c5d2..08180f3d 100644 --- a/lib/components/atomic_components/shared_components_atoms/submit_button.dart +++ b/lib/components/atomic_components/shared_components_atoms/submit_button.dart @@ -9,7 +9,7 @@ class SubmitButtonUtil extends StatelessWidget { final String labelText; Future Function()? onPressed; - SubmitButtonUtil({ + SubmitButtonUtil({super.key, required this.labelText, required this.onPressed, }); diff --git a/lib/components/atomic_components/shared_components_atoms/tabview.dart b/lib/components/atomic_components/shared_components_atoms/tabview.dart index 422c3d60..6ec30597 100644 --- a/lib/components/atomic_components/shared_components_atoms/tabview.dart +++ b/lib/components/atomic_components/shared_components_atoms/tabview.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; diff --git a/lib/components/molecular_components/menu_item/menu_item.dart b/lib/components/molecular_components/menu_item/menu_item.dart index 395c21ce..ce3aac0a 100644 --- a/lib/components/molecular_components/menu_item/menu_item.dart +++ b/lib/components/molecular_components/menu_item/menu_item.dart @@ -2,11 +2,11 @@ import 'package:flutter/material.dart'; abstract class MenuEntry extends StatefulWidget { const MenuEntry({ - Key? key, + super.key, this.action, this.title, this.icon, - }) : super(key: key); + }); final Function()? action; final String? title; diff --git a/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart b/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart index 19ecdff5..fe501dc9 100644 --- a/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart +++ b/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart @@ -10,10 +10,10 @@ class OptModalWidget extends StatefulWidget { final String defaultAccessType; const OptModalWidget({ - Key? key, + super.key, this.defaultPersonType = '.*', this.defaultAccessType = '.*', - }) : super(key: key); + }); @override _OptModalWidgetState createState() => _OptModalWidgetState(); diff --git a/lib/components/molecular_components/opt_modal/opt_modal_widget.dart b/lib/components/molecular_components/opt_modal/opt_modal_widget.dart index 21be811f..2a5e9329 100644 --- a/lib/components/molecular_components/opt_modal/opt_modal_widget.dart +++ b/lib/components/molecular_components/opt_modal/opt_modal_widget.dart @@ -11,10 +11,10 @@ class OptModalWidget extends StatefulWidget { final String defaultAccessType; const OptModalWidget({ - Key? key, + super.key, this.defaultPersonType = '.*', this.defaultAccessType = '.*', - }) : super(key: key); + }); @override _OptModalWidgetState createState() => _OptModalWidgetState(); @@ -315,12 +315,12 @@ class _OptModalWidgetState extends State { ), ElevatedButton( onPressed: _applyFilter, - child: - Text(FFLocalizations.of(context).getText('88kshkph')), style: ElevatedButton.styleFrom( foregroundColor: FlutterFlowTheme.of(context).info, backgroundColor: FlutterFlowTheme.of(context).primary, ), + child: + Text(FFLocalizations.of(context).getText('88kshkph')), ), ], ), diff --git a/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart b/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart index ebae1e35..ce905389 100644 --- a/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart +++ b/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart @@ -5,16 +5,17 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class OrderFilterModalWidget extends StatefulWidget { final String defaultAdresseeType; final String defaultStatus; const OrderFilterModalWidget({ - Key? key, + super.key, this.defaultAdresseeType = '.*', this.defaultStatus = '.*', - }) : super(key: key); + }); @override _OrderFilterModalWidgetState createState() => _OrderFilterModalWidgetState(); @@ -26,25 +27,25 @@ class _OrderFilterModalWidgetState extends State { late Map selected; final List> adresseeTypeOptions = [ { - 'title': FFLocalizations.of(SecureStorageHelper().context!) + 'title': FFLocalizations.of(StorageUtil().context!) .getVariableText(enText: 'Resident', ptText: 'Morador'), 'value': 'MOR' }, { - 'title': FFLocalizations.of(SecureStorageHelper().context!) + 'title': FFLocalizations.of(StorageUtil().context!) .getVariableText(enText: 'Property', ptText: 'Propriedade'), 'value': 'PRO' }, ]; final List> statusOptions = [ { - 'title': FFLocalizations.of(SecureStorageHelper().context!) + 'title': FFLocalizations.of(StorageUtil().context!) .getVariableText( ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'), 'value': 'notPickedUp' }, { - 'title': FFLocalizations.of(SecureStorageHelper().context!) + 'title': FFLocalizations.of(StorageUtil().context!) .getVariableText(ptText: 'Retirado', enText: 'Picked Up'), 'value': 'pickedUp' }, diff --git a/lib/components/molecular_components/visitor_not_found_component/visitor_not_found_component_widget.dart b/lib/components/molecular_components/visitor_not_found_component/visitor_not_found_component_widget.dart index 5b5ce3be..00261f19 100644 --- a/lib/components/molecular_components/visitor_not_found_component/visitor_not_found_component_widget.dart +++ b/lib/components/molecular_components/visitor_not_found_component/visitor_not_found_component_widget.dart @@ -9,7 +9,7 @@ import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; class VisitorNotFoundComponentWidget extends StatefulWidget { - const VisitorNotFoundComponentWidget({this.doc, Key? key}) : super(key: key); + const VisitorNotFoundComponentWidget({this.doc, super.key}); final String? doc; @override diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index 322184b3..82d5e236 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -6,6 +6,7 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; import '/backend/api_requests/api_calls.dart'; @@ -70,7 +71,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState final List locals = response.jsonBody['locais'] ?? []; - if (locals != null && locals.isNotEmpty) { + if (locals.isNotEmpty) { setState(() { _localsWrap.addAll(locals); _hasData = true; @@ -80,9 +81,9 @@ class _BottomArrowLinkedLocalsComponentWidgetState // Verifica se há apenas um local e se o status é 'A' if (locals.length == 1 && locals[0]['CLU_STATUS'] == 'A') { final local = locals[0]; - SQLiteStorageHelper().cliName = local['CLI_NOME']; - SQLiteStorageHelper().cliUUID = local['CLI_ID']; - SQLiteStorageHelper().ownerUUID = local['CLU_OWNER_ID']; + StorageUtil().cliName = local['CLI_NOME']; + StorageUtil().cliUUID = local['CLI_ID']; + StorageUtil().ownerUUID = local['CLU_OWNER_ID']; context.pop(); } @@ -104,6 +105,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState _loading = false; }); } + return null; } Future _fetchResponseLink(String status, String cliID) async { @@ -170,9 +172,9 @@ class _BottomArrowLinkedLocalsComponentWidgetState statusHashMap: [_statusHashMap(local)], onTapCardItemAction: () async { if (local['CLU_STATUS'] == 'A') { - SQLiteStorageHelper().cliUUID = local['CLI_ID']; - SQLiteStorageHelper().cliName = local['CLI_NOME']; - SQLiteStorageHelper().ownerUUID = local['CLU_OWNER_ID']; + StorageUtil().cliUUID = local['CLI_ID']; + StorageUtil().cliName = local['CLI_NOME']; + StorageUtil().ownerUUID = local['CLU_OWNER_ID']; context.pop(); } else if (local['CLU_STATUS'] == 'B') { @@ -292,7 +294,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState FFLocalizations.of(context).getVariableText( ptText: 'Escolha um local', enText: 'Choose a location'), overflow: TextOverflow.ellipsis, - style: TextStyle(fontWeight: FontWeight.bold), + style: const TextStyle(fontWeight: FontWeight.bold), )))), ), ), diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart index efd60746..84b308c6 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart +++ b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart @@ -1,6 +1,6 @@ -import 'dart:math'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'local_profile_component_widget.dart' show LocalProfileComponentWidget; @@ -20,8 +20,8 @@ class LocalProfileComponentModel } Future getData() async { - cliName = SQLiteStorageHelper().cliName; - cliUUID = SQLiteStorageHelper().cliUUID; + cliName = StorageUtil().cliName; + cliUUID = StorageUtil().cliUUID; setStateCallback?.call(); } 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 5f0717b3..20d270b5 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 @@ -7,6 +7,7 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; import '/flutter_flow/custom_functions.dart' as functions; @@ -17,7 +18,7 @@ import 'local_profile_component_model.dart'; export 'local_profile_component_model.dart'; class LocalProfileComponentWidget extends StatefulWidget { - LocalProfileComponentWidget({Key? key}) : super(key: key); + const LocalProfileComponentWidget({super.key}); @override State createState() => @@ -42,7 +43,7 @@ class _LocalProfileComponentWidgetState _model.setStateCallback = () => safeSetState(() {}); () async { - _model.cliUUID = SQLiteStorageHelper().cliUUID; + _model.cliUUID = StorageUtil().cliUUID; if (_model.cliUUID.isEmpty) { await processLocals(); @@ -73,11 +74,11 @@ class _LocalProfileComponentWidgetState final petAmountRegister = response.jsonBody['petAmountRegister'] ?? '0'; final name = response.jsonBody['visitado']['VDO_NOME']; - SQLiteStorageHelper().whatsapp = whatsapp; - SQLiteStorageHelper().provisional = provisional; - SQLiteStorageHelper().pets = pets; - SQLiteStorageHelper().petAmountRegister = petAmountRegister; - SQLiteStorageHelper().cliName = name; + StorageUtil().whatsapp = whatsapp; + StorageUtil().provisional = provisional; + StorageUtil().pets = pets; + StorageUtil().petAmountRegister = petAmountRegister; + StorageUtil().cliName = name; safeSetState(() {}); return; @@ -86,7 +87,7 @@ class _LocalProfileComponentWidgetState DialogUtil.warningDefault(context).whenComplete(() => processLocals()); safeSetState(() {}); return; - } catch (e, s) { + } catch (e) { DialogUtil.warningDefault(context).whenComplete(() => processLocals()); } } @@ -95,7 +96,7 @@ class _LocalProfileComponentWidgetState try { final GetLocalsCall callback = PhpGroup.getLocalsCall; - final cliUUID = SQLiteStorageHelper().cliUUID; + final cliUUID = StorageUtil().cliUUID; var response = await callback.call(); List locals = response.jsonBody['locais'] ?? []; diff --git a/lib/components/organism_components/menu_component/menu_component_model.dart b/lib/components/organism_components/menu_component/menu_component_model.dart index 0d61b860..6c99d9a6 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -72,7 +72,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future deliverySchedule(BuildContext context) async { - final bool isProvisional = SQLiteStorageHelper().provisional; + final bool isProvisional = StorageUtil().provisional; if (isProvisional == true) { context.push( @@ -91,7 +91,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future provisionalSchedule(BuildContext context) async { - final isProvisional = SQLiteStorageHelper().provisional; + final isProvisional = StorageUtil().provisional; if (isProvisional == true) { context.push( '/provisionalSchedule', @@ -109,7 +109,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future fastPassAction(BuildContext context) async { - final isWpp = SQLiteStorageHelper().whatsapp; + final isWpp = StorageUtil().whatsapp; if (isWpp) { context.push( '/fastPassPage', @@ -201,7 +201,7 @@ class MenuComponentModel extends FlutterFlowModel { ptText: 'Tem certeza', ), () async { PhpGroup.unregisterDevice.call(); - StorageManager.purge(); + StorageUtil.purge(); context.go( '/welcomePage', @@ -231,7 +231,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future packageOrder(BuildContext context) async { - final isWpp = SQLiteStorageHelper().whatsapp; + final isWpp = StorageUtil().whatsapp; if (isWpp) { context.push( @@ -250,7 +250,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future reservation(BuildContext context) async { - final isWpp = SQLiteStorageHelper().whatsapp; + final isWpp = StorageUtil().whatsapp; if (isWpp) { context.push( '/reservation', @@ -277,13 +277,13 @@ class MenuComponentModel extends FlutterFlowModel { return Padding( padding: MediaQuery.viewInsetsOf(context), child: OptionSelectionModalWidget( - routesListStr: [ + routesListStr: const [ 'liberationHistory', 'acessHistoryPage', 'scheduleCompleteVisitPage', 'messageHistoryPage' ], - iconsListIcon: [ + iconsListIcon: const [ Icons.history_rounded, Icons.history_rounded, Icons.history_rounded, @@ -366,7 +366,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future petsAction(BuildContext context) async { - bool isPet = SQLiteStorageHelper().pets; + bool isPet = StorageUtil().pets; if (isPet) { context.push( '/petsPage', diff --git a/lib/components/organism_components/message_well_component/message_well_component_model.dart b/lib/components/organism_components/message_well_component/message_well_component_model.dart index e6b577de..d3aad87c 100644 --- a/lib/components/organism_components/message_well_component/message_well_component_model.dart +++ b/lib/components/organism_components/message_well_component/message_well_component_model.dart @@ -6,9 +6,6 @@ import '/flutter_flow/flutter_flow_util.dart'; import 'message_well_component_widget.dart' show MessageWellComponentWidget; import 'package:flutter/material.dart'; -/// - -import 'package:flutter/material.dart'; class MessageWellComponentModel diff --git a/lib/components/organism_components/message_well_component/message_well_component_widget.dart b/lib/components/organism_components/message_well_component/message_well_component_widget.dart index 81de018c..40005da6 100644 --- a/lib/components/organism_components/message_well_component/message_well_component_widget.dart +++ b/lib/components/organism_components/message_well_component/message_well_component_widget.dart @@ -35,7 +35,7 @@ class _MessageWellComponentWidgetState @override void initState() { super.initState(); - WidgetsBinding.instance?.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { context.read().fetchMessages(); }); diff --git a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart index 1edff6aa..f594143b 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:hub/backend/api_requests/api_manager.dart'; @@ -6,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:hub/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:intl/intl.dart'; class ScheduleVisitDetailModel @@ -59,9 +59,9 @@ class ScheduleVisitDetailModel } Future initDB() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart index 9051c4d5..19bbfa3a 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart @@ -9,7 +9,6 @@ import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:provider/provider.dart'; class ScheduleVisitDetailWidget extends StatefulWidget { const ScheduleVisitDetailWidget({ diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart index fff98ee1..231bdfb6 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart @@ -3,6 +3,7 @@ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:flutter/material.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel { @@ -17,10 +18,10 @@ class UpArrowLinkedLocalsComponentModel } Future initDB() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; - cliName = SQLiteStorageHelper().cliName; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; + cliName = StorageUtil().cliName; } @override diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart index d2a448e5..9415e7fc 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart @@ -7,7 +7,6 @@ import 'package:hub/components/organism_components/up_arrow_linked_locals_compon import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:provider/provider.dart'; class UpArrowLinkedLocalsComponentWidget extends StatefulWidget { const UpArrowLinkedLocalsComponentWidget({super.key}); diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart index a24124ac..6622fb27 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -32,9 +33,9 @@ class AccessNotificationModalTemplateComponentModel } Future initDB() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart index 999fcf5b..652bdfe6 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart @@ -3,7 +3,6 @@ import '/flutter_flow/flutter_flow_util.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:provider/provider.dart'; import 'access_notification_modal_template_component_model.dart'; export 'access_notification_modal_template_component_model.dart'; diff --git a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart index 80be7d12..4cb84ecc 100644 --- a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart +++ b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart @@ -13,12 +13,12 @@ export 'card_item_template_component_model.dart'; class CardItemTemplateComponentWidget extends StatefulWidget { const CardItemTemplateComponentWidget({ - Key? key, + super.key, required this.labelsHashMap, required this.statusHashMap, required this.imagePath, required this.onTapCardItemAction, - }) : super(key: key); + }); final Map? labelsHashMap; final List?> statusHashMap; diff --git a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_model.dart b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_model.dart index 25cc4529..716e98ef 100644 --- a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_model.dart +++ b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_model.dart @@ -26,10 +26,12 @@ class PassKeyTemplateComponentModel ptText: 'Este campo é obrigatório', ); } - if ( val.length < 4 ) return FFLocalizations.of(context).getVariableText( + if ( val.length < 4 ) { + return FFLocalizations.of(context).getVariableText( enText: 'This field must have at least 4 characters', ptText: 'Este campo deve ter pelo menos 4 caracteres', ); + } return null; } diff --git a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart index 832f2cd6..b709cc5b 100644 --- a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart +++ b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -130,7 +131,7 @@ class _PassKeyTemplateWidgetState extends State { child: Text( FFLocalizations.of(context).getVariableText( enText: 'INSERT PASSWORD', - ptText: SecureStorageHelper().accessPass != '' + ptText: StorageUtil().accessPass != '' ? 'ALTERAR SENHA' : 'ADICIONAR SENHA', ), @@ -317,10 +318,10 @@ class _PassKeyTemplateWidgetState extends State { context.pop(true); }, text: FFLocalizations.of(context).getVariableText( - ptText: SecureStorageHelper().accessPass != '' + ptText: StorageUtil().accessPass != '' ? 'Alterar' : 'Adicionar', - enText: SecureStorageHelper().accessPass != '' + enText: StorageUtil().accessPass != '' ? 'Change' : 'Add', ), diff --git a/lib/components/templates_components/forgot_password_template_component/forgot_password_template_component_widget.dart b/lib/components/templates_components/forgot_password_template_component/forgot_password_template_component_widget.dart index a5033296..88a2f4b8 100644 --- a/lib/components/templates_components/forgot_password_template_component/forgot_password_template_component_widget.dart +++ b/lib/components/templates_components/forgot_password_template_component/forgot_password_template_component_widget.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/utils/dialog_util.dart'; @@ -6,7 +5,6 @@ import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/backend/api_requests/api_calls.dart'; -import '/components/molecular_components/throw_exception/throw_exception_widget.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/flutter_flow/flutter_flow_widgets.dart'; diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart index e6653c0b..63ce5b0e 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart @@ -1,10 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:hub/app_state.dart'; -import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class LiberationHistoryItemDetailsTemplateComponentModel extends FlutterFlowModel< @@ -30,9 +28,9 @@ class LiberationHistoryItemDetailsTemplateComponentModel void initState(BuildContext context) {} Future initDatabase() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart index 23a0d124..539f36eb 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart @@ -1,12 +1,9 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/app_state.dart'; import 'package:hub/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart'; -import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:provider/provider.dart'; class LiberationHistoryItemDetailsTemplateComponentWidget extends StatefulWidget { diff --git a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_model.dart b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_model.dart index f949913a..74099118 100644 --- a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_model.dart +++ b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_model.dart @@ -1,9 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:hub/app_state.dart'; -import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; class MessageNotificationModalTemplateComponentModel extends FlutterFlowModel { diff --git a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart index 303780ca..2055c251 100644 --- a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart +++ b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart @@ -3,7 +3,6 @@ import 'package:google_fonts/google_fonts.dart'; import 'package:hub/components/templates_components/message_notificaion_modal_template_component/message_notification_model.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:provider/provider.dart'; class MessageNotificationModalTemplateComponentWidget extends StatefulWidget { const MessageNotificationModalTemplateComponentWidget({ diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart index d62becb1..d8e0e8e0 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart @@ -3,7 +3,7 @@ import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; -import 'package:sqflite/sqflite.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class ScheduleProvisionalVisitPageModel extends FlutterFlowModel { @@ -124,11 +124,11 @@ class ScheduleProvisionalVisitPageModel } Future init() async { - cliUUID = SQLiteStorageHelper().cliUUID; - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliName = SQLiteStorageHelper().cliName; - ownerUUID = SQLiteStorageHelper().ownerUUID; + cliUUID = StorageUtil().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliName = StorageUtil().cliName; + ownerUUID = StorageUtil().ownerUUID; setState?.call(); } diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart index d3041fa1..ad763b85 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart @@ -4,10 +4,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart'; -import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; -import 'package:provider/provider.dart'; import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_theme.dart'; diff --git a/lib/components/templates_components/qr_code_pass_key_template_component/qr_code_pass_key_template_component_model.dart b/lib/components/templates_components/qr_code_pass_key_template_component/qr_code_pass_key_template_component_model.dart index da0ca0a5..7d6efd50 100644 --- a/lib/components/templates_components/qr_code_pass_key_template_component/qr_code_pass_key_template_component_model.dart +++ b/lib/components/templates_components/qr_code_pass_key_template_component/qr_code_pass_key_template_component_model.dart @@ -21,10 +21,12 @@ class QrCodePassKeyTemplateComponentModel ptText: 'Este campo é obrigatório', ); } - if (val.length < 4) return FFLocalizations.of(context).getVariableText( + if (val.length < 4) { + return FFLocalizations.of(context).getVariableText( enText: 'This field must be at least 4 characters', ptText: 'Este campo deve ter pelo menos 4 caracteres', ); + } return null; } diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart index cd667c8e..2bde3236 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/backend/api_requests/api_calls.dart'; @@ -134,9 +135,9 @@ class RegisiterVistorTemplateComponentModel } Future initializeDatabase() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart index 3bd63a0e..924af967 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart @@ -68,7 +68,7 @@ class _RegisiterVistorTemplateComponentWidgetState _model.textController4 ??= TextEditingController(); _model.textFieldFocusNode4 ??= FocusNode(); - WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { _model.textController2.text = widget.doc ?? ''; }); } diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart index 1415d199..f4bbed31 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart @@ -1,13 +1,12 @@ import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/flutter_flow/random_data_util.dart'; -import 'package:hub/pages/home_page/home_page_model.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/device_util.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'sign_in_template_component_widget.dart' @@ -88,7 +87,7 @@ class SignInTemplateComponentModel try { final ApiCallResponse? response; final LoginCall callback = PhpGroup.loginCall; - SecureStorageHelper().deviceDescription = randomString( + StorageUtil().deviceDescription = randomString( 10, 10, true, @@ -111,27 +110,27 @@ class SignInTemplateComponentModel devUUID = await DeviceUtil.getDevUUID(); if ((email != '') && (passwd != '')) { - SecureStorageHelper().email = email; - SecureStorageHelper().passwd = passwd; + StorageUtil().email = email; + StorageUtil().passwd = passwd; + StorageUtil().devUUID = devUUID!; response = await callback.call(); if (response.jsonBody['error'] == false) { + userUUID = response.jsonBody['uid']; - status = response.jsonBody['user']['status']; userDevUUID = response.jsonBody['user']['dev_id']; userName = response.jsonBody['user']['name']; - SQLiteStorageHelper().devUUID = devUUID!; - SQLiteStorageHelper().userUUID = userUUID; - SQLiteStorageHelper().userDevUUID = userDevUUID; - SQLiteStorageHelper().status = status; - SQLiteStorageHelper().userName = userName; + StorageUtil().userUUID = userUUID; + StorageUtil().userDevUUID = userDevUUID; + StorageUtil().status = status; + StorageUtil().userName = userName; isLogged = true; await checkLocals(context: context, model: model).then((value) { - SecureStorageHelper().haveLocal = value; - SecureStorageHelper().isLogged = isLogged; + StorageUtil().haveLocal = value; + StorageUtil().isLogged = isLogged; toggleApp(context); }); } else { @@ -153,7 +152,7 @@ class SignInTemplateComponentModel } Future toggleApp(BuildContext context) async { - final haveLocal = SecureStorageHelper().haveLocal; + final haveLocal = StorageUtil().haveLocal; if (haveLocal == true) { context.go('/homePage'); } else if (haveLocal == false) { diff --git a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_model.dart b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_model.dart index 57fc1e84..62d43a2d 100644 --- a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_model.dart +++ b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_model.dart @@ -1,5 +1,4 @@ import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/random_data_util.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; diff --git a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart index 59fc1cc5..8dd9accf 100644 --- a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart +++ b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart @@ -5,6 +5,7 @@ import 'package:google_fonts/google_fonts.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/atom_image_svg_theme.dart'; import 'package:hub/shared/components/atoms/atom_terms_of_use.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; import 'package:provider/provider.dart'; @@ -105,7 +106,7 @@ class _SignUpTemplateComponentWidgetState final double screenWidth = mediaQuery.size.width; final double screenHeight = mediaQuery.size.height; - bool _isFormInvalid() { + bool isFormInvalid() { if (_model.nameRegisterFormTextController.text == '' || _model.emailRegisterFormTextController.text == '' || _model.passwordRegisterFormTextController.text == '') { @@ -684,7 +685,7 @@ class _SignUpTemplateComponentWidgetState padding: const EdgeInsetsDirectional .fromSTEB(0.0, 0.0, 0.0, 16.0), child: FFButtonWidget( - onPressed: _isFormInvalid() + onPressed: isFormInvalid() ? null : () async { var shouldSetState = false; @@ -701,7 +702,7 @@ class _SignUpTemplateComponentWidgetState .emailRegisterFormTextController .text, device: - SecureStorageHelper() + StorageUtil() .deviceType, ); shouldSetState = true; diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart index 8bb70b0d..1188b53b 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart @@ -1,4 +1,5 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -36,9 +37,9 @@ class ViewVisitDetailModel extends FlutterFlowModel { } Future initializeDatabase() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart index d58b7043..fbbd960a 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/utils/dialog_util.dart'; -import 'package:provider/provider.dart'; import 'package:share_plus/share_plus.dart'; import '/backend/api_requests/api_calls.dart'; diff --git a/lib/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_widget.dart b/lib/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_widget.dart index bc39e658..f4864b0b 100644 --- a/lib/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_widget.dart +++ b/lib/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_widget.dart @@ -1,4 +1,3 @@ -import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:hub/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart'; diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart index 7c06018b..d0695010 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart @@ -4,6 +4,7 @@ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:flutter/material.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel { @@ -39,9 +40,9 @@ class VisitorSearchModalTemplateComponentModel } Future initDatabase() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart index 713cc6f8..584b48fe 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart @@ -179,7 +179,7 @@ class _VisitorSearchModalTemplateComponentWidgetState ], ), ), - if (_model.visitors.isNotEmpty && _model.visitors.length > 0) + if (_model.visitors.isNotEmpty && _model.visitors.isNotEmpty) Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, diff --git a/lib/components/templates_components/welcome_template_component/welcome_template_component_widget.dart b/lib/components/templates_components/welcome_template_component/welcome_template_component_widget.dart index e0b97fe2..999a3a80 100644 --- a/lib/components/templates_components/welcome_template_component/welcome_template_component_widget.dart +++ b/lib/components/templates_components/welcome_template_component/welcome_template_component_widget.dart @@ -6,7 +6,6 @@ import '/flutter_flow/flutter_flow_util.dart'; import '/flutter_flow/flutter_flow_widgets.dart'; import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; -import 'package:flutter_svg/flutter_svg.dart'; import 'package:google_fonts/google_fonts.dart'; import 'welcome_template_component_model.dart'; export 'welcome_template_component_model.dart'; diff --git a/lib/flutter_flow/flutter_flow_drop_down.dart b/lib/flutter_flow/flutter_flow_drop_down.dart index 35831023..493a9e50 100644 --- a/lib/flutter_flow/flutter_flow_drop_down.dart +++ b/lib/flutter_flow/flutter_flow_drop_down.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'form_field_controller.dart'; -import 'package:flutter/material.dart'; class FlutterFlowDropDown extends StatefulWidget { const FlutterFlowDropDown({ diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 013fcb8f..13334eb7 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -11,6 +11,7 @@ import 'package:hub/pages/provisional_schedule_page/provisional_schedule_widget. import 'package:hub/pages/reception_page/reception_page_widget.dart'; import 'package:hub/pages/reservation_page/reservation_page_widget.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; import '/backend/schema/structs/index.dart'; @@ -73,8 +74,8 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter( FFRoute( name: '_initialize', path: '/', - builder: (context, _) => SecureStorageHelper().isLogged - ? SecureStorageHelper().haveLocal == true + builder: (context, _) => StorageUtil().isLogged + ? StorageUtil().haveLocal == true ? const HomePageWidget() : const ReceptionPageWidget() : const WelcomePageWidget(), diff --git a/lib/flutter_flow/nav/serialization_util.dart b/lib/flutter_flow/nav/serialization_util.dart index 349feee6..9ee5ecdb 100644 --- a/lib/flutter_flow/nav/serialization_util.dart +++ b/lib/flutter_flow/nav/serialization_util.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:developer'; import 'package:flutter/material.dart'; diff --git a/lib/flutter_flow/permissions_util.dart b/lib/flutter_flow/permissions_util.dart index 304c8a17..10768b17 100644 --- a/lib/flutter_flow/permissions_util.dart +++ b/lib/flutter_flow/permissions_util.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:permission_handler/permission_handler.dart'; const kPermissionStateToBool = { diff --git a/lib/main.dart b/lib/main.dart index dee73e96..20bdcc59 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,12 +12,10 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; import 'package:hub/backend/notifications/notification_service.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; -import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; -import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:responsive_framework/responsive_framework.dart'; final GlobalKey navigatorKey = GlobalKey(); @@ -43,19 +41,13 @@ Future _initializeApp() async { + + Future _initializeStorageHelpers() async { - final SharedPreferencesStorageHelper sharedPreferencesHelper = SharedPreferencesStorageHelper(); - final SecureStorageHelper secureStorageHelper = SecureStorageHelper(); - final SQLiteStorageHelper sqLiteStorageHelper = SQLiteStorageHelper(); + await StorageUtil().ensureInitialization(); - await sqLiteStorageHelper.ensureInitialization(); - await sharedPreferencesHelper.ensureInitialization(); - await secureStorageHelper.ensureInitialization(); - if (sharedPreferencesHelper.isFirstRun) { - sharedPreferencesHelper.isFirstRun = false; - secureStorageHelper.purge(); - } + } Future _initializeTracking() async { @@ -95,8 +87,8 @@ Future _initializeFlutterFlow() async { Future _foregroundHandleMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - SecureStorageHelper().haveLocal = true; - SecureStorageHelper().context?.go('/homePage'); + StorageUtil().haveLocal = true; + StorageUtil().context?.go('/homePage'); } if (!Platform.isIOS) { NotificationService.show( @@ -108,8 +100,8 @@ Future _foregroundHandleMessage(RemoteMessage message) async { Future _backgroundHandleMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - SecureStorageHelper().set('haveLocal', 'true'); - SecureStorageHelper().context?.go('/homePage'); + StorageUtil().haveLocal = true; + StorageUtil().context?.go('/homePage'); } } diff --git a/lib/pages/acess_history_page/acess_history_page_model.dart b/lib/pages/acess_history_page/acess_history_page_model.dart index 93e9de78..89ca0b9d 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -5,6 +5,7 @@ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/acess_history_page/acess_history_page_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class AcessHistoryPageModel extends FlutterFlowModel { late final String devUUID; @@ -33,9 +34,9 @@ class AcessHistoryPageModel extends FlutterFlowModel { } Future initDatabase() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/pages/acess_history_page/acess_history_page_widget.dart b/lib/pages/acess_history_page/acess_history_page_widget.dart index 854d8eb6..b9234979 100644 --- a/lib/pages/acess_history_page/acess_history_page_widget.dart +++ b/lib/pages/acess_history_page/acess_history_page_widget.dart @@ -199,7 +199,7 @@ class _AccessHistoryState extends State { return personTypeMatches; }).toList(); - if (filteredAccess != null && filteredAccess.isNotEmpty) { + if (filteredAccess.isNotEmpty) { setState(() { _accessWrap.addAll(filteredAccess); _hasData = true; @@ -221,6 +221,7 @@ class _AccessHistoryState extends State { _loading = false; }); } + return null; } void _showNoMoreDataSnackbar(BuildContext context) { diff --git a/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart b/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart index 357b751f..46d3c440 100644 --- a/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart +++ b/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart @@ -1,11 +1,9 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:provider/provider.dart'; import '/flutter_flow/flutter_flow_util.dart'; diff --git a/lib/pages/fast_pass_page/fast_pass_page_widget.dart b/lib/pages/fast_pass_page/fast_pass_page_widget.dart index 1a732254..dc4fadfa 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -7,11 +7,14 @@ import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:webview_flutter/webview_flutter.dart'; class FastPassPageWidget extends StatefulWidget { + const FastPassPageWidget({super.key}); + @override _FastPassPageWidgetState createState() => _FastPassPageWidgetState(); } @@ -21,19 +24,14 @@ class _FastPassPageWidgetState extends State { late WebViewController _controllerAll; Future> initVariables() async { - final email = SecureStorageHelper().email; - final name = SQLiteStorageHelper().userName; - final userUUID = SQLiteStorageHelper().userUUID; - final devUUID = SQLiteStorageHelper().devUUID; - final cliUUID = SQLiteStorageHelper().cliUUID; - final createdAt = '0000-00-00 00:00:00'; + final email = StorageUtil().email; + final name = StorageUtil().userName; + final userUUID = StorageUtil().userUUID; + final devUUID = StorageUtil().devUUID; + final cliUUID = StorageUtil().cliUUID; + const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; - final freUserData = "{\"name\": \"$name\", " + - "\"email\": \"$email\"," + - "\"dev_id\": \"$devUUID\"," + - "\"created_at\":\"$createdAt\"," + - "\"updated_at\": \"0000-00-00 00:00:00\"," + - "\"status\": \"A\" }"; + final freUserData = "{\"name\": \"$name\", \"email\": \"$email\",\"dev_id\": \"$devUUID\",\"created_at\":\"$createdAt\",\"updated_at\": \"0000-00-00 00:00:00\",\"status\": \"A\" }"; return { 'url': url, @@ -55,7 +53,7 @@ class _FastPassPageWidgetState extends State { future: initVariables(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return Center(child: CircularProgressIndicator()); + return const Center(child: CircularProgressIndicator()); } else if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); } else if (snapshot.hasData) { @@ -143,7 +141,7 @@ class _FastPassPageWidgetState extends State { ..loadRequest(Uri.parse(url)), ); } else { - return Center(child: Text('Unexpected error')); + return const Center(child: Text('Unexpected error')); } }, ), diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index 99505b0e..11baa3ae 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hub/app_state.dart'; import 'package:hub/components/organism_components/local_profile_component/local_profile_component_model.dart'; import 'package:hub/components/organism_components/menu_component/menu_component_model.dart'; import 'package:hub/components/organism_components/message_well_component/message_well_component_model.dart'; @@ -7,6 +6,7 @@ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/home_page/home_page_widget.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class HomePageModel extends FlutterFlowModel { bool isGrid = false; @@ -25,11 +25,11 @@ class HomePageModel extends FlutterFlowModel { late MessageWellComponentModel messageWellComponentModel; Future _initVariable() async { - devUUID = SQLiteStorageHelper().devUUID; - cliUUID = SQLiteStorageHelper().cliUUID; - userUUID = SQLiteStorageHelper().userUUID; - userName = SQLiteStorageHelper().cliName; - userEmail = SecureStorageHelper().email; + devUUID = StorageUtil().devUUID; + cliUUID = StorageUtil().cliUUID; + userUUID = StorageUtil().userUUID; + userName = StorageUtil().cliName; + userEmail = StorageUtil().email; } @override diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index 949e94d0..d0824e48 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -13,10 +13,11 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/home_page/home_page_model.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart'; class HomePageWidget extends StatefulWidget { - const HomePageWidget({Key? key}) : super(key: key); + const HomePageWidget({super.key}); @override State createState() => _HomePageWidgetState(); @@ -52,7 +53,7 @@ class _HomePageWidgetState extends State { @override Widget build(BuildContext context) { - SecureStorageHelper().context = context; + StorageUtil().context = context; return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index e0d075ed..bc339f98 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -1,11 +1,11 @@ import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:flutter/material.dart'; import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class LiberationHistoryModel extends FlutterFlowModel { late final String devUUID; @@ -38,9 +38,9 @@ class LiberationHistoryModel extends FlutterFlowModel { } Future init() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliName; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliName; } Future answersRequest( diff --git a/lib/pages/liberation_history/liberation_history_widget.dart b/lib/pages/liberation_history/liberation_history_widget.dart index 65811564..953a102f 100644 --- a/lib/pages/liberation_history/liberation_history_widget.dart +++ b/lib/pages/liberation_history/liberation_history_widget.dart @@ -331,7 +331,7 @@ class _LiberationHistoryWidgetState extends State { final List requests = response.jsonBody['solicitacoes'] ?? []; - if (requests != null && requests.isNotEmpty) { + if (requests.isNotEmpty) { setState(() { _requestWrap.addAll(requests); _hasData = true; @@ -358,6 +358,7 @@ class _LiberationHistoryWidgetState extends State { _loading = false; }); } + return null; } void _showNoMoreDataSnackBar(BuildContext context) { diff --git a/lib/pages/message_history_page/message_history_page_model.dart b/lib/pages/message_history_page/message_history_page_model.dart index f2b8300b..66f17cc2 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -1,4 +1,3 @@ -import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; @@ -6,6 +5,7 @@ import 'package:hub/flutter_flow/request_manager.dart'; import 'package:flutter/material.dart'; import 'package:hub/pages/message_history_page/message_history_page_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; class MessageHistoryPageModel extends FlutterFlowModel { @@ -43,9 +43,9 @@ class MessageHistoryPageModel } Future init() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override diff --git a/lib/pages/message_history_page/message_history_page_widget.dart b/lib/pages/message_history_page/message_history_page_widget.dart index 625d274c..8a149975 100644 --- a/lib/pages/message_history_page/message_history_page_widget.dart +++ b/lib/pages/message_history_page/message_history_page_widget.dart @@ -105,7 +105,7 @@ class _MessageHistoryPageWidgetState extends State final List messages = response.jsonBody['mensagens'] ?? []; - if (messages != null && messages.isNotEmpty) { + if (messages.isNotEmpty) { setState(() { _messageWrap.addAll(messages); _hasData = true; @@ -131,6 +131,7 @@ class _MessageHistoryPageWidgetState extends State _loading = false; }); } + return null; } void _loadMore() { diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index fae8194d..527ccbeb 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -12,6 +12,7 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; import 'package:rxdart/rxdart.dart'; @@ -63,7 +64,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = SQLiteStorageHelper().cliUUID; + cliUUID = StorageUtil().cliUUID; } @override @@ -99,7 +100,7 @@ class _PackageOrderPage extends State { final List orders = response.jsonBody['value']['list'] ?? []; - if (orders != null && orders.isNotEmpty) { + if (orders.isNotEmpty) { setState(() { _orderList.addAll(orders); _hasData = true; @@ -125,6 +126,7 @@ class _PackageOrderPage extends State { _loading = false; }); } + return null; } void _loadMoreOrders() { @@ -413,7 +415,7 @@ class _PackageOrderPage extends State { FlutterFlowTheme.of(context).primary, }), ], - buttons: [], + buttons: const [], ), ); }); diff --git a/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart b/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart index f2f8ceac..c6852f85 100644 --- a/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart +++ b/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart @@ -8,7 +8,6 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/people_on_the_property_page/people_on_the_property_page_model.dart'; -import 'package:provider/provider.dart'; import '../../shared/utils/log_util.dart'; diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index 8bbff0a5..34b7a39e 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -9,10 +9,11 @@ import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_p import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; class PetsHistoryScreen extends StatefulWidget { - PetsHistoryScreen({Key? key, required this.model}) : super(key: key); + const PetsHistoryScreen({super.key, required this.model}); final PetsPageModel model; @@ -66,7 +67,7 @@ class _PetsHistoryScreenState extends State final List pets = response.jsonBody['pets']['list'] ?? []; safeSetState(() => count = response.jsonBody['pets']['count'] ?? 0); - if (pets != null && pets.isNotEmpty) { + if (pets.isNotEmpty) { setState(() { _petsWrap.addAll(pets); _hasData = true; @@ -93,6 +94,7 @@ class _PetsHistoryScreenState extends State _loading = false; }); } + return null; } void _loadMore() { @@ -150,7 +152,7 @@ class _PetsHistoryScreenState extends State if (index == 0) { // Add your item here return Padding( - padding: EdgeInsets.only(right: 30, top: 10), + padding: const EdgeInsets.only(right: 30, top: 10), child: Text( widget.model.petAmountRegister == '0' ? FFLocalizations.of(context).getVariableText( @@ -232,21 +234,21 @@ class _PetsHistoryScreenState extends State if (uItem['gender'] == "MAC") { FFLocalizations.of(context).getVariableText( - ptText: 'Macho', enText: 'Male'): Color(0xFF094CB0), + ptText: 'Macho', enText: 'Male'): const Color(0xFF094CB0), }, if (uItem['gender'] == "FEM") { FFLocalizations.of(context).getVariableText( ptText: 'Femêa', enText: 'Female', - ): Color(0xFFE463E7), + ): const Color(0xFFE463E7), } ], onTapCardItemAction: () async { - final cliUUID = SQLiteStorageHelper().cliUUID; - final cliName = SQLiteStorageHelper().cliName; - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = StorageUtil().cliUUID; + final cliName = StorageUtil().cliName; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; await showDialog( useSafeArea: true, context: context, diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index c024e854..70885f03 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -16,6 +16,7 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/image_util.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; class PetsPageModel extends FlutterFlowModel { @@ -102,10 +103,10 @@ class PetsPageModel extends FlutterFlowModel { String? Function(BuildContext, String?)? textControllerObservationValidator; Future initAsync() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; - petAmountRegister = SQLiteStorageHelper().petAmountRegister.toString(); + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; + petAmountRegister = StorageUtil().petAmountRegister.toString(); safeSetState?.call(); } @@ -266,7 +267,7 @@ class PetsPageModel extends FlutterFlowModel { var img = await ImageUtils.convertImageFileToBase64(uploadedLocalFile!); img = "base64;jpeg,$img"; final url = - 'https://freaccess.com.br/freaccess/getImage.php?devUUID=${devUUID}&userUUID=${userUUID}&cliID=${cliUUID}&atividade=consultaFotoPet&petId=$petId'; + 'https://freaccess.com.br/freaccess/getImage.php?devUUID=$devUUID&userUUID=$userUUID&cliID=$cliUUID&atividade=consultaFotoPet&petId=$petId'; final response = await PhpGroup.updatePet.call( petID: petId, image: imgBase64, @@ -547,15 +548,15 @@ class PetsPageModel extends FlutterFlowModel { item['notes'] ?? '', }), imagePath: - 'https://freaccess.com.br/freaccess/getImage.php?devUUID=${devUUID}&userUUID=${userUUID}&cliID=${cliUUID}&atividade=consultaFotoPet&petId=${item['id'] ?? ''}', + 'https://freaccess.com.br/freaccess/getImage.php?devUUID=$devUUID&userUUID=$userUUID&cliID=$cliUUID&atividade=consultaFotoPet&petId=${item['id'] ?? ''}', statusHashMap: [ if (item['gender'] == "MAC") Map.from({ - item['name']: Color(0xFF094CB0), + item['name']: const Color(0xFF094CB0), }), if (item['gender'] == "FEM") Map.from({ - item['name']: Color(0xFFE463E7), + item['name']: const Color(0xFFE463E7), }), ], ); diff --git a/lib/pages/pets_page/pets_page_widget.dart b/lib/pages/pets_page/pets_page_widget.dart index c12af2fe..48834d3a 100644 --- a/lib/pages/pets_page/pets_page_widget.dart +++ b/lib/pages/pets_page/pets_page_widget.dart @@ -1,18 +1,12 @@ import 'dart:convert'; -import 'dart:developer'; -import 'package:easy_debounce/easy_debounce.dart'; import 'package:flutter/material.dart'; -import 'package:crypto/crypto.dart' as crypto; -import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:http/http.dart'; -import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/appbar.dart'; -import 'package:hub/components/atomic_components/shared_components_atoms/custom_datepicker.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/custom_input.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/custom_select.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/media_upload_button.dart'; @@ -21,19 +15,14 @@ import 'package:hub/components/atomic_components/shared_components_atoms/tabview import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/form_field_controller.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/flutter_flow/upload_data.dart'; import 'package:hub/pages/pets_page/pets_history_screen.dart'; import 'package:hub/pages/pets_page/pets_page_model.dart'; -import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/image_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; import 'package:material_symbols_icons/symbols.dart'; -import 'package:sqflite/sqflite.dart'; class PetsPageWidget extends StatefulWidget { dynamic pet; diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 443c28b0..5f0254aa 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -4,13 +4,11 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/storage_util.dart'; import 'package:share_plus/share_plus.dart'; -import 'package:sqflite/sqflite.dart'; class PreferencesPageModel with ChangeNotifier { final unfocusNode = FocusNode(); @@ -25,7 +23,7 @@ class PreferencesPageModel with ChangeNotifier { } Future enablePerson(BuildContext context) async { - final String userDevUUID = SQLiteStorageHelper().userDevUUID; + final String userDevUUID = StorageUtil().userDevUUID; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( @@ -70,7 +68,7 @@ class PreferencesPageModel with ChangeNotifier { Future toggleAccess(BuildContext context) async { onChange(String key) async { - SecureStorageHelper().accessPass = key; + StorageUtil().accessPass = key; await PhpGroup.changePass .call( newSenha: key, @@ -106,10 +104,10 @@ class PreferencesPageModel with ChangeNotifier { Future togglePanic(BuildContext context) async { onChange(String key) async { - SecureStorageHelper().panicPass = key; + StorageUtil().panicPass = key; await PhpGroup.changePanic .call( - newSenhaPanico: SecureStorageHelper().panicPass, + newSenhaPanico: StorageUtil().panicPass, ) .then((value) async { final String content; @@ -147,7 +145,7 @@ class PreferencesPageModel with ChangeNotifier { ); onChange(String? key) async { - if (!fingerprint) SecureStorageHelper().fingerprintPass = key ?? ''; + if (!fingerprint) StorageUtil().fingerprintPass = key ?? ''; if (fingerprint) SecureStorageHelper().delete('fingerprintPass'); fingerprint = await _toggleBoolInDb('fingerprint'); @@ -178,7 +176,7 @@ class PreferencesPageModel with ChangeNotifier { ptText: 'Conta deletada com sucesso', ); - StorageManager.purge(); + StorageUtil.purge(); context.pop(); context.go( @@ -224,7 +222,7 @@ class PreferencesPageModel with ChangeNotifier { ptText: 'Tem certeza que deseja sair?', ); onConfirm() async { - StorageManager.purge(); + StorageUtil.purge(); context.go( '/welcomePage', @@ -260,9 +258,9 @@ class PreferencesPageModel with ChangeNotifier { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) { if (value.jsonBody['error'] == false) { - SQLiteStorageHelper().cliName = ''; - SQLiteStorageHelper().cliUUID = ''; - SQLiteStorageHelper().ownerUUID = ''; + StorageUtil().cliName = ''; + StorageUtil().cliUUID = ''; + StorageUtil().ownerUUID = ''; context.pop(); diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index e58d1dd8..ebd23d55 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -11,7 +11,7 @@ import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; class PreferencesPageWidget extends StatefulWidget { - PreferencesPageWidget(); + const PreferencesPageWidget({super.key}); @override _PreferencesPageWidgetState createState() => _PreferencesPageWidgetState(); @@ -210,7 +210,7 @@ class _PreferencesPageWidgetState extends State { : FlutterFlowTheme.of(context).primary, ), ), - SizedBox(width: 8.0), + const SizedBox(width: 8.0), Expanded( child: Text( content, @@ -239,7 +239,7 @@ class _PreferencesPageWidgetState extends State { enText: 'Are you sure you want to logout?', ptText: 'Tem certeza', ), () async { - StorageManager.purge(); + StorageUtil.purge(); // setState(() {}); context.go( diff --git a/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart b/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart index d7a11ba3..022822ed 100644 --- a/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart +++ b/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart @@ -1,11 +1,9 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:provider/provider.dart'; import '/flutter_flow/flutter_flow_util.dart'; diff --git a/lib/pages/qr_code_page/qr_code_page_model.dart b/lib/pages/qr_code_page/qr_code_page_model.dart index eca74dac..8edbff92 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/qr_code_page/qr_code_page_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:qr_flutter/qr_flutter.dart'; class QrCodePageModel extends FlutterFlowModel { @@ -11,7 +12,7 @@ class QrCodePageModel extends FlutterFlowModel { bool isAccess = false; - String? key = null; + String? key; DateTime? time; late final bool isFingerprint; @@ -27,8 +28,8 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = SQLiteStorageHelper().fingerprint; - userDevUUID = SQLiteStorageHelper().userDevUUID; + isFingerprint = StorageUtil().fingerprint; + userDevUUID = StorageUtil().userDevUUID; } @override diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index 7b98bf8f..f5ac5a24 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -18,6 +18,7 @@ import 'package:hub/pages/qr_code_page/qr_code_page_model.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/biometric_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:percent_indicator/circular_percent_indicator.dart'; // import 'package:percent_indicator/percent_indicator.dart'; @@ -307,11 +308,11 @@ class _QrCodePageWidgetState extends State builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return CircularProgressIndicator(); + return const CircularProgressIndicator(); } else if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else if (!snapshot.hasData) { - return Text('No data'); + return const Text('No data'); } else { final progress = snapshot.data!; return CircularPercentIndicator( @@ -372,7 +373,7 @@ class _QrCodePageWidgetState extends State .reverse(); } _model.isAccess = !_model.isAccess; - _model.key = SecureStorageHelper().fingerprintPass; + _model.key = StorageUtil().fingerprintPass; }); })) .onError((error, StackTrace) { diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index a1c9f048..8104f8b2 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -2,17 +2,18 @@ import 'package:flutter/material.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final String userDevUUID = SQLiteStorageHelper().userDevUUID; + final String userDevUUID = StorageUtil().userDevUUID; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( - ptText: 'Este é o meu identificador de acesso: ${userDevUUID}', - enText: 'This is my access identifier: ${userDevUUID}', + ptText: 'Este é o meu identificador de acesso: $userDevUUID', + enText: 'This is my access identifier: $userDevUUID', ), ); } diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 62132754..75be8092 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -9,7 +9,6 @@ import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/reception_page/reception_page_model.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; -import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; @@ -29,7 +28,7 @@ class _ReceptionPageWidgetState extends State { @override Widget build(BuildContext context) { - SecureStorageHelper().context = context; + StorageUtil().context = context; return ChangeNotifierProvider( create: (context) => ReceptionPageModel(), child: Scaffold( @@ -155,7 +154,7 @@ class _ReceptionPageWidgetState extends State { onPressed: () async { PhpGroup.unregisterDevice(); - StorageManager.purge(); + StorageUtil.purge(); setState(() {}); context.go( diff --git a/lib/pages/register_visitor_page/register_visitor_page_model.dart b/lib/pages/register_visitor_page/register_visitor_page_model.dart index 85e15627..9c813fc5 100644 --- a/lib/pages/register_visitor_page/register_visitor_page_model.dart +++ b/lib/pages/register_visitor_page/register_visitor_page_model.dart @@ -1,8 +1,6 @@ import 'package:hub/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart'; -import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; -import '/flutter_flow/form_field_controller.dart'; import 'register_visitor_page_widget.dart' show RegisterVisitorPageWidget; import 'package:flutter/material.dart'; diff --git a/lib/pages/register_visitor_page/register_visitor_page_widget.dart b/lib/pages/register_visitor_page/register_visitor_page_widget.dart index e7a84c33..483364bf 100644 --- a/lib/pages/register_visitor_page/register_visitor_page_widget.dart +++ b/lib/pages/register_visitor_page/register_visitor_page_widget.dart @@ -4,7 +4,6 @@ import 'package:hub/components/templates_components/regisiter_vistor_template_co import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:provider/provider.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'register_visitor_page_model.dart'; diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index 6d47a096..b03f072e 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -8,12 +8,15 @@ import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:sqflite/sqflite.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:webview_flutter/webview_flutter.dart'; class ReservationPageWidget extends StatefulWidget { + const ReservationPageWidget({super.key}); + @override _ReservationPageWidgetState createState() => _ReservationPageWidgetState(); } @@ -23,21 +26,16 @@ class _ReservationPageWidgetState extends State { late WebViewController _controllerAll; Future> initVariables() async { - final email = SecureStorageHelper().email; - final name = SQLiteStorageHelper().cliName; - final userUUID = SQLiteStorageHelper().userUUID; - final devUUID = SQLiteStorageHelper().devUUID; - final createdAt = SQLiteStorageHelper().createdAt; - final clientId = SQLiteStorageHelper().cliUUID; + final email = StorageUtil().email; + final name = StorageUtil().cliName; + final userUUID = StorageUtil().userUUID; + final devUUID = StorageUtil().devUUID; + final createdAt = StorageUtil().createdAt; + final clientId = StorageUtil().cliUUID; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; - final freUserData = "{\"name\": \"$name\", " + - "\"email\": \"$email\"," + - "\"dev_id\": \"$devUUID\"," + - "\"created_at\": \"0000-00-00 00:00:00\"," + - "\"updated_at\": \"0000-00-00 00:00:00\"," + - "\"status\": \"A\" }"; + final freUserData = "{\"name\": \"$name\", \"email\": \"$email\",\"dev_id\": \"$devUUID\",\"created_at\": \"0000-00-00 00:00:00\",\"updated_at\": \"0000-00-00 00:00:00\",\"status\": \"A\" }"; return { 'url': url, @@ -59,7 +57,7 @@ class _ReservationPageWidgetState extends State { future: initVariables(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return Center(child: CircularProgressIndicator()); + return const Center(child: CircularProgressIndicator()); } else if (snapshot.hasError || snapshot.hasData == false || snapshot.data!.isEmpty) { @@ -151,7 +149,7 @@ class _ReservationPageWidgetState extends State { ..loadRequest(Uri.parse(url)), ); } else { - return Center(child: Text('Unexpected error')); + return const Center(child: Text('Unexpected error')); } }, ), 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 3c0aafd5..4467764d 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 @@ -15,6 +15,7 @@ import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_p import 'package:hub/pages/schedule_complete_visit_page/visit_history_page_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/mixins/status_mixin.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; import 'package:intl/intl.dart'; import 'package:share_plus/share_plus.dart'; @@ -181,9 +182,9 @@ class ScheduleCompleteVisitPageModel } Future _initVariables() async { - devUUID = SQLiteStorageHelper().devUUID; - cliUUID = SQLiteStorageHelper().cliUUID; - userUUID = SQLiteStorageHelper().userUUID; + devUUID = StorageUtil().devUUID; + cliUUID = StorageUtil().cliUUID; + userUUID = StorageUtil().userUUID; } @override @@ -409,7 +410,7 @@ class ScheduleCompleteVisitPageModel enText: 'Are you sure you want to block this visit?', ), () async { await changeStatusAction - ?.call( + .call( context, int.parse(item['VAW_DESTINO']), int.parse(item['VAW_ID']), @@ -511,13 +512,13 @@ class ScheduleCompleteVisitPageModel icon: const Icon(Icons.share), onPressed: () async { Share.share(''' -Olá, \*${item['VTE_NOME']}\*! Você foi convidado para \*${cliName}\*. +Olá, \*${item['VTE_NOME']}\*! Você foi convidado para \*$cliName\*. \*Validade do Convite\*: - Início: ${item['VAW_DTINICIO']} - Fim: ${item['VAW_DTFIM']} -URL do Convite: https://visita.freaccess.com.br/${item['VAW_ID']}/${cliUUID}/${item['VAW_CHAVE']} +URL do Convite: https://visita.freaccess.com.br/${item['VAW_ID']}/$cliUUID/${item['VAW_CHAVE']} '''); }, options: FFButtonOptions( @@ -551,7 +552,7 @@ URL do Convite: https://visita.freaccess.com.br/${item['VAW_ID']}/${cliUUID}/${i : '', }), imagePath: - 'https://freaccess.com.br/freaccess/getImage.php?cliID=${cliUUID}&atividade=getFoto&Documento=${item['VTE_DOCUMENTO'] ?? ''}&tipo=E', + 'https://freaccess.com.br/freaccess/getImage.php?cliID=$cliUUID&atividade=getFoto&Documento=${item['VTE_DOCUMENTO'] ?? ''}&tipo=E', statusHashMap: [ if (Status.getStatus(item['VAW_STATUS']) == StatusEnum.active) Map.from({ diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart index 65d624ba..2579e86c 100644 --- a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart @@ -26,7 +26,7 @@ import 'package:hub/shared/utils/share_util.dart'; import 'package:provider/provider.dart'; class ScheduleComplete extends StatefulWidget { - const ScheduleComplete({Key? key}) : super(key: key); + const ScheduleComplete({super.key}); @override State createState() { @@ -35,7 +35,7 @@ class ScheduleComplete extends StatefulWidget { } class ScheduleCompleteVisitPageWidget extends ScheduleComplete { - const ScheduleCompleteVisitPageWidget(); + const ScheduleCompleteVisitPageWidget({super.key}); @override State createState() => @@ -48,8 +48,8 @@ class _ScheduleCompleteVisitPageWidgetState late ScheduleCompleteVisitPageModel _model; int _visitHistoryLoadingIdx = 0; final int _visitHistoryLoadingCount = 10; - List _visitHistoryList = []; - ScrollController _visitHistoryController = ScrollController(); + final List _visitHistoryList = []; + final ScrollController _visitHistoryController = ScrollController(); final scaffoldKey = GlobalKey(); @@ -162,7 +162,7 @@ PreferredSizeWidget appBarScheduleCompleteVisit(BuildContext context) { } Widget bodyScheduleCompleteVisit(BuildContext context, - ScheduleCompleteVisitPageModel _model, Function safeSetState) { + ScheduleCompleteVisitPageModel model, Function safeSetState) { return SafeArea( top: true, child: Column( @@ -194,7 +194,7 @@ Widget bodyScheduleCompleteVisit(BuildContext context, ), ), ], - controller: _model.tabBarController, + controller: model.tabBarController, onTap: (i) async { [() async {}, () async {}][i](); }, @@ -202,12 +202,12 @@ Widget bodyScheduleCompleteVisit(BuildContext context, ), Expanded( child: TabBarView( - controller: _model.tabBarController, + controller: model.tabBarController, children: [ - scheduleVisit(context, _model, safeSetState), + scheduleVisit(context, model, safeSetState), wrapWithModel( - model: _model, - child: VisitHistoryWidget(), + model: model, + child: const VisitHistoryWidget(), updateCallback: () { safeSetState(() {}); }, @@ -221,7 +221,7 @@ Widget bodyScheduleCompleteVisit(BuildContext context, } Widget scheduleVisit(BuildContext context, - ScheduleCompleteVisitPageModel _model, Function safeSetState) { + ScheduleCompleteVisitPageModel model, Function safeSetState) { return SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.max, @@ -266,9 +266,9 @@ Widget scheduleVisit(BuildContext context, padding: const EdgeInsetsDirectional.fromSTEB( 24.0, 0.0, 24.0, 0.0), child: TextFormField( - controller: _model.textController1, + controller: model.textController1, readOnly: true, - focusNode: _model.textFieldFocusNode1, + focusNode: model.textFieldFocusNode1, autovalidateMode: AutovalidateMode.onUserInteraction, autofocus: false, @@ -353,7 +353,7 @@ Widget scheduleVisit(BuildContext context, lineHeight: 1.8, ), textAlign: TextAlign.start, - validator: _model.textController1Validator + validator: model.textController1Validator .asValidator(context)), ), Padding( @@ -468,7 +468,7 @@ Widget scheduleVisit(BuildContext context, if (datePicked1Date != null && datePicked1Time != null) { safeSetState(() { - _model.datePicked1 = DateTime( + model.datePicked1 = DateTime( datePicked1Date.year, datePicked1Date.month, datePicked1Date.day, @@ -478,15 +478,15 @@ Widget scheduleVisit(BuildContext context, }); } safeSetState(() { - _model.textController1?.text = dateTimeFormat( + model.textController1?.text = dateTimeFormat( 'dd/MM/yyyy HH:mm:ss', - _model.datePicked1, + model.datePicked1, locale: FFLocalizations.of(context) .languageCode, ); - _model.textController1?.selection = + model.textController1?.selection = TextSelection.collapsed( - offset: _model + offset: model .textController1!.text.length); }); }, @@ -517,8 +517,8 @@ Widget scheduleVisit(BuildContext context, 24.0, 0.0, 24.0, 0.0), child: TextFormField( readOnly: true, - controller: _model.textController2, - focusNode: _model.textFieldFocusNode2, + controller: model.textController2, + focusNode: model.textFieldFocusNode2, autovalidateMode: AutovalidateMode.onUserInteraction, autofocus: false, @@ -601,7 +601,7 @@ Widget scheduleVisit(BuildContext context, lineHeight: 1.8, ), textAlign: TextAlign.start, - validator: _model.textController2Validator + validator: model.textController2Validator .asValidator(context), ), ), @@ -717,7 +717,7 @@ Widget scheduleVisit(BuildContext context, if (datePicked2Date != null && datePicked2Time != null) { safeSetState(() { - _model.datePicked2 = DateTime( + model.datePicked2 = DateTime( datePicked2Date.year, datePicked2Date.month, datePicked2Date.day, @@ -727,15 +727,15 @@ Widget scheduleVisit(BuildContext context, }); } safeSetState(() { - _model.textController2?.text = dateTimeFormat( + model.textController2?.text = dateTimeFormat( 'dd/MM/yyyy HH:mm:ss', - _model.datePicked2, + model.datePicked2, locale: FFLocalizations.of(context) .languageCode, ); - _model.textController2?.selection = + model.textController2?.selection = TextSelection.collapsed( - offset: _model + offset: model .textController2!.text.length); }); }, @@ -779,11 +779,11 @@ Widget scheduleVisit(BuildContext context, ), ), ), - if (_model.visitorJsonList.isNotEmpty) + if (model.visitorJsonList.isNotEmpty) Builder( builder: (context) { final visitorListView = - _model.visitorJsonList.map((e) => e).toList(); + model.visitorJsonList.map((e) => e).toList(); return ListView.separated( padding: const EdgeInsets.fromLTRB( 0, @@ -826,7 +826,7 @@ Widget scheduleVisit(BuildContext context, fadeOutDuration: const Duration(milliseconds: 500), imageUrl: - "https://freaccess.com.br/freaccess/getImage.php?devUUID=${_model.devUUID}&userUUID=${_model.userUUID}&cliID=${_model.cliUUID}&atividade=getFoto&Documento=${getJsonField(visitorListViewItem, r'''$.VTE_DOCUMENTO''').toString()}&tipo=E", + "https://freaccess.com.br/freaccess/getImage.php?devUUID=${model.devUUID}&userUUID=${model.userUUID}&cliID=${model.cliUUID}&atividade=getFoto&Documento=${getJsonField(visitorListViewItem, r'''$.VTE_DOCUMENTO''').toString()}&tipo=E", fit: BoxFit.cover, ), ), @@ -858,7 +858,7 @@ Widget scheduleVisit(BuildContext context, ), IconButton( onPressed: () async { - _model.removeFromVisitorJsonList( + model.removeFromVisitorJsonList( visitorListViewItem); safeSetState(() {}); }, @@ -890,10 +890,10 @@ Widget scheduleVisit(BuildContext context, context: context, builder: (context) { return GestureDetector( - onTap: () => _model + onTap: () => model .unfocusNode.canRequestFocus ? FocusScope.of(context) - .requestFocus(_model.unfocusNode) + .requestFocus(model.unfocusNode) : FocusScope.of(context).unfocus(), child: SizedBox( height: @@ -906,14 +906,14 @@ Widget scheduleVisit(BuildContext context, child: VisitorSearchModalTemplateComponentWidget( getVisitors: (visitorsParam) async { - _model.visitorJsonList = + model.visitorJsonList = visitorsParam! .toList() .cast(); safeSetState(() {}); }, getDocs: (docsParam) async { - _model.visitorStrList = + model.visitorStrList = strListToStr( docsParam!.toList()); safeSetState(() {}); @@ -1063,17 +1063,17 @@ Widget scheduleVisit(BuildContext context, .reasonsMotDescStrList( snapshot.data!.jsonBody); - _model.processDropDown1(reasonsJsonList!); + model.processDropDown1(reasonsJsonList!); return FlutterFlowDropDown( fillColor: FlutterFlowTheme.of(context) .primaryBackground, controller: - _model.dropDownValueController1, - options: _model.reasonsDropDown1, + model.dropDownValueController1, + options: model.reasonsDropDown1, optionLabels: reasonsOptionLabels, onChanged: (val) => safeSetState( - () => _model.dropDownValue1 = val), + () => model.dropDownValue1 = val), width: double.infinity, height: double.infinity, textStyle: FlutterFlowTheme.of(context) @@ -1118,7 +1118,7 @@ Widget scheduleVisit(BuildContext context, ), ], ), - if (_model.dropDownValue1 == '') + if (model.dropDownValue1 == '') Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, @@ -1176,15 +1176,15 @@ Widget scheduleVisit(BuildContext context, .getDadosCall .levelNACDescricaoStrList( snapshot.data!.jsonBody); - _model.processDropDown2(lavelsJsonList!); + model.processDropDown2(lavelsJsonList!); return FlutterFlowDropDown( controller: - _model.dropDownValueController2, - options: _model.lavelsDropDown2, + model.dropDownValueController2, + options: model.lavelsDropDown2, optionLabels: lavelsOptionLabels, onChanged: (val) => safeSetState( - () => _model.dropDownValue2 = val), + () => model.dropDownValue2 = val), width: double.infinity, height: double.infinity, textStyle: FlutterFlowTheme.of(context) @@ -1231,7 +1231,7 @@ Widget scheduleVisit(BuildContext context, ), ], ), - if (_model.dropDownValue2 == '') + if (model.dropDownValue2 == '') Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, @@ -1312,9 +1312,9 @@ Widget scheduleVisit(BuildContext context, ), ), Switch( - value: _model.switchValue!, + value: model.switchValue!, onChanged: (newValue) async { - safeSetState(() => _model.switchValue = newValue); + safeSetState(() => model.switchValue = newValue); }, focusColor: FlutterFlowTheme.of(context).primary, trackColor: WidgetStateProperty.resolveWith( @@ -1389,8 +1389,8 @@ Widget scheduleVisit(BuildContext context, child: SizedBox( width: double.infinity, child: TextFormField( - controller: _model.textController3, - focusNode: _model.textFieldFocusNode3, + controller: model.textController3, + focusNode: model.textFieldFocusNode3, autofocus: false, cursorColor: FlutterFlowTheme.of(context).primary, textInputAction: TextInputAction.next, @@ -1470,7 +1470,7 @@ Widget scheduleVisit(BuildContext context, textAlign: TextAlign.start, maxLines: null, maxLength: 80, - validator: _model.textController3Validator + validator: model.textController3Validator .asValidator(context), ), ), @@ -1490,21 +1490,21 @@ Widget scheduleVisit(BuildContext context, enText: 'Schedule', ptText: 'Agendar', ), - onPressed: _model.isValid() + onPressed: model.isValid() ? () async { Future scheduleVisit() async { await PhpGroup.postScheduleVisitCall .call( - devDesc: _model.textController3.text, - idVisitante: _model.visitorStrList, - dtInicio: _model - .convertDateFormat(_model.textController1.text ?? ''), - dtFim: _model - .convertDateFormat(_model.textController2.text ?? ''), - unica: _model.switchValue == true ? 'Sim' : 'Não', - idMotivo: extractIdToStr(_model.dropDownValue1!), - idNAC: extractIdToStr(_model.dropDownValue2!), - obs: _model.textController3.text, + devDesc: model.textController3.text, + idVisitante: model.visitorStrList, + dtInicio: model + .convertDateFormat(model.textController1.text ?? ''), + dtFim: model + .convertDateFormat(model.textController2.text ?? ''), + unica: model.switchValue == true ? 'Sim' : 'Não', + idMotivo: extractIdToStr(model.dropDownValue1!), + idNAC: extractIdToStr(model.dropDownValue2!), + obs: model.textController3.text, ) .catchError((e) async { await DialogUtil.errorDefault(context); @@ -1515,14 +1515,14 @@ Widget scheduleVisit(BuildContext context, false) { context.pop(); - _model.dropDownValue1 = null; - _model.dropDownValue2 = null; - _model.dropDownValueController1 = + model.dropDownValue1 = null; + model.dropDownValue2 = null; + model.dropDownValueController1 = FormFieldController(''); - _model.dropDownValueController2 = + model.dropDownValueController2 = FormFieldController(''); - _model.visitorStrList = ''; - _model.visitorJsonList = []; + model.visitorStrList = ''; + model.visitorJsonList = []; ToastUtil.showToast( message: FFLocalizations.of(context) @@ -1543,16 +1543,16 @@ Widget scheduleVisit(BuildContext context, safeSetState(() {}); } - if (_model.visitorJsonList.length > 1) { + if (model.visitorJsonList.length > 1) { final title = FFLocalizations.of(context).getVariableText( ptText: 'Cadastrar Múltiplos Visitantes', enText: 'Register Multiple Visitors', ); final content = FFLocalizations.of(context).getVariableText( ptText: - 'Você deseja agendar uma visita para ${_model.visitorJsonList.length} visitantes?', + 'Você deseja agendar uma visita para ${model.visitorJsonList.length} visitantes?', enText: - 'Do you want to schedule a visit for ${_model.visitorJsonList.length} visitors?', + 'Do you want to schedule a visit for ${model.visitorJsonList.length} visitors?', ); showAlertDialog(context, title, content, scheduleVisit); @@ -1561,9 +1561,9 @@ Widget scheduleVisit(BuildContext context, context: context, builder: (context) { return GestureDetector( - onTap: () => _model.unfocusNode.canRequestFocus + onTap: () => model.unfocusNode.canRequestFocus ? FocusScope.of(context) - .requestFocus(_model.unfocusNode) + .requestFocus(model.unfocusNode) : FocusScope.of(context).unfocus(), child: Dialog( alignment: Alignment.topCenter, @@ -1597,28 +1597,28 @@ Widget scheduleVisit(BuildContext context, ), ], imagePath: - 'https://freaccess.com.br/freaccess/getImage.php?cliID=${_model.cliUUID}&atividade=getFoto&Documento=${_model.visitorJsonList[0]['VTE_DOCUMENTO'] ?? ''}&tipo=E', + 'https://freaccess.com.br/freaccess/getImage.php?cliID=${model.cliUUID}&atividade=getFoto&Documento=${model.visitorJsonList[0]['VTE_DOCUMENTO'] ?? ''}&tipo=E', labelsHashMap: { - 'Nome': _model.visitorJsonList[0]['VTE_NOME'], - 'Start': _model.textController1.text, - 'End': _model.textController2.text ?? '', + 'Nome': model.visitorJsonList[0]['VTE_NOME'], + 'Start': model.textController1.text, + 'End': model.textController2.text ?? '', 'Reason': (RegExp(r'MOT_DESCRICAO:\s*([^,]+)') .firstMatch( - _model.dropDownValue1.toString()) + model.dropDownValue1.toString()) ?.group(1) .toString()) ?? '', 'Level': (RegExp(r'NAC_DESCRICAO:\s*([^,]+)') .firstMatch( - _model.dropDownValue2.toString()) + model.dropDownValue2.toString()) ?.group(1) .toString()) ?? '', - 'Single Visit': _model.switchValue == true + 'Single Visit': model.switchValue == true ? 'Sim' : 'Não', - if (_model.textController3.text.isNotEmpty) - 'Observation': _model.textController3.text, + if (model.textController3.text.isNotEmpty) + 'Observation': model.textController3.text, }, statusHashMap: [ Map.from({ diff --git a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart index d07f5759..c90bd2f3 100644 --- a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart @@ -9,10 +9,11 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/mixins/status_mixin.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; class VisitHistoryWidget extends ScheduleComplete { - const VisitHistoryWidget(); + const VisitHistoryWidget({super.key}); @override _VisitHistoryWidgetState createState() => _VisitHistoryWidgetState(); @@ -34,9 +35,9 @@ class _VisitHistoryWidgetState extends State List _visitWrap = []; Future _initVariables() async { - devUUID = SQLiteStorageHelper().devUUID; - userUUID = SQLiteStorageHelper().userUUID; - cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = StorageUtil().devUUID; + userUUID = StorageUtil().userUUID; + cliUUID = StorageUtil().cliUUID; } @override @@ -75,7 +76,7 @@ class _VisitHistoryWidgetState extends State final List visits = response.jsonBody['visitas'] ?? []; - if (visits != null && visits.isNotEmpty) { + if (visits.isNotEmpty) { setState(() { _visitWrap.addAll(visits); _hasData = true; @@ -102,6 +103,7 @@ class _VisitHistoryWidgetState extends State _loading = false; }); } + return null; } void _loadMore() { @@ -245,10 +247,10 @@ class _VisitHistoryWidgetState extends State }, ], onTapCardItemAction: () async { - final cliUUID = SQLiteStorageHelper().cliUUID; - final cliName = SQLiteStorageHelper().cliName; - final devUUID = SQLiteStorageHelper().devUUID; - final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = StorageUtil().cliUUID; + final cliName = StorageUtil().cliName; + final devUUID = StorageUtil().devUUID; + final userUUID = StorageUtil().userUUID; await showDialog( useSafeArea: true, diff --git a/lib/pages/welcome_page/welcome_page_widget.dart b/lib/pages/welcome_page/welcome_page_widget.dart index 63bf188c..8a4be699 100644 --- a/lib/pages/welcome_page/welcome_page_widget.dart +++ b/lib/pages/welcome_page/welcome_page_widget.dart @@ -1,12 +1,12 @@ import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/mixins/switcher_mixin.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import '/components/templates_components/welcome_template_component/welcome_template_component_widget.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import 'package:provider/provider.dart'; import 'welcome_page_model.dart'; export 'welcome_page_model.dart'; @@ -30,13 +30,13 @@ class _WelcomePageWidgetState extends State { // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { if (isAndroid == true) { - SecureStorageHelper().deviceType = 'Android'; + StorageUtil().deviceType = 'Android'; setState(() {}); } else if (isiOS == true) { - SecureStorageHelper().deviceType = 'iOS'; + StorageUtil().deviceType = 'iOS'; setState(() {}); } else { - SecureStorageHelper().deviceType = 'Web'; + StorageUtil().deviceType = 'Web'; setState(() {}); } }); diff --git a/lib/shared/helpers/secure_storage_helper.dart b/lib/shared/helpers/secure_storage_helper.dart index 106964dc..5a996810 100644 --- a/lib/shared/helpers/secure_storage_helper.dart +++ b/lib/shared/helpers/secure_storage_helper.dart @@ -1,15 +1,12 @@ -import 'dart:convert'; import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/cache_util.dart'; -import 'package:synchronized/synchronized.dart'; class SecureStorageHelper extends ChangeNotifier implements Storage { static final SecureStorageHelper _instance = SecureStorageHelper._internal(); final FlutterSecureStorage _secureStorage = const FlutterSecureStorage(); - static final _lock = Lock(); factory SecureStorageHelper() => _instance; @@ -17,166 +14,81 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { static SecureStorageHelper get instance => _instance; - String? _deviceDescription; - String get deviceDescription => _deviceDescription ?? ''; - set deviceDescription(String value) => _setAndCacheString('deviceDescription', value, (v) => _deviceDescription = v); - BuildContext? _context; - BuildContext? get context => _context; - set context(BuildContext? value) => _setAndCacheObject('ff_context', value.toString(), (v) => _context = value); + - bool? _haveLocal; - bool? get haveLocal => _haveLocal; - set haveLocal(bool? value) => _setAndCacheBool('ff_have_local', value ?? false, (v) => _haveLocal = value); - - String? _fingerprintPass; - String get fingerprintPass => _fingerprintPass ?? ''; - set fingerprintPass(String value) => _setAndCacheString('fingerprintPass', value, (v) => _fingerprintPass = v); - - String? _accessPass; - String get accessPass => _accessPass ?? ''; - set accessPass(String value) => _setAndCacheString('accessPass', value, (v) => _accessPass = v); - - String? _panicPass; - String get panicPass => _panicPass ?? ''; - set panicPass(String value) => _setAndCacheString('panicPass', value, (v) => _panicPass = v); - - String? _tokenAPNS; - String? get tokenAPNS => _tokenAPNS; - set tokenAPNS(String? value) => _setAndCacheString('ff_tokenAPNS', value ?? '', (v) => _tokenAPNS = v); - - String? _email; - String get email => _email ?? ''; - set email(String value) => _setAndCacheString('ff_email', value, (v) => _email = v); - - String? _passwd; - String get passwd => _passwd ?? ''; - set passwd(String value) => _setAndCacheString('ff_passwd', value, (v) => _passwd = v); - - String? _deviceType; - String get deviceType => _deviceType ?? ''; - set deviceType(String value) => _setAndCacheString('ff_deviceType', value, (v) => _deviceType = v); - - bool? _isLogged; - bool get isLogged => _isLogged ?? false; - set isLogged(bool value) => _setAndCacheBool('ff_isLogged', value, (v) => _isLogged = v); - - String? _token; - String get token => _token ?? ''; - set token(String value) => _setAndCacheString('ff_token', value, (v) => _token = v); - - Future ensureInitialization() async { - log('SecureStorageHelper: Starting initialization'); - await _lock.synchronized(() async { - try { - log('SecureStorageHelper: Calling initFunction'); - _email = await _getString('ff_email'); - log('SecureStorageHelper: _email = $_email'); - _passwd = await _getString('ff_passwd'); - log('SecureStorageHelper: _passwd = $_passwd'); - _deviceType = await _getString('ff_deviceType'); - log('SecureStorageHelper: _deviceType = $_deviceType'); - _isLogged = await _getBool('ff_isLogged'); - log('SecureStorageHelper: _isLogged = $_isLogged'); - _tokenAPNS = await _getString('ff_tokenAPNS'); - log('SecureStorageHelper: _tokenAPNS = $_tokenAPNS'); - _accessPass = await _getString('accessPass'); - log('SecureStorageHelper: _accessPass = $_accessPass'); - _panicPass = await _getString('panicPass'); - log('SecureStorageHelper: _panicPass = $_panicPass'); - _fingerprintPass = await _getString('fingerprintPass'); - log('SecureStorageHelper: _fingerprintPass = $_fingerprintPass'); - _context = await _getObject('ff_context'); - log('SecureStorageHelper: _context = $_context'); - _haveLocal = await _getBool('ff_have_local'); - log('SecureStorageHelper: _haveLocal = $_haveLocal'); - _deviceDescription = await _getString('deviceDescription'); - log('SecureStorageHelper: _deviceDescription = $_deviceDescription'); - log('SecureStorageHelper: initFunction completed successfully'); - } catch (e) { - log('SecureStorageHelper: Error during initialization: $e'); - } - }); - log('SecureStorageHelper: Initialization complete'); + Future setAndCacheString(String key, String value, Function(String) cacheSetter) async { + log('setAndCacheString value for key: $key to $value'); + await _secureStorage.write(key: key, value: value); + CacheUtil.instance.set(key, value); + cacheSetter(value); } - Future _setAndCacheString(String key, String value, Function(String) cacheSetter) async { - await _lock.synchronized(() async { - await _secureStorage.write(key: key, value: value); + Future setAndCacheBool(String key, bool value, Function(bool) cacheSetter) async { + log('setAndCacheBool value for key: $key to $value'); + await _secureStorage.write(key: key, value: value.toString()); + CacheUtil.instance.set(key, value); + cacheSetter(value); + } + + Future setAndCacheObject(String key, String value, Function(String) cacheSetter) async { + log('setAndCacheObject value for key: $key to $value'); + await _secureStorage.write(key: key, value: value); + CacheUtil.instance.set(key, value); + cacheSetter(value); + } + + Future getString(String key) async { + log('getString value for key: $key'); + var value = CacheUtil.instance.get(key); + if (value == null) { + value = await _secureStorage.read(key: key); CacheUtil.instance.set(key, value); - cacheSetter(value); - }); + } + return value; } - Future _setAndCacheBool(String key, bool value, Function(bool) cacheSetter) async { - await _lock.synchronized(() async { - await _secureStorage.write(key: key, value: value.toString()); + Future getBool(String key) async { + log('getBool value for key: $key'); + var value = CacheUtil.instance.get(key); + if (value == null) { + value = await _secureStorage.read(key: key); + CacheUtil.instance.set(key, value == 'true'); + } + return value == 'true'; + } + + Future getObject(String key) async { + log('getObject value for key: $key'); + var value = CacheUtil.instance.get(key); + if (value == null) { + value = await _secureStorage.read(key: key); CacheUtil.instance.set(key, value); - cacheSetter(value); - }); - } - - Future _setAndCacheObject(String key, String value, Function(String) cacheSetter) async { - await _lock.synchronized(() async { - await _secureStorage.write(key: key, value: value); - CacheUtil.instance.set(key, value); - cacheSetter(value); - }); - } - - Future _getString(String key) async { - return await _lock.synchronized(() async { - var value = CacheUtil.instance.get(key); - if (value == null) { - value = await _secureStorage.read(key: key); - CacheUtil.instance.set(key, value); - } - return value; - }); - } - - Future _getBool(String key) async { - return await _lock.synchronized(() async { - var value = CacheUtil.instance.get(key); - if (value == null) { - value = await _secureStorage.read(key: key); - CacheUtil.instance.set(key, value == 'true'); - } - return value == 'true'; - }); - } - - Future _getObject(String key) async { - return await _lock.synchronized(() async { - var value = CacheUtil.instance.get(key); - if (value == null) { - value = await _secureStorage.read(key: key); - CacheUtil.instance.set(key, value); - } - return value as BuildContext?; - }); + } + return value as BuildContext?; } @override - Future set(String key, dynamic value) async { + Future set(String key, dynamic value, Function(dynamic) cacheSetter) async { if (value is String) { - await _setAndCacheString(key, value, (v) {}); + await setAndCacheString(key, value, cacheSetter); } else if (value is bool) { - await _setAndCacheBool(key, value, (v) {}); + await setAndCacheBool(key, value, cacheSetter); } else if (value is BuildContext) { - await _setAndCacheObject(key, value.toString(), (v) {}); + await setAndCacheObject(key, value.toString(), cacheSetter); } } @override Future get(String key) async { - var stringValue = await _getString(key); + log('get value for key: $key'); + var stringValue = await getString(key); if (stringValue != null) return stringValue; - var boolValue = await _getBool(key); + var boolValue = await getBool(key); if (boolValue != null) return boolValue; - var objectValue = await _getObject(key); + var objectValue = await getObject(key); if (objectValue != null) return objectValue; return null; @@ -184,16 +96,16 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { @override Future delete(String key) async { - await _lock.synchronized(() async { - await _secureStorage.delete(key: key); - CacheUtil.instance.delete(key); - }); + log('delete value for key: $key'); + await _secureStorage.delete(key: key); + CacheUtil.instance.delete(key); } Future purge() async { - await _lock.synchronized(() async { - await _secureStorage.deleteAll(); - CacheUtil.instance.clear(); - }); + log('purge values'); + await _secureStorage.deleteAll(); + CacheUtil.instance.clear(); } + + } \ No newline at end of file diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart index 0fdc632b..422b8675 100644 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -1,12 +1,14 @@ +import 'dart:developer'; + import 'package:hub/shared/utils/storage_util.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:hub/shared/utils/cache_util.dart'; -import 'package:synchronized/synchronized.dart'; class SharedPreferencesStorageHelper implements Storage { static final SharedPreferencesStorageHelper _instance = SharedPreferencesStorageHelper._internal(); - static final _lock = Lock(); SharedPreferences? _prefs; + SharedPreferences? get prefs => _prefs; + set prefs(SharedPreferences? value) => _prefs = value; factory SharedPreferencesStorageHelper() => _instance; @@ -18,86 +20,80 @@ class SharedPreferencesStorageHelper implements Storage { bool get isFirstRun => _isFirstRun; set isFirstRun(bool value) => _setAndCacheBool('first_run', value, (v) => _isFirstRun = v); - Future ensureInitialization() async { - await _lock.synchronized(() async { - if (_prefs == null) { - _prefs = await SharedPreferences.getInstance(); - _isFirstRun = _prefs?.getBool('first_run') ?? true; - } - }); - } + Future _setAndCache(String key, T value, Function(T) cacheSetter, Future Function(String, T) setFunc) async { - await _lock.synchronized(() async { - await setFunc(key, value); - CacheUtil.instance.set(key, value); - cacheSetter(value); - }); + 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 { + 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 { + 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 { + 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 { + 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 { + log('setAndCacheStringList value for key: $key to $value'); await _setAndCache(key, value, cacheSetter, _prefs!.setStringList); } @override - Future set(String key, dynamic value) async { - await _lock.synchronized(() async { - if (value is bool) { - await _prefs?.setBool(key, value); - } else if (value is String) { - await _prefs?.setString(key, value); - } else if (value is int) { - await _prefs?.setInt(key, value); - } else if (value is double) { - await _prefs?.setDouble(key, value); - } else if (value is List) { - await _prefs?.setStringList(key, value); - } - CacheUtil.instance.set(key, value); - }); + Future set(String key, dynamic value, Function(dynamic) cacheSetter) async { + + if (value is bool) { + await _prefs?.setBool(key, value); + } else if (value is String) { + await _prefs?.setString(key, value); + } else if (value is int) { + await _prefs?.setInt(key, value); + } else if (value is double) { + await _prefs?.setDouble(key, value); + } else if (value is List) { + await _prefs?.setStringList(key, value); + } + CacheUtil.instance.set(key, value); } @override Future get(String key) async { - return await _lock.synchronized(() async { - var value = CacheUtil.instance.get(key); - if (value == null) { - value = _prefs?.get(key); - CacheUtil.instance.set(key, value); - } - return value; - }); + log('Getting value for key: $key'); + var value = CacheUtil.instance.get(key); + if (value == null) { + value = _prefs?.get(key); + CacheUtil.instance.set(key, value); + } + return value; } @override Future delete(String key) async { - await _lock.synchronized(() async { - await _prefs?.remove(key); - CacheUtil.instance.delete(key); - }); + log('Deleting value for key: $key'); + await _prefs?.remove(key); + CacheUtil.instance.delete(key); } + @override Future purge() async { - await _lock.synchronized(() async { - await _prefs?.clear(); - CacheUtil.instance.clear(); - await ensureInitialization(); - }); + log('Purging shared preferences'); + await _prefs?.clear(); + CacheUtil.instance.clear(); + } } \ No newline at end of file diff --git a/lib/shared/helpers/sqlite_storage_helper.dart b/lib/shared/helpers/sqlite_storage_helper.dart index 7e481f34..d008d7ed 100644 --- a/lib/shared/helpers/sqlite_storage_helper.dart +++ b/lib/shared/helpers/sqlite_storage_helper.dart @@ -1,4 +1,5 @@ import 'package:hub/shared/utils/cache_util.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:sqflite/sqflite.dart'; import 'dart:developer'; import 'package:path/path.dart'; @@ -38,7 +39,7 @@ class DatabaseConfig { ]; } -class SQLiteStorageHelper { +class SQLiteStorageHelper implements Storage { static final SQLiteStorageHelper _instance = SQLiteStorageHelper._internal(); static Database? _database; static String? _databasePath; @@ -51,7 +52,7 @@ class SQLiteStorageHelper { - Future ensureInitialization() async { + Future get database async { log('Getting database instance'); if (_database != null) return _database!; _database = await _initDatabase(); @@ -140,220 +141,6 @@ class SQLiteStorageHelper { } } - String _devUUID = ''; - String _userUUID = ''; - String _userDevUUID = ''; - String _status = ''; - String _userName = ''; - String _cliUUID = ''; - String _ownerUUID = ''; - String _cliName = ''; - String _petAmountRegister = ''; - bool _whatsapp = false; - bool _provisional = false; - bool _pets = false; - bool _local = false; - bool _notify = false; - bool _fingerprint = false; - bool _access = false; - bool _panic = false; - bool _person = false; - bool _requestOSnotification = false; - - String get createdAt { - log('Getting createdAt'); - return '0000-00-00 00:00:00'; - } - - String get devUUID { - log('Getting devUUID'); - return _devUUID; - } - - String get userUUID { - log('Getting userUUID'); - return _userUUID; - } - - String get userDevUUID { - log('Getting userDevUUID'); - return _userDevUUID; - } - - String get status { - log('Getting status'); - return _status; - } - - String get userName { - log('Getting userName'); - return _userName; - } - - String get cliUUID { - log('Getting cliUUID'); - return _cliUUID; - } - - String get ownerUUID { - log('Getting ownerUUID'); - return _ownerUUID; - } - - String get cliName { - log('Getting cliName'); - return _cliName; - } - - String get petAmountRegister { - log('Getting petAmountRegister'); - return _petAmountRegister; - } - - bool get whatsapp { - log('Getting whatsapp'); - return _whatsapp; - } - - bool get provisional { - log('Getting provisional'); - return _provisional; - } - - bool get pets { - log('Getting pets'); - return _pets; - } - - bool get local { - log('Getting local'); - return _local; - } - - bool get notify { - log('Getting notify'); - return _notify; - } - - bool get fingerprint { - log('Getting fingerprint'); - return _fingerprint; - } - - bool get access { - log('Getting access'); - return _access; - } - - bool get panic { - log('Getting panic'); - return _panic; - } - - bool get person { - log('Getting person'); - return _person; - } - - bool get requestOSnotification { - log('Getting requestOSnotification'); - return _requestOSnotification; - } - - set devUUID(String value) { - log('Setting devUUID to $value'); - set('devUUID', value); - } - - set userUUID(String value) { - log('Setting userUUID to $value'); - set('userUUID', value); - } - - set userDevUUID(String value) { - log('Setting userDevUUID to $value'); - set('userDevUUID', value); - } - - set status(String value) { - log('Setting status to $value'); - set('status', value); - } - - set userName(String value) { - log('Setting userName to $value'); - set('userName', value); - } - - set cliUUID(String value) { - log('Setting cliUUID to $value'); - set('cliUUID', value); - } - - set ownerUUID(String value) { - log('Setting ownerUUID to $value'); - set('ownerUUID', value); - } - - set cliName(String value) { - log('Setting cliName to $value'); - set('cliName', value); - } - - set petAmountRegister(String value) { - log('Setting petAmountRegister to $value'); - set('petAmountRegister', value); - } - - set whatsapp(bool value) { - log('Setting whatsapp to $value'); - set('whatsapp', value); - } - - set provisional(bool value) { - log('Setting provisional to $value'); - set('provisional', value); - } - - set pets(bool value) { - log('Setting pets to $value'); - set('pets', value); - } - - set local(bool value) { - log('Setting local to $value'); - set('local', value); - } - - set notify(bool value) { - log('Setting notify to $value'); - set('notify', value); - } - - set fingerprint(bool value) { - log('Setting fingerprint to $value'); - set('fingerprint', value); - } - - set access(bool value) { - log('Setting access to $value'); - set('access', value); - } - - set panic(bool value) { - log('Setting panic to $value'); - set('panic', value); - } - - set person(bool value) { - log('Setting person to $value'); - set('person', value); - } - - set requestOSnotification(bool value) { - log('Setting requestOSnotification to $value'); - set('requestOSnotification', value); - } Future setupLocalVariables() async { log('Setting up local variables'); @@ -403,6 +190,9 @@ class SQLiteStorageHelper { return value == 'true'; } + + + @override Future get(String key) async { log('Getting value for key: $key'); final cachedValue = CacheUtil().get(key); @@ -412,7 +202,7 @@ class SQLiteStorageHelper { } try { - final db = await ensureInitialization(); + final db = await database; final result = await db.query( DatabaseConfig.tableKeychain, columns: [DatabaseConfig.columnValue], @@ -434,10 +224,11 @@ class SQLiteStorageHelper { } } - Future set(String key, dynamic value) async { + @override + Future set(String key, dynamic value, Function(dynamic) cacheSetter) async { log('Setting value for key: $key to $value'); CacheUtil().set(key, value); - final db = await ensureInitialization(); + final db = await database; final data = { DatabaseConfig.columnKey: key, DatabaseConfig.columnValue: value.toString(), @@ -450,13 +241,14 @@ class SQLiteStorageHelper { data, conflictAlgorithm: ConflictAlgorithm.replace, ); - log('Value set for key: $key'); + log('Value $value set for key: $key'); return result; } + @override Future delete(String key) async { log('Deleting value for key: $key'); - final db = await ensureInitialization(); + final db = await database; final result = await db.transaction((txn) async { return await txn.delete( DatabaseConfig.tableKeychain, @@ -468,10 +260,11 @@ class SQLiteStorageHelper { return result; } + @override Future purge() async { log('Purging database'); await deleteDatabaseDB(); - await ensureInitialization(); + await database; log('Database purged'); } @@ -482,9 +275,12 @@ class SQLiteStorageHelper { log('Database deleted'); _database = null; } + } +class SqliteStorageDelegate {} + diff --git a/lib/shared/utils/biometric_util.dart b/lib/shared/utils/biometric_util.dart index 5a3faeb0..fcb67c53 100644 --- a/lib/shared/utils/biometric_util.dart +++ b/lib/shared/utils/biometric_util.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:local_auth/local_auth.dart'; class BiometricHelper { diff --git a/lib/shared/utils/device_util.dart b/lib/shared/utils/device_util.dart index 76fb92d2..42519099 100644 --- a/lib/shared/utils/device_util.dart +++ b/lib/shared/utils/device_util.dart @@ -19,6 +19,7 @@ class DeviceUtil { var androidDeviceInfo = await deviceInfo.androidInfo; return androidDeviceInfo.id; // unique ID on Android } + return null; } static Future getSerialNumber() async { @@ -31,5 +32,6 @@ class DeviceUtil { var androidDeviceInfo = await deviceInfo.androidInfo; return androidDeviceInfo.serialNumber; // unique ID on Android } + return null; } } diff --git a/lib/shared/utils/image_util.dart b/lib/shared/utils/image_util.dart index 25c56281..fe728e0d 100644 --- a/lib/shared/utils/image_util.dart +++ b/lib/shared/utils/image_util.dart @@ -17,6 +17,7 @@ class ImageUtils { String base64Image = base64Encode(imageBytes); return base64Image; } + return null; } static Future convertToUploadFile(String img) async { diff --git a/lib/shared/utils/log_util.dart b/lib/shared/utils/log_util.dart index 11aa8b27..519cedee 100644 --- a/lib/shared/utils/log_util.dart +++ b/lib/shared/utils/log_util.dart @@ -1,6 +1,5 @@ import 'dart:developer'; -import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; class LogUtil { diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index 61729bfc..842c5102 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -1,10 +1,11 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final cliName = SQLiteStorageHelper().cliName; - final cliUUID = SQLiteStorageHelper().cliUUID; + final cliName = StorageUtil().cliName; + final cliUUID = StorageUtil().cliUUID; for (var i = 0; i < payload['convites'].length; i++) { await Share.share(''' @@ -15,7 +16,7 @@ Olá, \*${payload['convites'][i]['VTE_NOME']}\*! Você foi convidado para \*$cli - Fim: ${payload['convites'][i]['VAW_DTFIM']} URL do Convite: https://visita.freaccess.com.br/${payload['convites'][i]['VAW_ID']}/$cliUUID/${payload['convites'][i]['VAW_CHAVE']} - '''); +'''); } } } diff --git a/lib/shared/utils/storage_util.dart b/lib/shared/utils/storage_util.dart index a801c513..e1054458 100644 --- a/lib/shared/utils/storage_util.dart +++ b/lib/shared/utils/storage_util.dart @@ -1,14 +1,19 @@ import 'dart:developer'; +import 'package:flutter/material.dart'; import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/cache_util.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +enum StorageType { SecureStorage, SharedPreferences, SQLite3 } abstract class Storage { - Future set(String key, dynamic value); + Future set(String key, dynamic value, Function(dynamic) cacheSetter); Future get(String key); Future delete(String key); + Future purge(); } class StorageData { @@ -19,25 +24,30 @@ class StorageData { StorageData(this.key, this.value, this.type); } -enum StorageType { SecureStorage, SharedPreferences, SQLite3 } +class StorageUtil { + static final StorageUtil _instance = StorageUtil._internal(); -class StorageManager { - static final SecureStorageHelper _secureStorage = SecureStorageHelper(); - static final SharedPreferencesStorageHelper _sharedPreferences = SharedPreferencesStorageHelper(); - static final SQLiteStorageHelper _sqliteStorage = SQLiteStorageHelper(); + factory StorageUtil() { + return _instance; + } + + StorageUtil._internal(); + + final SQLiteStorageHelper _sqliteStorage = SQLiteStorageHelper(); + final SecureStorageHelper _secureStorage = SecureStorageHelper(); + final SharedPreferencesStorageHelper _sharedPreferences = SharedPreferencesStorageHelper(); static Future set(StorageData data) async { try { switch (data.type) { case StorageType.SecureStorage: - await _secureStorage.set(data.key, data.value); + await SecureStorageHelper().set(data.key, data.value, (v){}); break; case StorageType.SharedPreferences: - await _sharedPreferences.set(data.key, data.value); + await SharedPreferencesStorageHelper().set(data.key, data.value, (v){}); break; case StorageType.SQLite3: - await _sqliteStorage.set(data.key, data.value); - + await SQLiteStorageHelper().set(data.key, data.value, (v){}); break; } } catch (e) { @@ -51,13 +61,13 @@ class StorageManager { if (value == null) { switch (data.type) { case StorageType.SecureStorage: - value = await _secureStorage.get(data.key); + value = await SecureStorageHelper().get(data.key); break; case StorageType.SharedPreferences: - value = await _sharedPreferences.get(data.key); + value = await SharedPreferencesStorageHelper().get(data.key); break; case StorageType.SQLite3: - value = await _sqliteStorage.get(data.key); + value = await SQLiteStorageHelper().get(data.key); break; } CacheUtil().set(data.key, value); @@ -71,16 +81,16 @@ class StorageManager { static Future delete(StorageData data) async { try { + CacheUtil().delete(data.key); switch (data.type) { case StorageType.SecureStorage: - CacheUtil().delete(data.key); - await _secureStorage.delete(data.key); + await SecureStorageHelper().delete(data.key); break; case StorageType.SharedPreferences: - await _sharedPreferences.delete(data.key); + await SharedPreferencesStorageHelper().delete(data.key); break; case StorageType.SQLite3: - await _sqliteStorage.delete(data.key); + await SQLiteStorageHelper().delete(data.key); break; } } catch (e) { @@ -90,13 +100,191 @@ class StorageManager { static Future purge() async { try { - await _secureStorage.purge(); - await _sharedPreferences.purge(); - await _sqliteStorage.purge(); + await SecureStorageHelper().purge(); + await SharedPreferencesStorageHelper().purge(); + await SQLiteStorageHelper().purge(); } catch (e) { log('Error purging data: $e'); } } -} -class StorageUtil {} \ No newline at end of file + Future ensureInitialization() async { + await initSharedPreferences(); + await initSecureStorage(); + await initSQLiteStorage(); + } + + Future initSharedPreferences() async { + if (_sharedPreferences.prefs == null) { + _sharedPreferences.prefs = await SharedPreferences.getInstance(); + _sharedPreferences.isFirstRun = _sharedPreferences.prefs?.getBool('first_run') ?? true; + } + if (_sharedPreferences.isFirstRun) { + _sharedPreferences.isFirstRun = false; + _sharedPreferences.purge(); + } + } + + Future initSecureStorage() async { + log('SecureStorageHelper: Starting initialization'); + try { + _email = await _secureStorage.getString('ff_email'); + _passwd = await _secureStorage.getString('ff_passwd'); + _deviceType = await _secureStorage.getString('ff_deviceType'); + _isLogged = await _secureStorage.getBool('ff_isLogged'); + _tokenAPNS = await _secureStorage.getString('ff_tokenAPNS'); + _accessPass = await _secureStorage.getString('accessPass'); + _panicPass = await _secureStorage.getString('panicPass'); + _fingerprintPass = await _secureStorage.getString('fingerprintPass'); + _haveLocal = await _secureStorage.getBool('ff_have_local'); + _deviceDescription = await _secureStorage.getString('deviceDescription'); + } catch (e) { + log('SecureStorageHelper: Error during initialization: $e'); + } + log('SecureStorageHelper: Initialization complete'); + } + + Future initSQLiteStorage() async { + log('SQLiteStorageHelper: Starting initialization'); + try { + await _sqliteStorage.database; + } catch (e) { + log('SQLiteStorageHelper: Error during initialization: $e'); + } + log('SQLiteStorageHelper: Initialization complete'); + } + + bool _isFirstRun = true; + bool get isFirstRun => _isFirstRun; + set isFirstRun(bool value) { + _isFirstRun = value; + _sharedPreferences.set('first_run', value, (v){}); + } + + String? _deviceDescription; + String get deviceDescription => _deviceDescription ?? ''; + set deviceDescription(String value) => _secureStorage.set('deviceDescription', value, (v) => _deviceDescription = v); + + BuildContext? _context; + BuildContext? get context => _context; + set context(BuildContext? value) => _secureStorage.set('ff_context', value.toString(), (v) => _context = value); + + bool? _haveLocal; + bool? get haveLocal => _haveLocal; + set haveLocal(bool? value) => _secureStorage.set('ff_have_local', value ?? false, (v) => _haveLocal = value); + + String? _fingerprintPass; + String get fingerprintPass => _fingerprintPass ?? ''; + set fingerprintPass(String value) => _secureStorage.set('fingerprintPass', value, (v) => _fingerprintPass = v); + + String? _accessPass; + String get accessPass => _accessPass ?? ''; + set accessPass(String value) => _secureStorage.set('accessPass', value, (v) => _accessPass = v); + + String? _panicPass; + String get panicPass => _panicPass ?? ''; + set panicPass(String value) => _secureStorage.set('panicPass', value, (v) => _panicPass = v); + + String? _tokenAPNS; + String? get tokenAPNS => _tokenAPNS; + set tokenAPNS(String? value) => _secureStorage.set('ff_tokenAPNS', value ?? '', (v) => _tokenAPNS = v); + + String? _email; + String get email => _email ?? ''; + set email(String value) => _secureStorage.set('ff_email', value, (v) => _email = v); + + String? _passwd; + String get passwd => _passwd ?? ''; + set passwd(String value) => _secureStorage.set('ff_passwd', value, (v) => _passwd = v); + + String? _deviceType; + String get deviceType => _deviceType ?? ''; + set deviceType(String value) => _secureStorage.set('ff_deviceType', value, (v) => _deviceType = v); + + bool? _isLogged; + bool get isLogged => _isLogged ?? false; + set isLogged(bool value) => _secureStorage.set('ff_isLogged', value, (v) => _isLogged = v); + + String? _token; + String get token => _token ?? ''; + set token(String value) => _secureStorage.set('ff_token', value, (v) => _token = v); + + + final String _devUUID = ''; + String get devUUID => _devUUID; + set devUUID(String value) => _sqliteStorage.set('devUUID', value, (v){}); + + final String _userUUID = ''; + String get userUUID => _userUUID; + set userUUID(String value) => _sqliteStorage.set('userUUID', value, (v){}); + + final String _userDevUUID = ''; + String get userDevUUID => _userDevUUID; + set userDevUUID(String value) => _sqliteStorage.set('userDevUUID', value, (v){}); + + final String _status = ''; + String get status => _status; + set status(String value) => _sqliteStorage.set('status', value, (v){}); + + final String _userName = ''; + String get userName => _userName; + set userName(String value) => _sqliteStorage.set('userName', value, (v){}); + + final String _cliUUID = ''; + String get cliUUID => _cliUUID; + set cliUUID(String value) => _sqliteStorage.set('cliUUID', value, (v){}); + + final String _ownerUUID = ''; + String get ownerUUID => _ownerUUID; + set ownerUUID(String value) => _sqliteStorage.set('ownerUUID', value, (v){}); + + final String _cliName = ''; + String get cliName => _cliName; + set cliName(String value) => _sqliteStorage.set('cliName', value, (v){}); + + final String _petAmountRegister = ''; + String get petAmountRegister => _petAmountRegister; + set petAmountRegister(String value) => _sqliteStorage.set('petAmountRegister', value, (v){}); + + final bool _whatsapp = false; + bool get whatsapp => _whatsapp; + set whatsapp(bool value) => _sqliteStorage.set('whatsapp', value, (v){}); + + final bool _provisional = false; + bool get provisional => _provisional; + set provisional(bool value) => _sqliteStorage.set('provisional', value, (v){}); + + final bool _pets = false; + bool get pets => _pets; + set pets(bool value) => _sqliteStorage.set('pets', value, (v){}); + + final bool _local = false; + bool get local => _local; + set local(bool value) => _sqliteStorage.set('local', value, (v){}); + + final bool _notify = false; + bool get notify => _notify; + set notify(bool value) => _sqliteStorage.set('notify', value, (v){}); + + final bool _fingerprint = false; + bool get fingerprint => _fingerprint; + set fingerprint(bool value) => _sqliteStorage.set('fingerprint', value, (v){}); + + final bool _access = false; + bool get access => _access; + set access(bool value) => _sqliteStorage.set('access', value, (v){}); + + final bool _panic = false; + bool get panic => _panic; + set panic(bool value) => _sqliteStorage.set('panic', value, (v){}); + + final bool _person = false; + bool get person => _person; + set person(bool value) => _sqliteStorage.set('person', value, (v){}); + + final bool _requestOSnotification = false; + bool get requestOSnotification => _requestOSnotification; + set requestOSnotification(bool value) => _sqliteStorage.set('requestOSnotification', value, (v){}); + + String get createdAt => '0000-00-00 00:00:00'; +} diff --git a/lib/shared/utils/validator_util.dart b/lib/shared/utils/validator_util.dart index f1550827..18424821 100644 --- a/lib/shared/utils/validator_util.dart +++ b/lib/shared/utils/validator_util.dart @@ -23,14 +23,14 @@ class ValidatorUtil { DateFormat dateFormat = DateFormat(format); DateTime dateTime = dateFormat.parse(value); - return dateTime.toIso8601String() + 'Z'; + return '${dateTime.toIso8601String()}Z'; } static String toISO8601USA(String format, String value) { DateFormat dateFormat = DateFormat(format); DateTime dateTime = dateFormat.parse(value); - String date = dateTime.toIso8601String() + 'Z'; - date = date.substring(0, 11) + '03:00:00.000Z'; + String date = '${dateTime.toIso8601String()}Z'; + date = '${date.substring(0, 11)}03:00:00.000Z'; return date; } diff --git a/lib/shared/widgets/drawer_widget/drawer_widget.dart b/lib/shared/widgets/drawer_widget/drawer_widget.dart index 0a4ad55a..80af1bf1 100644 --- a/lib/shared/widgets/drawer_widget/drawer_widget.dart +++ b/lib/shared/widgets/drawer_widget/drawer_widget.dart @@ -52,7 +52,7 @@ class CustomDrawer extends StatelessWidget { width: 50.0, height: 50.0, clipBehavior: Clip.antiAlias, - decoration: BoxDecoration( + decoration: const BoxDecoration( shape: BoxShape.circle, ), child: CachedNetworkImage( From 99a23f29755808a7c4777a9e4a0ade4e37266996 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 26 Sep 2024 13:53:50 -0300 Subject: [PATCH 6/6] WIP --- .../firebase_messaging_service.dart | 18 -- .../local_profile_component_widget.dart | 21 +- .../preferences_settings_model.dart | 2 +- lib/shared/utils/storage_util.dart | 218 +++++++++++++----- 4 files changed, 175 insertions(+), 84 deletions(-) diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index ff259a39..be23aad5 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -35,24 +35,6 @@ class FirebaseMessagingService { _firebaseMessaging.setAutoInitEnabled(false); _firebaseMessaging.pluginConstants; - - // FirebaseMessaging.onBackgroundMessage(handleMessage); - - // FirebaseMessaging.onMessage.listen((RemoteMessage message) { - // handleMessage(message); - // }); - - // FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { - // log('A Message was opened: $message'); - // }); - - // FirebaseMessaging.instance - // .getInitialMessage() - // .then((RemoteMessage? message) { - // if (message != null) { - // log('A Message was opened: $message'); - // } - // }); } static Future getToken() async => 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 20d270b5..f5b709e7 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 @@ -68,26 +68,31 @@ class _LocalProfileComponentWidgetState // final errorMsg = response.jsonBody['error_msg']; if (error == false) { - final whatsapp = response.jsonBody['whatsapp'] ?? false; - final provisional = response.jsonBody['provisional'] ?? false; - final pets = response.jsonBody['pet'] ?? false; - final petAmountRegister = response.jsonBody['petAmountRegister'] ?? '0'; - final name = response.jsonBody['visitado']['VDO_NOME']; + final bool whatsapp = response.jsonBody['whatsapp'] ?? false; + final bool provisional = response.jsonBody['provisional'] ?? false; + final bool pets = response.jsonBody['pet'] ?? false; + final String petAmountRegister = + response.jsonBody['petAmountRegister'].toString().isEmpty + ? '0' + : response.jsonBody['petAmountRegister'].toString(); + final String name = response.jsonBody['visitado']['VDO_NOME']; StorageUtil().whatsapp = whatsapp; StorageUtil().provisional = provisional; StorageUtil().pets = pets; StorageUtil().petAmountRegister = petAmountRegister; - StorageUtil().cliName = name; + StorageUtil().userName = name; safeSetState(() {}); return; + } else if (error == true) { + DialogUtil.warningDefault(context).whenComplete(() => processLocals()); + safeSetState(() {}); } - DialogUtil.warningDefault(context).whenComplete(() => processLocals()); - safeSetState(() {}); return; } catch (e) { + log('() => error: $e'); // Add this line to log the error DialogUtil.warningDefault(context).whenComplete(() => processLocals()); } } diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 5f0254aa..b119be90 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -316,7 +316,7 @@ class PreferencesPageModel with ChangeNotifier { Future _toggleBoolInDb(String key) async { final currentValue = await _getBoolFromDb(key); final newValue = !currentValue; - await SQLiteStorageHelper().set(key, newValue.toString()); + await SQLiteStorageHelper().set(key, newValue.toString(), (v) {}); return newValue; } diff --git a/lib/shared/utils/storage_util.dart b/lib/shared/utils/storage_util.dart index e1054458..e1e6067c 100644 --- a/lib/shared/utils/storage_util.dart +++ b/lib/shared/utils/storage_util.dart @@ -35,21 +35,30 @@ class StorageUtil { final SQLiteStorageHelper _sqliteStorage = SQLiteStorageHelper(); final SecureStorageHelper _secureStorage = SecureStorageHelper(); - final SharedPreferencesStorageHelper _sharedPreferences = SharedPreferencesStorageHelper(); + final SharedPreferencesStorageHelper _sharedPreferences = + SharedPreferencesStorageHelper(); static Future set(StorageData data) async { try { + var currentValue = CacheUtil().get(data.key); + if (currentValue != null && currentValue == data.value) { + log('Value for key ${data.key} is already set to ${data.value}, skipping update.'); + return; + } + switch (data.type) { case StorageType.SecureStorage: - await SecureStorageHelper().set(data.key, data.value, (v){}); + await SecureStorageHelper().set(data.key, data.value, (v) {}); break; case StorageType.SharedPreferences: - await SharedPreferencesStorageHelper().set(data.key, data.value, (v){}); + await SharedPreferencesStorageHelper() + .set(data.key, data.value, (v) {}); break; case StorageType.SQLite3: - await SQLiteStorageHelper().set(data.key, data.value, (v){}); + await SQLiteStorageHelper().set(data.key, data.value, (v) {}); break; } + CacheUtil().set(data.key, data.value); } catch (e) { log('Error setting data: $e'); } @@ -117,7 +126,8 @@ class StorageUtil { Future initSharedPreferences() async { if (_sharedPreferences.prefs == null) { _sharedPreferences.prefs = await SharedPreferences.getInstance(); - _sharedPreferences.isFirstRun = _sharedPreferences.prefs?.getBool('first_run') ?? true; + _sharedPreferences.isFirstRun = + _sharedPreferences.prefs?.getBool('first_run') ?? true; } if (_sharedPreferences.isFirstRun) { _sharedPreferences.isFirstRun = false; @@ -158,133 +168,227 @@ class StorageUtil { bool get isFirstRun => _isFirstRun; set isFirstRun(bool value) { _isFirstRun = value; - _sharedPreferences.set('first_run', value, (v){}); + _sharedPreferences.set('first_run', value, (v) => _isFirstRun = v); } String? _deviceDescription; String get deviceDescription => _deviceDescription ?? ''; - set deviceDescription(String value) => _secureStorage.set('deviceDescription', value, (v) => _deviceDescription = v); + set deviceDescription(String value) { + _deviceDescription = value; + _secureStorage.set( + 'deviceDescription', value, (v) => _deviceDescription = v); + } BuildContext? _context; BuildContext? get context => _context; - set context(BuildContext? value) => _secureStorage.set('ff_context', value.toString(), (v) => _context = value); + set context(BuildContext? value) { + _context = value; + _secureStorage.set('ff_context', value.toString(), (v) => _context = value); + } bool? _haveLocal; bool? get haveLocal => _haveLocal; - set haveLocal(bool? value) => _secureStorage.set('ff_have_local', value ?? false, (v) => _haveLocal = value); + set haveLocal(bool? value) { + _haveLocal = value; + _secureStorage.set( + 'ff_have_local', value ?? false, (v) => _haveLocal = value); + } String? _fingerprintPass; String get fingerprintPass => _fingerprintPass ?? ''; - set fingerprintPass(String value) => _secureStorage.set('fingerprintPass', value, (v) => _fingerprintPass = v); + set fingerprintPass(String value) { + _fingerprintPass = value; + _secureStorage.set('fingerprintPass', value, (v) => _fingerprintPass = v); + } String? _accessPass; String get accessPass => _accessPass ?? ''; - set accessPass(String value) => _secureStorage.set('accessPass', value, (v) => _accessPass = v); + set accessPass(String value) { + _accessPass = value; + _secureStorage.set('accessPass', value, (v) => _accessPass = v); + } String? _panicPass; String get panicPass => _panicPass ?? ''; - set panicPass(String value) => _secureStorage.set('panicPass', value, (v) => _panicPass = v); + set panicPass(String value) { + _panicPass = value; + _secureStorage.set('panicPass', value, (v) => _panicPass = v); + } String? _tokenAPNS; String? get tokenAPNS => _tokenAPNS; - set tokenAPNS(String? value) => _secureStorage.set('ff_tokenAPNS', value ?? '', (v) => _tokenAPNS = v); + set tokenAPNS(String? value) { + _tokenAPNS = value; + _secureStorage.set('ff_tokenAPNS', value ?? '', (v) => _tokenAPNS = v); + } String? _email; String get email => _email ?? ''; - set email(String value) => _secureStorage.set('ff_email', value, (v) => _email = v); + set email(String value) { + _email = value; + _secureStorage.set('ff_email', value, (v) => _email = v); + } String? _passwd; String get passwd => _passwd ?? ''; - set passwd(String value) => _secureStorage.set('ff_passwd', value, (v) => _passwd = v); + set passwd(String value) { + _passwd = value; + _secureStorage.set('ff_passwd', value, (v) => _passwd = v); + } String? _deviceType; String get deviceType => _deviceType ?? ''; - set deviceType(String value) => _secureStorage.set('ff_deviceType', value, (v) => _deviceType = v); + set deviceType(String value) { + _deviceType = value; + _secureStorage.set('ff_deviceType', value, (v) => _deviceType = v); + } bool? _isLogged; bool get isLogged => _isLogged ?? false; - set isLogged(bool value) => _secureStorage.set('ff_isLogged', value, (v) => _isLogged = v); + set isLogged(bool value) { + _isLogged = value; + _secureStorage.set('ff_isLogged', value, (v) => _isLogged = v); + } String? _token; String get token => _token ?? ''; - set token(String value) => _secureStorage.set('ff_token', value, (v) => _token = v); + set token(String value) { + _token = value; + _secureStorage.set('ff_token', value, (v) => _token = v); + } - - final String _devUUID = ''; + String _devUUID = ''; String get devUUID => _devUUID; - set devUUID(String value) => _sqliteStorage.set('devUUID', value, (v){}); + set devUUID(String value) { + _devUUID = value; + _sqliteStorage.set('devUUID', value, (v) {}); + } - final String _userUUID = ''; + String _userUUID = ''; String get userUUID => _userUUID; - set userUUID(String value) => _sqliteStorage.set('userUUID', value, (v){}); + set userUUID(String value) { + _userUUID = value; + _sqliteStorage.set('userUUID', value, (v) {}); + } - final String _userDevUUID = ''; + String _userDevUUID = ''; String get userDevUUID => _userDevUUID; - set userDevUUID(String value) => _sqliteStorage.set('userDevUUID', value, (v){}); + set userDevUUID(String value) { + _userDevUUID = value; + _sqliteStorage.set('userDevUUID', value, (v) {}); + } - final String _status = ''; + String _status = ''; String get status => _status; - set status(String value) => _sqliteStorage.set('status', value, (v){}); + set status(String value) { + _status = value; + _sqliteStorage.set('status', value, (v) {}); + } - final String _userName = ''; + String _userName = ''; String get userName => _userName; - set userName(String value) => _sqliteStorage.set('userName', value, (v){}); + set userName(String value) { + _userName = value; + _sqliteStorage.set('userName', value, (v) {}); + } - final String _cliUUID = ''; + String _cliUUID = ''; String get cliUUID => _cliUUID; - set cliUUID(String value) => _sqliteStorage.set('cliUUID', value, (v){}); + set cliUUID(String value) { + _cliUUID = value; + _sqliteStorage.set('cliUUID', value, (v) {}); + } - final String _ownerUUID = ''; + String _ownerUUID = ''; String get ownerUUID => _ownerUUID; - set ownerUUID(String value) => _sqliteStorage.set('ownerUUID', value, (v){}); + set ownerUUID(String value) { + _ownerUUID = value; + _sqliteStorage.set('ownerUUID', value, (v) {}); + } - final String _cliName = ''; + String _cliName = ''; String get cliName => _cliName; - set cliName(String value) => _sqliteStorage.set('cliName', value, (v){}); + set cliName(String value) { + _cliName = value; + _sqliteStorage.set('cliName', value, (v) {}); + } - final String _petAmountRegister = ''; + String _petAmountRegister = ''; String get petAmountRegister => _petAmountRegister; - set petAmountRegister(String value) => _sqliteStorage.set('petAmountRegister', value, (v){}); + set petAmountRegister(String value) { + _petAmountRegister = value; + _sqliteStorage.set('petAmountRegister', value, (v) {}); + } - final bool _whatsapp = false; + bool _whatsapp = false; bool get whatsapp => _whatsapp; - set whatsapp(bool value) => _sqliteStorage.set('whatsapp', value, (v){}); + set whatsapp(bool value) { + _whatsapp = value; + _sqliteStorage.set('whatsapp', value, (v) {}); + } - final bool _provisional = false; + bool _provisional = false; bool get provisional => _provisional; - set provisional(bool value) => _sqliteStorage.set('provisional', value, (v){}); + set provisional(bool value) { + _provisional = value; + _sqliteStorage.set('provisional', value, (v) {}); + } - final bool _pets = false; + bool _pets = false; bool get pets => _pets; - set pets(bool value) => _sqliteStorage.set('pets', value, (v){}); + set pets(bool value) { + _pets = value; + _sqliteStorage.set('pets', value, (v) {}); + } - final bool _local = false; + bool _local = false; bool get local => _local; - set local(bool value) => _sqliteStorage.set('local', value, (v){}); + set local(bool value) { + _local = value; + _sqliteStorage.set('local', value, (v) {}); + } - final bool _notify = false; + bool _notify = false; bool get notify => _notify; - set notify(bool value) => _sqliteStorage.set('notify', value, (v){}); + set notify(bool value) { + _notify = value; + _sqliteStorage.set('notify', value, (v) {}); + } - final bool _fingerprint = false; + bool _fingerprint = false; bool get fingerprint => _fingerprint; - set fingerprint(bool value) => _sqliteStorage.set('fingerprint', value, (v){}); + set fingerprint(bool value) { + _fingerprint = value; + _sqliteStorage.set('fingerprint', value, (v) {}); + } - final bool _access = false; + bool _access = false; bool get access => _access; - set access(bool value) => _sqliteStorage.set('access', value, (v){}); + set access(bool value) { + _access = value; + _sqliteStorage.set('access', value, (v) {}); + } - final bool _panic = false; + bool _panic = false; bool get panic => _panic; - set panic(bool value) => _sqliteStorage.set('panic', value, (v){}); + set panic(bool value) { + _panic = value; + _sqliteStorage.set('panic', value, (v) {}); + } - final bool _person = false; + bool _person = false; bool get person => _person; - set person(bool value) => _sqliteStorage.set('person', value, (v){}); + set person(bool value) { + _person = value; + _sqliteStorage.set('person', value, (v) {}); + } - final bool _requestOSnotification = false; + bool _requestOSnotification = false; bool get requestOSnotification => _requestOSnotification; - set requestOSnotification(bool value) => _sqliteStorage.set('requestOSnotification', value, (v){}); + set requestOSnotification(bool value) { + _requestOSnotification = value; + _sqliteStorage.set('requestOSnotification', value, (v) {}); + } String get createdAt => '0000-00-00 00:00:00'; }