From a68c240c57ea11e616019790d0ba0853cd1f3fac Mon Sep 17 00:00:00 2001 From: Ivan Antunes Date: Mon, 4 Nov 2024 17:42:12 -0300 Subject: [PATCH] feat: refactory storage --- android/app/build.gradle | 6 +- integration_test/app_test.dart | 15 +- lib/app_state.dart | 1 - lib/backend/api_requests/api_calls.dart | 189 ++++---- .../firebase_messaging_service.dart | 5 +- .../notifications/notification_service.dart | 20 +- .../menu_button_item_widget.dart | 2 - .../order_filter_modal_widget.dart | 11 +- ..._arrow_linked_locals_component_widget.dart | 22 +- .../local_profile_component_model.dart | 7 +- .../menu_component/menu_component_model.dart | 16 +- .../schedule_visit_detail_model.dart | 10 +- ...p_arrow_linked_locals_component_model.dart | 11 +- ...cation_modal_template_component_model.dart | 9 +- .../change_pass_widget.dart | 17 +- ...item_details_template_component_model.dart | 9 +- .../provisional_schedule_template_model.dart | 13 +- .../provisional_shcedule_template_widget.dart | 2 - ...siter_vistor_template_component_model.dart | 9 +- .../sign_up_template_component_widget.dart | 13 +- .../view_visit_detail_model.dart | 9 +- ...search_modal_template_component_model.dart | 9 +- lib/flutter_flow/flutter_flow_util.dart | 1 - lib/flutter_flow/nav/nav.dart | 19 +- lib/main.dart | 46 +- .../acess_history_page_model.dart | 9 +- .../fast_pass_page/fast_pass_page_widget.dart | 13 +- .../forgot_password_screen.dart | 6 +- lib/pages/home_page/home_page_model.dart | 13 +- lib/pages/home_page/home_page_widget.dart | 4 +- .../liberation_history_model.dart | 9 +- .../message_history_page_model.dart | 9 +- .../package_order_page.dart | 7 +- lib/pages/pets_page/pets_history_screen.dart | 11 +- lib/pages/pets_page/pets_page_model.dart | 11 +- .../preferences_settings_model.dart | 69 +-- .../preferences_settings_widget.dart | 16 +- .../qr_code_page/qr_code_page_model.dart | 8 +- .../qr_code_page/qr_code_page_widget.dart | 7 +- .../reception_page/reception_page_model.dart | 5 +- .../reception_page/reception_page_widget.dart | 8 +- .../reservation_page_widget.dart | 15 +- .../schedule_complete_visit_page_model.dart | 9 +- .../visit_history_page_widget.dart | 17 +- .../sign_in_page/sign_in_page_widget.dart | 4 +- .../sign_up_page/sign_up_page_widget.dart | 4 +- .../welcome_page/welcome_page_widget.dart | 15 +- lib/shared/helpers/base_storage.dart | 144 ++++++ lib/shared/helpers/secure_storage.dart | 41 ++ lib/shared/helpers/secure_storage_helper.dart | 110 ----- .../helpers/shared_preferences_storage.dart | 41 ++ .../shared_preferences_storage_helper.dart | 95 ---- lib/shared/helpers/sqlite_storage.dart | 133 ++++++ lib/shared/helpers/sqlite_storage_helper.dart | 275 ----------- lib/shared/helpers/storage_helper.dart | 81 ++++ .../authentication_service.dart | 39 +- .../localization/localization_service.dart | 90 ++-- lib/shared/utils/cache_util.dart | 34 -- lib/shared/utils/share_util.dart | 7 +- lib/shared/utils/storage_util.dart | 439 ------------------ .../image_cropper_widget/image_cropper.dart | 2 +- 61 files changed, 907 insertions(+), 1364 deletions(-) delete mode 100644 lib/app_state.dart create mode 100644 lib/shared/helpers/base_storage.dart create mode 100644 lib/shared/helpers/secure_storage.dart delete mode 100644 lib/shared/helpers/secure_storage_helper.dart create mode 100644 lib/shared/helpers/shared_preferences_storage.dart delete mode 100644 lib/shared/helpers/shared_preferences_storage_helper.dart create mode 100644 lib/shared/helpers/sqlite_storage.dart delete mode 100644 lib/shared/helpers/sqlite_storage_helper.dart create mode 100644 lib/shared/helpers/storage_helper.dart delete mode 100644 lib/shared/utils/cache_util.dart delete mode 100644 lib/shared/utils/storage_util.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index af88cf55..6ec0d534 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -57,12 +57,12 @@ android { compileOptions { coreLibraryDesugaringEnabled true - sourceCompatibility JavaVersion.VERSION_18 - targetCompatibility JavaVersion.VERSION_18 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = "18" + jvmTarget = "11" } signingConfigs { diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 3c69a8d3..5e237910 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -3,7 +3,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hub/flutter_flow/random_data_util.dart'; import 'package:hub/main.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:integration_test/integration_test.dart'; late WidgetTester widget; @@ -13,7 +14,9 @@ void main() { group('Initialization', () { group('Navigation', () { - setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); + setUpAll(() async => await initializeApp().then((_) async => + StorageHelper.instance.set(SecureStorageKey.isLogged.value, 'false', Storage.SecureStorage)) + ); testWidgets('Test Welcome', (WidgetTester tester) async { widget = tester; await _testWelcome(); @@ -24,14 +27,18 @@ void main() { }); group('Authentication', () { group('Sign in', () { - setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); + setUpAll(() async => await initializeApp().then((_) async => + StorageHelper.instance.set(SecureStorageKey.isLogged.value, 'false', Storage.SecureStorage)) + ); testWidgets('Test Sign In', (WidgetTester tester) async { widget = tester; await _testSignIn(); }); }); group('Sign up', () { - setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); + setUpAll(() async => await initializeApp().then((_) async => + StorageHelper.instance.set(SecureStorageKey.isLogged.value, 'false', Storage.SecureStorage)) + ); testWidgets('Test Sign Up', (WidgetTester tester) async { widget = tester; await _testSignUp(); diff --git a/lib/app_state.dart b/lib/app_state.dart deleted file mode 100644 index 8b137891..00000000 --- a/lib/app_state.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 1477e9f4..0d76e676 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -3,7 +3,8 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:hub/backend/notifications/firebase_messaging_service.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -56,8 +57,8 @@ class PhpGroup { class UnregisterDevice { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -84,9 +85,9 @@ class UnregisterDevice { class DeletePet { Future call({final int? petID = 0}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'excluirPet'; return ApiManager.instance.makeApiCall( @@ -129,9 +130,9 @@ class UpdatePet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'atualizarPet'; return ApiManager.instance.makeApiCall( @@ -175,9 +176,9 @@ class GetPets { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'consultaPets'; return ApiManager.instance.makeApiCall( @@ -209,9 +210,9 @@ class GetPetPhoto { Future call({final int? petId}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'consultaFotoPet'; return ApiManager.instance.makeApiCall( @@ -252,9 +253,9 @@ class RegisterPet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'cadastrarPet'; return ApiManager.instance.makeApiCall( @@ -297,9 +298,9 @@ class BuscaEnconcomendas { final String? adresseeType, final String? status, }) async { - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getEncomendas'; final String baseUrl = PhpGroup.getBaseUrl(); @@ -341,9 +342,9 @@ class CancelaVisita { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -375,8 +376,8 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; final String baseUrl = PhpGroup.getBaseUrl(); return ApiManager.instance.makeApiCall( @@ -407,9 +408,9 @@ class ChangePanic { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -443,9 +444,9 @@ class ChangePass { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -479,9 +480,9 @@ class RespondeVinculo { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -513,9 +514,9 @@ class ChangeNotifica { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -547,9 +548,9 @@ class UpdToken { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String token = StorageUtil().token; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String token = (await StorageHelper.instance.get(SecureStorageKey.token.value, Storage.SecureStorage)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'updToken', @@ -576,11 +577,11 @@ class UpdToken { class LoginCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String email = StorageUtil().email; - final String password = StorageUtil().passwd; - final String type = StorageUtil().deviceType; - final String description = StorageUtil().deviceDescription; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String email = (await StorageHelper.instance.get(SecureStorageKey.email.value, Storage.SecureStorage)) ?? ''; + final String password = (await StorageHelper.instance.get(SecureStorageKey.password.value, Storage.SecureStorage)) ?? ''; + final String type = (await StorageHelper.instance.get(SecureStorageKey.deviceType.value, Storage.SecureStorage)) ?? ''; + final String description = (await StorageHelper.instance.get(SecureStorageKey.deviceDescription.value, Storage.SecureStorage)) ?? ''; final String token = await FirebaseMessagingService.getToken(); return ApiManager.instance.makeApiCall( @@ -655,9 +656,9 @@ class ChangePasswordCall { required final String psswd, }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'changePassword', @@ -716,8 +717,8 @@ class GetLocalsCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -756,9 +757,9 @@ class PostScheduleVisitorCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'putVisitante'; return ApiManager.instance.makeApiCall( @@ -811,9 +812,9 @@ class PostScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'putVisita'; return ApiManager.instance.makeApiCall( @@ -865,9 +866,9 @@ class GetScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliUUID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1139,9 +1140,9 @@ class GetDadosCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliUUID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getDados'; return ApiManager.instance.makeApiCall( @@ -1372,9 +1373,9 @@ class GetVisitorByDocCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getVisitante'; return ApiManager.instance.makeApiCall( @@ -1426,9 +1427,9 @@ class GetFotoVisitanteCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getFotoVisitante'; return ApiManager.instance.makeApiCall( @@ -1465,9 +1466,9 @@ class PostProvVisitSchedulingCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'putAgendamentoProv'; return ApiManager.instance.makeApiCall( @@ -1514,9 +1515,9 @@ class GetVisitsCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1777,9 +1778,9 @@ class DeleteVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -1820,10 +1821,10 @@ class GetPessoasLocalCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String ownerUUID = StorageUtil().ownerUUID; - final String userUUID = StorageUtil().userUUID; - final String cliUUID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String ownerUUID = (await StorageHelper.instance.get(SQLiteStorageKey.ownerUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -1886,9 +1887,9 @@ class RespondeSolicitacaoCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliUUID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'respondeSolicitacao'; return ApiManager.instance.makeApiCall( @@ -1936,9 +1937,9 @@ class GetAccessCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliUUID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getAcessos'; return ApiManager.instance.makeApiCall( @@ -2185,9 +2186,9 @@ class GetLiberationsCall { final StreamController controller = StreamController(); Future.microtask(() async { - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliUUID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'getSolicitacoes'; try { @@ -2377,9 +2378,9 @@ class GetMessagesCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliUUID = StorageUtil().cliUUID; + final String devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; const String 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 d351fb2c..8c2aba83 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -2,8 +2,9 @@ import 'dart:developer'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/log_util.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'notification_service.dart'; @@ -42,7 +43,7 @@ class FirebaseMessagingService { final String? deviceToken = await _firebaseMessaging.getToken(); if (deviceToken != null) { - StorageUtil().token = deviceToken; + await StorageHelper.instance.set(SecureStorageKey.token.value, deviceToken, Storage.SecureStorage); 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 92aa3cfc..5a25aa9f 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -8,13 +8,15 @@ 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:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; -import 'package:hub/shared/utils/storage_util.dart'; Future onMessageReceived(Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final cliUUID = StorageUtil().cliUUID; + final cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + answersRequest( {required BuildContext context, required String? ref, @@ -41,7 +43,7 @@ Future onMessageReceived(Map payload, String? extra, Stri switch (handleClick) { case 'visit_request': showDialog( - context: StorageUtil().context!, + context: StorageHelper.instance.context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -160,7 +162,7 @@ Future onMessageReceived(Map payload, String? extra, Stri break; case 'access': showDialog( - context: StorageUtil().context!, + context: StorageHelper.instance.context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -217,7 +219,7 @@ Future onMessageReceived(Map payload, String? extra, Stri break; case 'mensagem': showDialog( - context: StorageUtil().context!, + context: StorageHelper.instance.context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -237,8 +239,8 @@ Future onMessageReceived(Map payload, String? extra, Stri break; case 'enroll_cond': - StorageUtil().haveLocal = true; - StorageUtil().context!.go('/homePage'); + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + StorageHelper.instance.context!.go('/homePage'); break; default: break; @@ -268,11 +270,11 @@ class NotificationService { debug: kDebugMode); await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async { - final bool requestOSnotification = StorageUtil().requestOSnotification; + final bool requestOSnotification = (await StorageHelper.instance.get(SQLiteStorageKey.requestOSNotification.value, Storage.SQLiteStorage)) == 'true'; if (requestOSnotification == false) { if (isAllowed == false) { - StorageUtil().requestOSnotification = true; + await StorageHelper.instance.set(SQLiteStorageKey.requestOSNotification.value, 'true', Storage.SQLiteStorage); 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 d5b66984..e8b734aa 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,8 +2,6 @@ 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/utils/dialog_util.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import '../../../shared/extensions/dialog_extensions.dart'; import '../../../shared/services/localization/localization_service.dart'; 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 c9fd0aa7..4a08d4ad 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,9 +4,8 @@ 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/storage_helper.dart'; // ignore: unused_import -import 'package:hub/shared/helpers/secure_storage_helper.dart'; -import 'package:hub/shared/utils/storage_util.dart'; class OrderFilterModalWidget extends StatefulWidget { final String defaultAdresseeType; @@ -28,22 +27,22 @@ class _OrderFilterModalWidgetState extends State { late Map selected; final List> adresseeTypeOptions = [ { - 'title': FFLocalizations.of(StorageUtil().context!).getVariableText(enText: 'Resident', ptText: 'Morador'), + 'title': FFLocalizations.of(StorageHelper.instance.context!).getVariableText(enText: 'Resident', ptText: 'Morador'), 'value': 'MOR' }, { - 'title': FFLocalizations.of(StorageUtil().context!).getVariableText(enText: 'Property', ptText: 'Propriedade'), + 'title': FFLocalizations.of(StorageHelper.instance.context!).getVariableText(enText: 'Property', ptText: 'Propriedade'), 'value': 'PRO' }, ]; final List> statusOptions = [ { - 'title': FFLocalizations.of(StorageUtil().context!) + 'title': FFLocalizations.of(StorageHelper.instance.context!) .getVariableText(ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'), 'value': 'notPickedUp' }, { - 'title': FFLocalizations.of(StorageUtil().context!).getVariableText(ptText: 'Retirado', enText: 'Picked Up'), + 'title': FFLocalizations.of(StorageHelper.instance.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 5d0a6dc8..fdfe0d70 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,9 +3,10 @@ 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/base_storage.dart'; +import 'package:hub/shared/helpers/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 '../../../shared/services/authentication/authentication_service.dart'; import '/backend/api_requests/api_calls.dart'; @@ -94,9 +95,10 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State _fetchResponseLink(String status, String cliID) async { try { - StorageUtil().cliUUID = cliID; + await StorageHelper.instance.set(SQLiteStorageKey.clientUUID.value, cliID, Storage.SQLiteStorage); var response = await PhpGroup.resopndeVinculo.call(tarefa: status); if (response.jsonBody['error'] == false) { @@ -139,7 +139,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State getData() async { - cliName = StorageUtil().cliName; - cliUUID = StorageUtil().cliUUID; + cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? '';; setStateCallback?.call(); } 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 2ee1f767..e5580a59 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.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/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; -import 'package:hub/shared/utils/storage_util.dart'; -import '../../../shared/services/localization/localization_service.dart'; import '/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart'; import '/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -60,7 +60,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openDeliverySchedule(BuildContext context) async { - final bool isProvisional = StorageUtil().provisional; + final bool isProvisional = await StorageHelper.instance.get(SQLiteStorageKey.provisional.value, Storage.SQLiteStorage) == 'true'; if (isProvisional == true) { context.push( '/deliverySchedule', @@ -78,7 +78,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openProvisionalSchedule(BuildContext context) async { - final isProvisional = StorageUtil().provisional; + final isProvisional = await StorageHelper.instance.get(SQLiteStorageKey.provisional.value, Storage.SQLiteStorage) == 'true'; if (isProvisional == true) { context.push( '/provisionalSchedule', @@ -96,7 +96,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openFastPassSchedule(BuildContext context) async { - final isWpp = StorageUtil().whatsapp; + final isWpp = await StorageHelper.instance.get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true'; if (isWpp) { context.push( '/fastPassPage', @@ -205,7 +205,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openMyOrders(BuildContext context) async { - final isWpp = StorageUtil().whatsapp; + final isWpp = await StorageHelper.instance.get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true';; if (isWpp) { context.push( '/packageOrder', @@ -223,7 +223,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openReservations(BuildContext context) async { - final isWpp = StorageUtil().whatsapp; + final isWpp = await StorageHelper.instance.get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true';; if (isWpp) { context.push( '/reservation', @@ -339,7 +339,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openPetsRegister(BuildContext context) async { - bool isPet = StorageUtil().pets; + bool isPet = await StorageHelper.instance.get(SQLiteStorageKey.pets.value, Storage.SQLiteStorage) == 'true';; if (isPet) { context.push( '/petsPage', 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 9fae560f..12f453a9 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 @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_manager.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/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; // ignore: unused_import -import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'package:intl/intl.dart'; class ScheduleVisitDetailModel extends FlutterFlowModel { @@ -56,9 +56,9 @@ class ScheduleVisitDetailModel extends FlutterFlowModel initDB() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } @override 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 235ccfe0..9d584cab 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 @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; import 'package:hub/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel { late final String devUUID; @@ -15,10 +16,10 @@ class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel initDB() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; - cliName = StorageUtil().cliName; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; } @override 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 dcd91556..1c73a4d8 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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -31,9 +32,9 @@ class AccessNotificationModalTemplateComponentModel } Future initDB() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } @override 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 f727fc2c..23bfaa8d 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,7 +3,8 @@ 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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -27,6 +28,8 @@ class PassKeyTemplateWidget extends StatefulWidget { class _PassKeyTemplateWidgetState extends State { late PassKeyTemplateComponentModel _model; + late String _accessPass = ''; + @override void setState(VoidCallback callback) { super.setState(callback); @@ -41,6 +44,12 @@ class _PassKeyTemplateWidgetState extends State { _model.keyTextFieldTextController1 ??= TextEditingController(); _model.keyTextFieldFocusNode1 ??= FocusNode(); _model.keyTextFieldFocusNode1!.addListener(() => setState(() {})); + + _initialize(); + } + + Future _initialize() async { + _accessPass = await StorageHelper.instance.get(SecureStorageKey.accessPass.value, Storage.SecureStorage) ?? ''; } @override @@ -124,7 +133,7 @@ class _PassKeyTemplateWidgetState extends State { child: Text( FFLocalizations.of(context).getVariableText( enText: 'INSERT PASSWORD', - ptText: StorageUtil().accessPass != '' ? 'ALTERAR SENHA' : 'ADICIONAR SENHA', + ptText: _accessPass != '' ? 'ALTERAR SENHA' : 'ADICIONAR SENHA', ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Outfit', @@ -287,8 +296,8 @@ class _PassKeyTemplateWidgetState extends State { context.pop(true); }, text: FFLocalizations.of(context).getVariableText( - ptText: StorageUtil().accessPass != '' ? 'Alterar' : 'Adicionar', - enText: StorageUtil().accessPass != '' ? 'Change' : 'Add', + ptText: _accessPass != '' ? 'Alterar' : 'Adicionar', + enText: _accessPass != '' ? 'Change' : 'Add', ), options: FFButtonOptions( width: 270.0, 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 86a9bc1d..608d447e 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,7 +1,8 @@ import 'package:flutter/material.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/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class LiberationHistoryItemDetailsTemplateComponentModel extends FlutterFlowModel { @@ -26,9 +27,9 @@ class LiberationHistoryItemDetailsTemplateComponentModel void initState(BuildContext context) {} Future initDatabase() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? '';; } @override 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 708ab789..cd779405 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,7 +2,8 @@ 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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class ScheduleProvisionalVisitPageModel extends FlutterFlowModel { String cliUUID = ''; @@ -131,11 +132,11 @@ class ScheduleProvisionalVisitPageModel extends FlutterFlowModel init() async { - cliUUID = StorageUtil().cliUUID; - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliName = StorageUtil().cliName; - ownerUUID = StorageUtil().ownerUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? '';; + cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + ownerUUID = (await StorageHelper.instance.get(SQLiteStorageKey.ownerUUID.value, Storage.SQLiteStorage)) ?? ''; 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 91c3487f..5717f098 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 @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:cached_network_image/cached_network_image.dart'; import 'package:easy_debounce/easy_debounce.dart'; import 'package:flutter/material.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 cd74c245..101f9f3b 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,8 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/backend/api_requests/api_calls.dart'; @@ -128,9 +129,9 @@ class RegisiterVistorTemplateComponentModel extends FlutterFlowModel initializeDatabase() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? '';; } @override 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 476cec88..709cdbba 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,7 +4,8 @@ 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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/flutter_flow/flutter_flow_animations.dart'; @@ -26,6 +27,7 @@ class SignUpTemplateComponentWidget extends StatefulWidget { class _SignUpTemplateComponentWidgetState extends State with TickerProviderStateMixin { late SignUpTemplateComponentModel _model; final animationsMap = {}; + late String _deviceType; @override void setState(VoidCallback callback) { @@ -83,6 +85,12 @@ class _SignUpTemplateComponentWidgetState extends State _initialize() async { + _deviceType = (await StorageHelper.instance.get(SecureStorageKey.deviceType.value, Storage.SecureStorage)) ?? ''; } @override @@ -96,7 +104,6 @@ class _SignUpTemplateComponentWidgetState extends State { } Future initializeDatabase() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? '';; } @override 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 8902a477..9e9b85c4 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 @@ -2,7 +2,8 @@ import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel { late final String devUUID; @@ -34,9 +35,9 @@ class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel initDatabase() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? '';; } @override diff --git a/lib/flutter_flow/flutter_flow_util.dart b/lib/flutter_flow/flutter_flow_util.dart index 09a7b7f9..66c13b4f 100644 --- a/lib/flutter_flow/flutter_flow_util.dart +++ b/lib/flutter_flow/flutter_flow_util.dart @@ -24,7 +24,6 @@ export 'dart:typed_data' show Uint8List; export 'package:intl/intl.dart'; export 'package:page_transition/page_transition.dart'; -export '/app_state.dart'; export 'custom_icons.dart' show FFIcons; export 'flutter_flow_model.dart'; export 'internationalization.dart' show FFLocalizations; diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 366f0ece..bc7d2897 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -12,8 +12,9 @@ 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/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; import '../../shared/utils/dialog_util.dart'; @@ -41,12 +42,18 @@ class AppStateNotifier extends ChangeNotifier { } } +initializeRouter() async { + final bool isLogged = await StorageHelper.instance.get(SecureStorageKey.isLogged.value, Storage.SecureStorage) == 'true'; + final bool? haveLocal = await StorageHelper.instance.get(SecureStorageKey.haveLocal.value, Storage.SecureStorage) == 'true';; + final bool haveUserUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? false; + final bool haveDevUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? false; +} + GoRouter createRouter(AppStateNotifier appStateNotifier) { - final bool isLogged = StorageUtil().isLogged; - final bool? haveLocal = StorageUtil().haveLocal; - final bool haveUserUUID = StorageUtil().userUUID.isNotEmpty; - final bool haveDevUUID = StorageUtil().devUUID.isNotEmpty; - final bool isRecovered = StorageUtil().isRecovered; + final bool isLogged = await StorageHelper.instance.get(SecureStorageKey.isLogged.value, Storage.SecureStorage) == 'true'; + final bool? haveLocal = await StorageHelper.instance.get(SecureStorageKey.haveLocal.value, Storage.SecureStorage) == 'true';; + final bool haveUserUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? false; + final bool haveDevUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? false; log('() => isLogged: $isLogged'); log('() => haveLocal: $haveLocal'); diff --git a/lib/main.dart b/lib/main.dart index 223bcb2f..95926c0f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,10 +18,10 @@ 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/forgot_password_page/forgot_password_screen.dart'; -import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:hub/shared/utils/device_util.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'package:responsive_framework/responsive_framework.dart'; final GlobalKey navigatorKey = GlobalKey(); @@ -35,7 +35,7 @@ void main() async { Future initializeApp() async { WidgetsFlutterBinding.ensureInitialized(); await _initializeTracking(); - await _initializeStorageHelpers(); + await StorageHelper.instance.init(); await _initializeFirebase(); await _initializeNotificationService(); @@ -44,13 +44,6 @@ Future initializeApp() async { await _initializeFlutterFlow(); } -Future _initializeStorageHelpers() async { - log('Initializing SharedPreferencesStorageHelper'); - await SharedPreferencesStorageHelper().initialize(); - log('Initializing SharedPreferencesStorageHelper'); - await StorageUtil().ensureInitialization(); -} - Future _initializeTracking() async { await AppTrackingTransparency.requestTrackingAuthorization(); } @@ -88,9 +81,10 @@ Future _initializeFlutterFlow() async { Future _foregroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - StorageUtil().haveLocal = true; - StorageUtil().context?.go('/homePage'); + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + StorageHelper.instance.context?.go('/homePage'); } + if (!Platform.isIOS) { NotificationService.show( title: message.notification!.title!, @@ -101,9 +95,8 @@ Future _foregroundHandlerMessage(RemoteMessage message) async { Future _backgroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - log('backgroundHandlerMessage'); - StorageUtil().haveLocal = true; - StorageUtil().context?.go('/homePage'); + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + StorageHelper.instance.context?.go('/homePage'); } } @@ -187,23 +180,21 @@ class _AppState extends State with WidgetsBindingObserver { Future initDeepLinks() async { _appLinks = AppLinks(); _linkSubscription = _appLinks.uriLinkStream.listen((uri) { - final bool isRecovered = StorageUtil().isRecovered; + final bool isRecovered = StorageHelper.instance.isRecovered; if (!isRecovered) openAppLink(uri); }); } void openAppLink(Uri uri) { - final bool isRecovered = StorageUtil().isRecovered; + final bool isRecovered = StorageHelper.instance.isRecovered; log('isRecovered: $isRecovered'); if (isRecovered) return; - StorageUtil().isRecovered = true; + StorageHelper.instance.isRecovered = true; final String email = uri.queryParameters['email'] ?? ''; final String token = uri.queryParameters['token'] ?? ''; final bool isNotEmpty = email.isNotEmpty && token.isNotEmpty; if (isNotEmpty) { - final BuildContext context = StorageUtil().context!; - final MediaQueryData mediaQuery = MediaQuery.of(context); - final double height = mediaQuery.size.height * 0.6; + final BuildContext context = StorageHelper.instance.context!; final FlutterFlowTheme theme = FlutterFlowTheme.of(context); final Widget screen = ForgotPasswordScreen(email: email, token: token); builder(context) => screen; @@ -217,7 +208,7 @@ class _AppState extends State with WidgetsBindingObserver { useSafeArea: true, enableDrag: true, // isDismissible: true, - ).whenComplete(() => StorageUtil().isRecovered = false); + ).whenComplete(() => StorageHelper.instance.isRecovered = false); } } @@ -230,18 +221,18 @@ class _AppState extends State with WidgetsBindingObserver { } FirebaseMessaging.onMessage.listen(_foregroundHandlerMessage); - FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { + FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - StorageUtil().haveLocal = true; + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); log('onMessageOpenedApp'); } else { onMessageReceived(message.data, message.notification!.body, message.data['click_action']); } }); - FirebaseMessaging.instance.getInitialMessage().then((message) { + FirebaseMessaging.instance.getInitialMessage().then((message) async { if (message != null) { if (message.data['click_action'] == 'enroll_cond') { - StorageUtil().haveLocal = true; + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); log('getInitialMessage'); } } @@ -286,8 +277,7 @@ class _AppState extends State with WidgetsBindingObserver { @override void didChangeAppLifecycleState(AppLifecycleState state) async { - bool initialize = await StorageUtil().ensureInitialization(); - if (initialize) await LocalizationService.processLocals(context); + await LocalizationService.processLocals(context); } @override 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 fe1307e5..bdb3b1b1 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -4,7 +4,8 @@ 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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class AcessHistoryPageModel extends FlutterFlowModel { late final String devUUID; @@ -32,9 +33,9 @@ class AcessHistoryPageModel extends FlutterFlowModel { } Future initDatabase() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } @override 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 04ebc5cc..bd7aa6e6 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,8 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart' as hub; +import 'package:hub/shared/helpers/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'; @@ -22,11 +23,11 @@ class _FastPassPageWidgetState extends State { late InAppWebViewController _controllerIOS; Future> initVariables() async { - final email = StorageUtil().email; - final name = StorageUtil().userName; - final userUUID = StorageUtil().userUUID; - final devUUID = StorageUtil().devUUID; - final cliUUID = StorageUtil().cliUUID; + final email = (await StorageHelper.instance.get(hub.SecureStorageKey.email.value, hub.Storage.SecureStorage)) ?? ''; + final name = (await StorageHelper.instance.get(hub.SQLiteStorageKey.userName.value, hub.Storage.SQLiteStorage)) ?? ''; + final devUUID = (await StorageHelper.instance.get(hub.SQLiteStorageKey.devUUID.value, hub.Storage.SQLiteStorage)) ?? ''; + final userUUID = (await StorageHelper.instance.get(hub.SQLiteStorageKey.userUUID.value, hub.Storage.SQLiteStorage)) ?? ''; + final cliUUID = (await StorageHelper.instance.get(hub.SQLiteStorageKey.clientUUID.value, hub.Storage.SQLiteStorage)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; final freUserData = diff --git a/lib/pages/forgot_password_page/forgot_password_screen.dart b/lib/pages/forgot_password_page/forgot_password_screen.dart index 219b30e9..afe231c2 100644 --- a/lib/pages/forgot_password_page/forgot_password_screen.dart +++ b/lib/pages/forgot_password_page/forgot_password_screen.dart @@ -3,9 +3,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; -import '../../components/atomic_components/shared_components_atoms/atom_image_svg_theme.dart'; import '../../flutter_flow/flutter_flow_animations.dart'; import '../../flutter_flow/flutter_flow_icon_button.dart'; import '../../flutter_flow/flutter_flow_model.dart'; @@ -13,7 +12,6 @@ import '../../flutter_flow/flutter_flow_theme.dart'; import '../../flutter_flow/flutter_flow_widgets.dart'; import '../../flutter_flow/internationalization.dart'; import '../../shared/services/authentication/authentication_service.dart'; -import '../../shared/utils/validator_util.dart'; import 'forgot_password_model.dart'; class ForgotPasswordScreen extends StatefulWidget { @@ -112,7 +110,7 @@ class _ForgotPasswordScreenState extends State with Ticker ), onPressed: () async { context.pop(); - StorageUtil().isRecovered = false; + StorageHelper.instance.isRecovered = false; }, ), title: Text( diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index 5af90cfc..ce206c32 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -4,7 +4,8 @@ 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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class HomePageModel extends FlutterFlowModel { bool isGrid = false; @@ -23,11 +24,11 @@ class HomePageModel extends FlutterFlowModel { late MessageWellComponentModel messageWellComponentModel; Future _initVariable() async { - devUUID = StorageUtil().devUUID; - cliUUID = StorageUtil().cliUUID; - userUUID = StorageUtil().userUUID; - userName = StorageUtil().userName; - userEmail = StorageUtil().email; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + userName = (await StorageHelper.instance.get(SQLiteStorageKey.userName.value, Storage.SQLiteStorage)) ?? ''; + userEmail = (await StorageHelper.instance.get(SecureStorageKey.email.value, Storage.SecureStorage)) ?? ''; } @override diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index 5e32386c..889263ec 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -9,7 +9,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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart'; class HomePageWidget extends StatefulWidget { @@ -50,7 +50,7 @@ class _HomePageWidgetState extends State { @override Widget build(BuildContext context) { - StorageUtil().context = context; + StorageHelper.instance.context = context; return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index ab7f61f4..1757239e 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -3,7 +3,8 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class LiberationHistoryModel extends FlutterFlowModel { late final String devUUID; @@ -35,9 +36,9 @@ class LiberationHistoryModel extends FlutterFlowModel { } Future init() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } Future answersRequest( 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 ca0efca3..1ff3ca7c 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -3,7 +3,8 @@ 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:hub/pages/message_history_page/message_history_page_widget.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; class MessageHistoryPageModel extends FlutterFlowModel { late final String devUUID; @@ -38,9 +39,9 @@ class MessageHistoryPageModel extends FlutterFlowModel } Future init() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } @override diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index 372e655e..c5c78c66 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -9,9 +9,10 @@ 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/base_storage.dart'; +import 'package:hub/shared/helpers/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'; @@ -62,7 +63,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = StorageUtil().cliUUID; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } @override @@ -215,8 +216,6 @@ class _PackageOrderPage extends State { } PreferredSizeWidget _appBar(BuildContext context) { - double screenWidth = MediaQuery.of(context).size.width; - double screenHeight = MediaQuery.of(context).size.height; return AppBar( 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 d4fe0614..1dc50ef2 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -4,9 +4,10 @@ import 'package:hub/components/templates_components/card_item_template_component import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/pets_page/pets_page_model.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/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'; class PetsHistoryScreen extends StatefulWidget { const PetsHistoryScreen({super.key, required this.model}); @@ -231,10 +232,10 @@ class _PetsHistoryScreenState extends State with TickerProvid } ], onTapCardItemAction: () async { - final cliUUID = StorageUtil().cliUUID; - final cliName = StorageUtil().cliName; - final devUUID = StorageUtil().devUUID; - final userUUID = StorageUtil().userUUID; + final devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; 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 020e7946..16981f6c 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -12,9 +12,10 @@ 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/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/image_util.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; class PetsPageModel extends FlutterFlowModel { @@ -101,10 +102,10 @@ class PetsPageModel extends FlutterFlowModel { String? Function(BuildContext, String?)? textControllerObservationValidator; Future initAsync() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; - petAmountRegister = StorageUtil().petAmountRegister.toString(); + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + petAmountRegister = (await StorageHelper.instance.get(SQLiteStorageKey.petAmount.value, Storage.SQLiteStorage)) ?? ''; 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 36ffd920..1c3bb3e9 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -5,11 +5,10 @@ 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_util.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/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'package:share_plus/share_plus.dart'; import '../../shared/utils/snackbar_util.dart'; @@ -17,16 +16,28 @@ import '../../shared/utils/snackbar_util.dart'; class PreferencesPageModel with ChangeNotifier { final unfocusNode = FocusNode(); - PreferencesPageModel() { - initVariables(); - } - Future initVariables() async { + late bool isFingerprint = false; + late bool isPerson = false; + late bool isNotify = false; + late bool isAccess = false; + late bool isPanic = false; + + Future _initialize() async { + isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; + isPerson = await StorageHelper.instance.get(SQLiteStorageKey.person.value, Storage.SQLiteStorage) == 'true'; + isNotify = await StorageHelper.instance.get(SQLiteStorageKey.notify.value, Storage.SQLiteStorage) == 'true'; + isAccess = await StorageHelper.instance.get(SQLiteStorageKey.access.value, Storage.SQLiteStorage) == 'true'; + isPanic = await StorageHelper.instance.get(SQLiteStorageKey.panic.value, Storage.SQLiteStorage) == 'true'; notifyListeners(); } + PreferencesPageModel() { + _initialize(); + } + Future enablePerson(BuildContext context) async { - final String userDevUUID = StorageUtil().userDevUUID; + final String userDevUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( @@ -47,10 +58,11 @@ class PreferencesPageModel with ChangeNotifier { ); onConfirm() async { String content; - String value = StorageUtil().notify ? 'N' : 'S'; + isNotify = await StorageHelper.instance.get(SQLiteStorageKey.notify.value, Storage.SQLiteStorage) == 'true'; + String value = isNotify ? 'N' : 'S'; await PhpGroup.changeNotifica.call(notifica: value).then((value) async { if (value.jsonBody['error'] == false) { - StorageUtil().notify = !StorageUtil().notify; + await StorageHelper.instance.set(SQLiteStorageKey.notify.value, isNotify ? 'false' : 'true',Storage.SQLiteStorage); notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Notification changed successfully', @@ -80,15 +92,15 @@ class PreferencesPageModel with ChangeNotifier { Future toggleAccess(BuildContext context) async { onChange(String key) async { - StorageUtil().accessPass = key; - await PhpGroup.changePass - .call( - newSenha: key, - ) - .then((value) async { + await StorageHelper.instance.set(SecureStorageKey.accessPass.value, key, Storage.SecureStorage); + isAccess = await StorageHelper.instance.get(SQLiteStorageKey.access.value, Storage.SQLiteStorage) == 'true'; + + await PhpGroup.changePass.call(newSenha: key).then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - if (!StorageUtil().access) StorageUtil().access = !StorageUtil().access; + if (!isAccess) { + await StorageHelper.instance.set(SQLiteStorageKey.access.value, isAccess ? 'false' : 'true', Storage.SQLiteStorage); + } notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Access pass changed successfully', @@ -116,15 +128,16 @@ class PreferencesPageModel with ChangeNotifier { Future togglePanic(BuildContext context) async { onChange(String key) async { - StorageUtil().panicPass = key; + await StorageHelper.instance.set(SecureStorageKey.panicPass.value, key, Storage.SecureStorage); + isPanic = await StorageHelper.instance.get(SQLiteStorageKey.panic.value, Storage.SQLiteStorage) == 'true'; await PhpGroup.changePanic - .call( - newSenhaPanico: StorageUtil().panicPass, - ) + .call(newSenhaPanico: key) .then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - if (!StorageUtil().panic) StorageUtil().panic = !StorageUtil().panic; + if (!isPanic) { + await StorageHelper.instance.set(SQLiteStorageKey.panic.value, isPanic ? 'false' : 'true', Storage.SQLiteStorage); + } notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Panic password changed successfully', @@ -156,17 +169,21 @@ class PreferencesPageModel with ChangeNotifier { ptText: 'ImpressĂ£o digital alterada com sucesso', ); + isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; + onChange(String? key) async { - StorageUtil().fingerprint = !StorageUtil().fingerprint; - if (!StorageUtil().fingerprint) StorageUtil().fingerprintPass = key ?? ''; - if (StorageUtil().fingerprint) StorageUtil().fingerprintPass = ''; + isFingerprint = !isFingerprint; + + await StorageHelper.instance.set(SecureStorageKey.fingerprintPass.value, isFingerprint ? '' : key ?? '', Storage.SecureStorage); + + isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; notifyListeners(); SnackBarUtil.showSnackBar(context, content); } - StorageUtil().fingerprint ? onChange(null) : _showPassKey(context, onChange); + isFingerprint ? onChange(null) : _showPassKey(context, onChange); } Future deleteAccount(BuildContext context) async { diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index 25b9c3a3..3f58e2c7 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; @@ -5,7 +7,8 @@ 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/preferences_settings_page/preferences_settings_model.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:provider/provider.dart'; class PreferencesPageWidget extends StatefulWidget { @@ -16,6 +19,7 @@ class PreferencesPageWidget extends StatefulWidget { } class _PreferencesPageWidgetState extends State { + @override void initState() { super.initState(); @@ -101,7 +105,7 @@ class _PreferencesPageWidgetState extends State { case 0: icon = Icons.fingerprint; onPressed = () => model.toggleFingerprint(context); - isEnabled = StorageUtil().fingerprint; + isEnabled = model.isFingerprint; content = FFLocalizations.of(context).getVariableText( ptText: 'Ative a autenticaĂ§Ă£o por impressĂ£o digital para login seguro.', enText: 'Enable fingerprint authentication for secure login.', @@ -110,7 +114,7 @@ class _PreferencesPageWidgetState extends State { case 1: icon = Icons.person; onPressed = () => model.enablePerson(context); - isEnabled = StorageUtil().person; + isEnabled = model.isPerson; content = FFLocalizations.of(context).getVariableText( ptText: 'Compartilhe o cĂ³digo de identificaĂ§Ă£o remota', enText: 'Share the remote identification code', @@ -119,7 +123,7 @@ class _PreferencesPageWidgetState extends State { case 2: icon = Icons.notifications; onPressed = () => model.toggleNotify(context); - isEnabled = StorageUtil().notify; + isEnabled = model.isNotify; content = FFLocalizations.of(context).getVariableText( ptText: 'Ative para receber sua notificaĂ§Ă£o de acesso', enText: 'Enable to receive your access notification', @@ -128,7 +132,7 @@ class _PreferencesPageWidgetState extends State { case 3: icon = Icons.lock; onPressed = () => model.toggleAccess(context); - isEnabled = StorageUtil().access; + isEnabled = model.isAccess; content = FFLocalizations.of(context).getVariableText( ptText: 'Ative para inserir uma credencial de acesso para o QRCode', enText: 'Enable to enter an access credential for the QRCode', @@ -137,7 +141,7 @@ class _PreferencesPageWidgetState extends State { case 4: icon = Icons.lock_clock_sharp; onPressed = () => model.togglePanic(context); - isEnabled = StorageUtil().panic; + isEnabled = model.isPanic; content = FFLocalizations.of(context).getVariableText( ptText: 'Ative para inserir uma credencial de pĂ¢nico para o QRCode', enText: 'Enable to enter a panic credential for the QRCode', 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 81bf7cc1..67af265c 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -4,7 +4,8 @@ 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/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:qr_flutter/qr_flutter.dart'; class QrCodePageModel extends FlutterFlowModel { @@ -28,8 +29,8 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = StorageUtil().fingerprint; - userDevUUID = StorageUtil().userDevUUID; + isFingerprint = await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; + userDevUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; } @override @@ -79,7 +80,6 @@ class QrCodePageModel extends FlutterFlowModel { packet.add(check); } - var bytes = packet.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join((' ')); return Uint8List.fromList(packet); } 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 8a116e1c..78ad964b 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -14,9 +14,10 @@ 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/base_storage.dart'; +import 'package:hub/shared/helpers/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:qr_flutter/qr_flutter.dart'; @@ -330,13 +331,13 @@ class _QrCodePageWidgetState extends State with TickerProvider Future _showBiometricsAuth(BuildContext context) async { BiometricHelper.checkBiometrics() .then((value) => BiometricHelper.authenticateBiometric().then((value) { - safeSetState(() { + safeSetState(() async { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { animationsMap['barcodeOnActionTriggerAnimation']!.controller.stop(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.reverse(); } _model.isAccess = !_model.isAccess; - _model.key = StorageUtil().fingerprintPass; + _model.key = (await StorageHelper.instance.get(SecureStorageKey.fingerprintPass.value, Storage.SecureStorage)) ?? ''; }); })) .onError((error, StackTrace) { diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index 0c99841c..9cc67c08 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final String userDevUUID = StorageUtil().userDevUUID; + final String userDevUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; notifyListeners(); Share.share( diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 600ab56b..f46dec51 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -11,8 +11,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/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; class ReceptionPageWidget extends StatefulWidget { @@ -54,7 +55,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB @override Widget build(BuildContext context) { - StorageUtil().context = context; + StorageHelper.instance.context = context; return ChangeNotifierProvider( create: (context) => ReceptionPageModel(), child: Scaffold( @@ -157,7 +158,8 @@ class _ReceptionPageWidgetState extends State with WidgetsB onPressed: () async { PhpGroup.unregisterDevice(); - StorageUtil.purge(); + StorageHelper.instance.clearAll(Storage.SecureStorage); + setState(() {}); context.go( diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index e083e070..3327a521 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -5,7 +5,8 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart' as hub; +import 'package:hub/shared/helpers/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'; @@ -21,12 +22,12 @@ class _ReservationPageWidgetState extends State { late WebViewController _controllerAll; Future> initVariables() async { - 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 email = (await StorageHelper.instance.get(hub.SecureStorageKey.email.value, hub.Storage.SecureStorage)) ?? ''; + final name = (await StorageHelper.instance.get(hub.SQLiteStorageKey.userName.value, hub.Storage.SQLiteStorage)) ?? ''; + final devUUID = (await StorageHelper.instance.get(hub.SQLiteStorageKey.devUUID.value, hub.Storage.SQLiteStorage)) ?? ''; + final userUUID = (await StorageHelper.instance.get(hub.SQLiteStorageKey.userUUID.value, hub.Storage.SQLiteStorage)) ?? ''; + final clientId = (await StorageHelper.instance.get(hub.SQLiteStorageKey.clientUUID.value, hub.Storage.SQLiteStorage)) ?? ''; + const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; 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 6e7c3d7a..421f2453 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 @@ -8,8 +8,9 @@ import 'package:hub/flutter_flow/form_field_controller.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/mixins/status_mixin.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import 'package:share_plus/share_plus.dart'; import '../../shared/utils/validator_util.dart'; @@ -213,9 +214,9 @@ class ScheduleCompleteVisitPageModel extends FlutterFlowModel } Future _initVariables() async { - devUUID = StorageUtil().devUUID; - cliUUID = StorageUtil().cliUUID; - userUUID = StorageUtil().userUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } @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 db5c6795..35d2aada 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,10 +5,11 @@ 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/base_storage.dart'; +import 'package:hub/shared/helpers/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 { @@ -33,9 +34,9 @@ class _VisitHistoryWidgetState extends State with TickerProv List _visitWrap = []; Future _initVariables() async { - devUUID = StorageUtil().devUUID; - userUUID = StorageUtil().userUUID; - cliUUID = StorageUtil().cliUUID; + devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; } @override @@ -232,10 +233,10 @@ class _VisitHistoryWidgetState extends State with TickerProv }, ], onTapCardItemAction: () async { - final cliUUID = StorageUtil().cliUUID; - final cliName = StorageUtil().cliName; - final devUUID = StorageUtil().devUUID; - final userUUID = StorageUtil().userUUID; + final devUUID = (await StorageHelper.instance.get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final userUUID = (await StorageHelper.instance.get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; await showDialog( useSafeArea: true, diff --git a/lib/pages/sign_in_page/sign_in_page_widget.dart b/lib/pages/sign_in_page/sign_in_page_widget.dart index a826572e..4a706f36 100644 --- a/lib/pages/sign_in_page/sign_in_page_widget.dart +++ b/lib/pages/sign_in_page/sign_in_page_widget.dart @@ -1,6 +1,6 @@ +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/mixins/switcher_mixin.dart'; -import '../../shared/utils/storage_util.dart'; import '/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -35,7 +35,7 @@ class _SignInPageWidgetState extends State { @override Widget build(BuildContext context) { - StorageUtil().context = context; + StorageHelper.instance.context = context; return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/pages/sign_up_page/sign_up_page_widget.dart b/lib/pages/sign_up_page/sign_up_page_widget.dart index bb786c31..1055cb1c 100644 --- a/lib/pages/sign_up_page/sign_up_page_widget.dart +++ b/lib/pages/sign_up_page/sign_up_page_widget.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/mixins/switcher_mixin.dart'; -import '../../shared/utils/storage_util.dart'; import '/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -36,7 +36,7 @@ class _SignUpPageWidgetState extends State { @override Widget build(BuildContext context) { - StorageUtil().context = context; + StorageHelper.instance.context = context; return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/pages/welcome_page/welcome_page_widget.dart b/lib/pages/welcome_page/welcome_page_widget.dart index 9434aacf..7cfb6c35 100644 --- a/lib/pages/welcome_page/welcome_page_widget.dart +++ b/lib/pages/welcome_page/welcome_page_widget.dart @@ -1,11 +1,8 @@ -import 'dart:async'; -import 'dart:developer'; - -import 'package:app_links/app_links.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/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'; @@ -34,13 +31,13 @@ class _WelcomePageWidgetState extends State { // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { if (isAndroid == true) { - StorageUtil().deviceType = 'Android'; + await StorageHelper.instance.set(SecureStorageKey.deviceType.value, 'Android', Storage.SecureStorage); setState(() {}); } else if (isiOS == true) { - StorageUtil().deviceType = 'iOS'; + await StorageHelper.instance.set(SecureStorageKey.deviceType.value, 'iOS', Storage.SecureStorage); setState(() {}); } else { - StorageUtil().deviceType = 'Web'; + await StorageHelper.instance.set(SecureStorageKey.deviceType.value, 'Web', Storage.SecureStorage); setState(() {}); } }); @@ -55,7 +52,7 @@ class _WelcomePageWidgetState extends State { @override Widget build(BuildContext context) { - StorageUtil().context = context; + StorageHelper.instance.context = context; return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/shared/helpers/base_storage.dart b/lib/shared/helpers/base_storage.dart new file mode 100644 index 00000000..37530a13 --- /dev/null +++ b/lib/shared/helpers/base_storage.dart @@ -0,0 +1,144 @@ +abstract class BaseStorage { + + Future init(); + + Future set(String key, String value); + + Future get(String key); + + Future delete(String key); + + Future clearAll(); +} + +enum Storage { + SecureStorage, + SharedPreferences, + SQLiteStorage, +} + +enum SharedPreferencesKey { + isFirstRun, +} + +extension SharedPreferencesKeyExtension on SharedPreferencesKey { + String get value { + switch (this) { + case SharedPreferencesKey.isFirstRun: + return 'fre_isFirstRun'; + default: + return ''; + } + } +} + +enum SecureStorageKey { + isLogged, + email, + password, + deviceType, + token, + accessPass, + panicPass, + fingerprintPass, + haveLocal, + deviceDescription, +} + +extension SecureStorageKeyExtension on SecureStorageKey { + String get value { + switch (this) { + case SecureStorageKey.isLogged: + return 'fre_isLogged'; + case SecureStorageKey.email: + return 'fre_email'; + case SecureStorageKey.password: + return 'fre_passwd'; + case SecureStorageKey.deviceType: + return 'fre_deviceType'; + case SecureStorageKey.token: + return 'fre_token'; + case SecureStorageKey.accessPass: + return 'fre_accessPass'; + case SecureStorageKey.panicPass: + return 'fre_panicPass'; + case SecureStorageKey.fingerprintPass: + return 'fre_fingerprintPass'; + case SecureStorageKey.haveLocal: + return 'fre_have_local'; + case SecureStorageKey.deviceDescription: + return 'fre_deviceDescription'; + default: + return ''; + } + } +} + +enum SQLiteStorageKey { + devUUID, + userUUID, + userDevUUID, + status, + userName, + clientUUID, + ownerUUID, + clientName, + petAmount, + whatsapp, + provisional, + pets, + local, + notify, + fingerprint, + access, + panic, + person, + requestOSNotification, +} + +extension SQLIteStorageKeyExtension on SQLiteStorageKey { + String get value { + switch (this) { + case SQLiteStorageKey.devUUID: + return 'fre_devUUID'; + case SQLiteStorageKey.userUUID: + return 'fre_userUUID'; + case SQLiteStorageKey.userDevUUID: + return 'fre_userDevUUID'; + case SQLiteStorageKey.status: + return 'fre_status'; + case SQLiteStorageKey.userName: + return 'fre_userName'; + case SQLiteStorageKey.clientUUID: + return 'fre_cliUUID'; + case SQLiteStorageKey.ownerUUID: + return 'fre_ownerUUID'; + case SQLiteStorageKey.clientName: + return 'fre_cliName'; + case SQLiteStorageKey.petAmount: + return 'fre_petAmountRegister'; + case SQLiteStorageKey.whatsapp: + return 'fre_whatsapp'; + case SQLiteStorageKey.provisional: + return 'fre_provisional'; + case SQLiteStorageKey.pets: + return 'fre_pets'; + case SQLiteStorageKey.local: + return 'fre_local'; + case SQLiteStorageKey.notify: + return 'fre_notify'; + case SQLiteStorageKey.fingerprint: + return 'fre_fingerprint'; + case SQLiteStorageKey.access: + return 'fre_access'; + case SQLiteStorageKey.panic: + return 'fre_panic'; + case SQLiteStorageKey.person: + return 'fre_person'; + case SQLiteStorageKey.requestOSNotification: + return 'fre_requestOSnotification'; + default: + return ''; + } + } +} \ No newline at end of file diff --git a/lib/shared/helpers/secure_storage.dart b/lib/shared/helpers/secure_storage.dart new file mode 100644 index 00000000..9f3dd979 --- /dev/null +++ b/lib/shared/helpers/secure_storage.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; + +class SecureStorage extends ChangeNotifier implements BaseStorage { + + SecureStorage._(); + + static final SecureStorage instance = SecureStorage._(); + + late final FlutterSecureStorage _secureStorage; + + @override + Future init() async { + _secureStorage = const FlutterSecureStorage(); + } + + @override + Future get(String key) async { + return await _secureStorage.read(key: key); + } + + @override + Future set(String key, String value) async { + await _secureStorage.write(key: key, value: value); + notifyListeners(); + } + + @override + Future delete(String key) async { + await _secureStorage.delete(key: key); + notifyListeners(); + } + + @override + Future clearAll() async { + await _secureStorage.deleteAll(); + notifyListeners(); + } + +} \ No newline at end of file diff --git a/lib/shared/helpers/secure_storage_helper.dart b/lib/shared/helpers/secure_storage_helper.dart deleted file mode 100644 index 7e483bde..00000000 --- a/lib/shared/helpers/secure_storage_helper.dart +++ /dev/null @@ -1,110 +0,0 @@ -import 'dart:developer'; - -import 'package:flutter/material.dart'; -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:hub/shared/utils/cache_util.dart'; -import 'package:hub/shared/utils/storage_util.dart'; - -class SecureStorageHelper extends ChangeNotifier implements Storage { - static final SecureStorageHelper _instance = SecureStorageHelper._internal(); - final FlutterSecureStorage _secureStorage = const FlutterSecureStorage(); - - factory SecureStorageHelper() => _instance; - - SecureStorageHelper._internal(); - - static SecureStorageHelper get instance => _instance; - - Future setAndCacheString(String key, String value, Function(String) cacheSetter) async { - log('SecureStorageHelper -> setAndCacheString value for key: $key to $value'); - await _secureStorage.write(key: key, value: value); - CacheUtil.instance.set(key, value); - cacheSetter(value); - } - - Future setAndCacheBool(String key, bool value, Function(bool) cacheSetter) async { - log('SecureStorageHelper -> 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('SecureStorageHelper -> 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 { - var value = CacheUtil.instance.get(key); - if (value == null) { - value = await _secureStorage.read(key: key); - CacheUtil.instance.set(key, value); - } - log('SecureStorageHelper -> getString $value for key: $key'); - return value; - } - - Future getBool(String key) async { - var value = CacheUtil.instance.get(key); - if (value == null || value == 'null') { - value = await _secureStorage.read(key: key); - CacheUtil.instance.set(key, value); - log('SecureStorageHelper -> getBool $value for key: $key'); - return value == 'true'; - } - log('SecureStorageHelper -> getBool $value for key: $key'); - return value == 'true' || value == true; - } - - Future getObject(String key) async { - var value = CacheUtil.instance.get(key); - if (value == null) { - value = await _secureStorage.read(key: key); - CacheUtil.instance.set(key, value); - } - log('SecureStorageHelper -> getObject $value for key: $key'); - return value as BuildContext?; - } - - @override - Future set(String key, dynamic value, Function(dynamic) cacheSetter) async { - if (value is String? || value is String) { - await setAndCacheString(key, value!, cacheSetter); - } else if (value is bool? || value is bool) { - await setAndCacheBool(key, value, cacheSetter); - } else if (value is BuildContext || value is BuildContext?) { - await setAndCacheObject(key, value.toString(), cacheSetter); - } - } - - @override - Future get(String key) async { - log('SecureStorageHelper -> get value for 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 { - log('SecureStorageHelper -> delete value for key: $key'); - await _secureStorage.delete(key: key); - CacheUtil.instance.delete(key); - } - - Future purge() async { - log('SecureStorageHelper -> Purging secure storage'); - await _secureStorage.deleteAll(); - - CacheUtil.instance.clear(); - } -} diff --git a/lib/shared/helpers/shared_preferences_storage.dart b/lib/shared/helpers/shared_preferences_storage.dart new file mode 100644 index 00000000..9e02ad33 --- /dev/null +++ b/lib/shared/helpers/shared_preferences_storage.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class SharedPreferencesStorage extends ChangeNotifier implements BaseStorage { + + SharedPreferencesStorage._(); + + static final SharedPreferencesStorage instance = SharedPreferencesStorage._(); + + late final SharedPreferences _prefs; + + @override + Future init() async { + _prefs = await SharedPreferences.getInstance(); + } + + @override + Future get(String key) async { + return _prefs.get(key).toString(); + } + + @override + Future set(String key, String value) async { + await _prefs.setString(key, value); + notifyListeners(); + } + + @override + Future delete(String key) async { + await _prefs.remove(key); + notifyListeners(); + } + + @override + Future clearAll() async { + await _prefs.clear(); + notifyListeners(); + } + +} \ 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 deleted file mode 100644 index c7764748..00000000 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ /dev/null @@ -1,95 +0,0 @@ -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'; - -class SharedPreferencesStorageHelper implements Storage { - static final SharedPreferencesStorageHelper _instance = SharedPreferencesStorageHelper._internal(); - SharedPreferences? _prefs; - - SharedPreferences? get prefs => _prefs; - set prefs(SharedPreferences? value) => _prefs = value; - - factory SharedPreferencesStorageHelper() => _instance; - - SharedPreferencesStorageHelper._internal(); - - static SharedPreferencesStorageHelper get instance => _instance; - - Future initialize() async => _prefs = await SharedPreferences.getInstance(); - - Future _setAndCache( - String key, T value, Function(T) cacheSetter, Future Function(String, T) setFunc) async { - log('setAndCache value for key: $key to $value'); - await setFunc(key, value); - CacheUtil.instance.set(key, value); - cacheSetter(value); - } - - Future _setAndCacheString(String key, String value, Function(String) cacheSetter) async { - 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, Function(dynamic) cacheSetter) async { - if (value is bool) { - log('() => setAndCacheBool $key to $value'); - await _prefs?.setBool(key, value); - } else if (value is String) { - await _prefs?.setString(key, value); - } 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 { - 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 { - log('Deleting value for key: $key'); - await _prefs?.remove(key); - CacheUtil.instance.delete(key); - } - - @override - Future purge() async { - log('Purging shared preferences'); - await _prefs?.clear(); - CacheUtil.instance.clear(); - } -} diff --git a/lib/shared/helpers/sqlite_storage.dart b/lib/shared/helpers/sqlite_storage.dart new file mode 100644 index 00000000..d4638250 --- /dev/null +++ b/lib/shared/helpers/sqlite_storage.dart @@ -0,0 +1,133 @@ +import 'dart:developer'; + +import 'package:flutter/material.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:sqflite/sqflite.dart'; +import 'package:sqflite/sqlite_api.dart'; +import 'package:path/path.dart'; + +class SQLiteStorage extends ChangeNotifier implements BaseStorage { + + SQLiteStorage._(); + + final String _dbName = 'database.db'; + final int _dbVersion = 1; + + static final SQLiteStorage instance = SQLiteStorage._(); + + late final _database; + + @override + Future init() async { + _database = await openDatabase( + join(await getDatabasesPath(), _dbName), + version: _dbVersion, + onCreate: _onCreate, + onUpgrade: _onUpdate, + onDowngrade: _onDowngrade, + ); + + await _onInitLocalVariables(_database); + } + + _onCreate(Database database, int version) async { + await database.execute(_tableKeychain); + } + + _onUpdate(Database database, int oldVersion, int newVersion) async {} + + _onDowngrade(Database database, int oldVersion, int newVersion) async {} + + _onInitLocalVariables(Database database) async { + // TODO: Talvez precise colocar um transaction aqui como o + // database.batch() para melhorar a performance + + for (var variable in _localVariables) { + var isConfig = await database.query('keychain', where: 'key = ?', whereArgs: [variable['key']]); + + if (isConfig.isEmpty) { + await database.insert('keychain', variable); + } + } + } + + String get _tableKeychain => ''' + CREATE TABLE keychain ( + key TEXT UNIQUE, + value TEXT, + type TEXT, + updateAt TEXT, + resolvedAt TEXT, + createdAt TEXT + ); + '''; + + List> get _localVariables => [ + {'key': SQLiteStorageKey.devUUID.value, 'value': '', 'type': 'user'}, + {'key': SQLiteStorageKey.userUUID.value, 'value': '', 'type': 'user'}, + {'key': SQLiteStorageKey.userDevUUID.value, 'value': '', 'type': 'user'}, + {'key': SQLiteStorageKey.status.value, 'value': '', 'type': 'user'}, + {'key': SQLiteStorageKey.userName.value, 'value': '', 'type': 'user'}, + {'key': SQLiteStorageKey.clientUUID.value, 'value': '', 'type': 'local'}, + {'key': SQLiteStorageKey.ownerUUID.value, 'value': '', 'type': 'local'}, + {'key': SQLiteStorageKey.clientName.value, 'value': '', 'type': 'local'}, + {'key': SQLiteStorageKey.whatsapp.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.provisional.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.pets.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.local.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.notify.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.fingerprint.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.access.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.panic.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.person.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.requestOSNotification.value, 'value': 'false', 'type': 'util'}, + {'key': SQLiteStorageKey.petAmount.value, 'value': '', 'type': 'local'}, + ]; + + @override + Future get(String key) async { + var response = await _database.query('keychain', where: 'key = ?', whereArgs: [key]); + + if (response.isEmpty) { + return null; + } + + return response.first['value']; + } + + @override + Future set(String key, String value) async { + var date = DateTime.now().toIso8601String(); + await _database.insert( + 'keychain', + { + 'key': key, + 'value': value, + 'type': 'local', + 'updateAt': date, + 'resolvedAt': date, + 'createdAt': date, + }, + conflictAlgorithm: ConflictAlgorithm.replace + ); + notifyListeners(); + } + + @override + Future delete(String key) async { + var isConfig = await _database.query('keychain', where: 'key = ?', whereArgs: [key]); + + if (isConfig.isNotEmpty) { + await _database.delete('keychain', where: 'key = ?', whereArgs: [key]); + } + + notifyListeners(); + } + + @override + Future clearAll() async { + await _database.delete('keychain'); + notifyListeners(); + } + +} \ No newline at end of file diff --git a/lib/shared/helpers/sqlite_storage_helper.dart b/lib/shared/helpers/sqlite_storage_helper.dart deleted file mode 100644 index b03ff079..00000000 --- a/lib/shared/helpers/sqlite_storage_helper.dart +++ /dev/null @@ -1,275 +0,0 @@ -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'; - -class DatabaseConfig { - static const String dbName = 'database.db'; - static const int dbVersion = 1; - - static const String tableKeychain = 'keychain'; - static const String columnKey = 'key'; - static const String columnValue = 'value'; - static const String columnType = 'type'; - 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 implements Storage { - static final SQLiteStorageHelper _instance = SQLiteStorageHelper._internal(); - static Database? _database; - static String? _databasePath; - - factory SQLiteStorageHelper() => _instance; - - SQLiteStorageHelper._internal(); - - static SQLiteStorageHelper get instance => _instance; - - Future get database 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); - log('Database path: $_databasePath'); - return _databasePath!; - } - - Future _initDatabase() async { - log('Initializing database'); - final path = await _getDatabasePath(); - return await openDatabase( - path, - version: DatabaseConfig.dbVersion, - onCreate: _onCreate, - onOpen: _onOpen, - onUpgrade: _onUpgrade, - onDowngrade: _onDowngrade, - onConfigure: _onConfigure, - ).catchError((error) { - log('Error initializing database: $error'); - throw error; - }).whenComplete(() async { - log('Database initialization complete'); - await setupLocalVariables(); - }); - } - - Future _onCreate(Database db, int version) async { - log('Creating tables...'); - await db.execute(''' - CREATE TABLE ${DatabaseConfig.tableKeychain} ( - ${DatabaseConfig.columnKey} TEXT UNIQUE, - ${DatabaseConfig.columnValue} TEXT, - ${DatabaseConfig.columnType} TEXT, - ${DatabaseConfig.columnUpdateAt} TEXT, - ${DatabaseConfig.columnResolvedAt} TEXT, - ${DatabaseConfig.columnCreatedAt} TEXT - ); - '''); - await _insertInitialData(db); - log('Tables created'); - } - - 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('Opening database'); - await _checkExistingData(db); - } - - Future _onUpgrade(Database db, int oldVersion, int newVersion) async { - log('Upgrading database from version $oldVersion to $newVersion'); - } - - Future _onDowngrade(Database db, int oldVersion, int newVersion) async { - log('Downgrading database from version $oldVersion to $newVersion'); - } - - Future _onConfigure(Database db) async { - log('Configuring database'); - } - - Future _checkExistingData(Database db) async { - log('Checking existing data'); - try { - final maps = await db.query(DatabaseConfig.tableKeychain); - log('Existing data: $maps'); - } catch (error) { - log('Error checking existing data: $error'); - } - } - - Future setupLocalVariables() async { - 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' - ]; - - 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'; - } - - @override - Future get(String key) async { - 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 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); - 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'); - return null; - } - } - - @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 database; - final data = { - DatabaseConfig.columnKey: key, - DatabaseConfig.columnValue: value.toString(), - DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), - DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), - }; - - final result = await db.insert( - DatabaseConfig.tableKeychain, - data, - conflictAlgorithm: ConflictAlgorithm.replace, - ); - log('Value $value set for key: $key with result: $result'); - return result; - } - - @override - Future delete(String key) async { - log('Deleting value for key: $key'); - final db = await database; - 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; - } - - @override - Future purge() async { - log('Purging SQLite storage'); - await deleteDatabaseDB(); - await database; - log('Database purged'); - } - - Future deleteDatabaseDB() async { - log('Deleting database'); - final path = await _getDatabasePath(); - await deleteDatabase(path); - log('Database deleted'); - _database = null; - } -} - -class SqliteStorageDelegate {} diff --git a/lib/shared/helpers/storage_helper.dart b/lib/shared/helpers/storage_helper.dart new file mode 100644 index 00000000..5339fc0d --- /dev/null +++ b/lib/shared/helpers/storage_helper.dart @@ -0,0 +1,81 @@ +import 'package:flutter/cupertino.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/secure_storage.dart'; +import 'package:hub/shared/helpers/shared_preferences_storage.dart'; +import 'package:hub/shared/helpers/sqlite_storage.dart'; + +class StorageHelper { + StorageHelper._(); + + late BuildContext? _context; + + late bool _isRecovered = false; + + static final StorageHelper instance = StorageHelper._(); + + BuildContext? get context => _context; + + set context(BuildContext? context) => _context = context; + + bool get isRecovered => _isRecovered; + + set isRecovered(bool isRecovered) => _isRecovered = isRecovered; + + Future init() async { + await SecureStorage.instance.init(); + await SharedPreferencesStorage.instance.init(); + await SQLiteStorage.instance.init(); + + String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value); + + if (isFirstRun == 'true') { + await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, 'false'); + await SecureStorage.instance.set(SecureStorageKey.isLogged.value, 'false'); + } + } + + Future get(String key, Storage storage) { + switch (storage) { + case Storage.SecureStorage: + return SecureStorage.instance.get(key); + case Storage.SharedPreferences: + return SharedPreferencesStorage.instance.get(key); + case Storage.SQLiteStorage: + return SQLiteStorage.instance.get(key); + } + } + + Future set(String key, String value, Storage storage) { + switch (storage) { + case Storage.SecureStorage: + return SecureStorage.instance.set(key, value); + case Storage.SharedPreferences: + return SharedPreferencesStorage.instance.set(key, value); + case Storage.SQLiteStorage: + return SQLiteStorage.instance.set(key, value); + } + } + + Future delete(String key, Storage storage) { + switch (storage) { + case Storage.SecureStorage: + return SecureStorage.instance.delete(key); + case Storage.SharedPreferences: + return SharedPreferencesStorage.instance.delete(key); + case Storage.SQLiteStorage: + return SQLiteStorage.instance.delete(key); + } + } + + Future clearAll(Storage storage) { + switch (storage) { + case Storage.SecureStorage: + return SecureStorage.instance.clearAll(); + case Storage.SharedPreferences: + return SharedPreferencesStorage.instance.clearAll(); + case Storage.SQLiteStorage: + return SQLiteStorage.instance.clearAll(); + } + } + +} \ No newline at end of file diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 4b262d98..010f51f6 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/snackbar_util.dart'; import '../../../backend/api_requests/api_calls.dart'; @@ -8,7 +10,6 @@ import '../../../flutter_flow/random_data_util.dart'; import '../../utils/device_util.dart'; import '../../utils/dialog_util.dart'; import '../../utils/log_util.dart'; -import '../../utils/storage_util.dart'; class AuthenticationService { static Future login(BuildContext context) async { @@ -23,13 +24,14 @@ class AuthenticationService { List locals = response.jsonBody['locais'] ?? []; if (locals.isEmpty) { - StorageUtil().haveLocal = false; + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'false', Storage.SecureStorage); context.go('/receptionPage'); } else { - StorageUtil().haveLocal = true; + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); context.go('/homePage'); } - StorageUtil().isLogged = true; + + await StorageHelper.instance.set(SecureStorageKey.isLogged.value, 'true', Storage.SecureStorage); } static Future signIn( @@ -41,13 +43,8 @@ class AuthenticationService { try { final ApiCallResponse? response; final LoginCall callback = PhpGroup.loginCall; - StorageUtil().deviceDescription = randomString( - 10, - 10, - true, - false, - false, - ); + String deviceDescription = randomString(10, 10, true, false, false); + await StorageHelper.instance.set(SecureStorageKey.deviceDescription.value, deviceDescription, Storage.SecureStorage); final String? devUUID; final String userUUID; @@ -62,9 +59,9 @@ class AuthenticationService { devUUID = await DeviceUtil.getDevUUID(); if ((email != '') && (passwd != '')) { - StorageUtil().email = email; - StorageUtil().passwd = passwd; - StorageUtil().devUUID = devUUID!; + await StorageHelper.instance.set(SecureStorageKey.email.value, email, Storage.SecureStorage); + await StorageHelper.instance.set(SecureStorageKey.password.value, passwd, Storage.SecureStorage); + await StorageHelper.instance.set(SQLiteStorageKey.devUUID.value, devUUID!, Storage.SQLiteStorage); response = await callback.call(); if (response.jsonBody['error'] == false) { @@ -73,10 +70,10 @@ class AuthenticationService { userDevUUID = response.jsonBody['user']['dev_id']; userName = response.jsonBody['user']['name']; - StorageUtil().userUUID = userUUID; - StorageUtil().userDevUUID = userDevUUID; - StorageUtil().status = status; - StorageUtil().userName = userName; + await StorageHelper.instance.set(SQLiteStorageKey.userUUID.value, userUUID, Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.userDevUUID.value, userDevUUID, Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.status.value, status, Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.userName.value, userName, Storage.SQLiteStorage); await login(context); } else { @@ -140,7 +137,7 @@ class AuthenticationService { alignment: Alignment.bottomCenter, ), }; - await StorageUtil.purge(); + await StorageHelper.instance.clearAll(Storage.SecureStorage); context.go('/welcomePage', extra: extra); } @@ -188,7 +185,7 @@ class AuthenticationService { static Future deleteAccount(BuildContext context) async { String content; try { - await PhpGroup.deleteAccount.call().then((value) { + await PhpGroup.deleteAccount.call().then((value) async { final Map extra = { kTransitionInfoKey: const TransitionInfo( hasTransition: true, @@ -201,7 +198,7 @@ class AuthenticationService { enText: 'Account deleted successfully', ptText: 'Conta deletada com sucesso', ); - StorageUtil.purge(); + await StorageHelper.instance.clearAll(Storage.SecureStorage); context.pop(); context.go('/welcomePage', extra: extra); } diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index a6656cc5..426049a7 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -2,8 +2,9 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; -import 'package:hub/shared/utils/storage_util.dart'; import '../../../backend/api_requests/api_calls.dart'; import '../../../components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart'; @@ -30,12 +31,12 @@ class LocalizationService { final bool isEnable = !isEmpty && isActive; if (isEnable) { - StorageUtil().haveLocal = true; - StorageUtil().isLogged = true; + await StorageHelper.instance.set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + await StorageHelper.instance.set(SecureStorageKey.isLogged.value, 'true', Storage.SecureStorage); await WidgetsBinding.instance.endOfFrame; - StorageUtil().cliUUID = ''; - StorageUtil().ownerUUID = ''; - StorageUtil().context?.go('/homePage'); + await StorageHelper.instance.set(SQLiteStorageKey.clientUUID.value, '', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.ownerUUID.value, '', Storage.SQLiteStorage); + StorageHelper.instance.context?.go('/homePage'); } } catch (e, s) { log(e.toString(), stackTrace: s); @@ -44,7 +45,6 @@ class LocalizationService { static Future processLocals(BuildContext context) async { try { - await StorageUtil().ensureInitialization(); final GetLocalsCall callback = PhpGroup.getLocalsCall; final ApiCallResponse response = await callback.call(); final bool isError = response.jsonBody['error']; @@ -59,16 +59,16 @@ class LocalizationService { _logLocalsStatus(locals); final bool isActive = _isActive(locals); - final bool isInactived = _isInactived(locals); + final bool isInactived = await _isInactived(locals); final bool isPending = _isPending(locals); final bool isUnique = locals.length == 1; final bool isBlocked = locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty; final bool isEnabled = isUnique && isActive; final bool isDisabled = isUnique && isBlocked; - final bool isUnselected = _isUnselected(); - final bool isSelected = _isSelected(isInactived); + final bool isUnselected = await _isUnselected(); + final bool isSelected = await _isSelected(isInactived); final bool isUnavailable = isPending && isUnselected && isUnique; - final bool isAvailable = _isAvailable(); + final bool isAvailable = await _isAvailable(); if (isDisabled) { AuthenticationService.signOut(context); @@ -109,7 +109,6 @@ class LocalizationService { static Future processData(BuildContext context) async { try { - await StorageUtil().ensureInitialization(); final GetDadosCall callback = PhpGroup.getDadosCall; var response = await callback.call(); final bool error = response.jsonBody['error']; @@ -119,7 +118,7 @@ class LocalizationService { DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context)); return false; } else { - _updateStorageUtil(response.jsonBody); + await _updateStorageUtil(response.jsonBody); return true; } } catch (e, s) { @@ -161,10 +160,10 @@ class LocalizationService { ptText: 'Dispositivo desvinculado com sucesso', ); - await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) { + await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async { if (value.jsonBody['error'] == false) { - StorageUtil().cliName = ''; - StorageUtil().cliUUID = ''; + await StorageHelper.instance.set(SQLiteStorageKey.clientName.value, '', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.clientUUID.value, '', Storage.SQLiteStorage); context.pop(); context.go( '/homePage', @@ -200,21 +199,19 @@ class LocalizationService { static void _handleError(BuildContext context, String errorMsg) { AuthenticationService.signOut(context); DialogUtil.error(context, errorMsg); - LogUtil.requestAPIFailed('getLocals.php', '{devUUID: ${StorageUtil().devUUID}, cliUUID: ${StorageUtil().userUUID}}', - 'Get Locals', errorMsg, StackTrace.current); } static Future _handleUnavailable(BuildContext context, List locals) async { log('() => isUnavailable'); try { - StorageUtil().cliUUID = locals[0]['CLI_ID']; - StorageUtil().ownerUUID = locals[0]['CLU_OWNER_ID']; - StorageUtil().cliName = locals[0]['CLI_NOME']; + await StorageHelper.instance.set(SQLiteStorageKey.clientUUID.value, locals[0]['CLI_ID'], Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID'], Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.clientName.value, locals[0]['CLI_NOME'], Storage.SQLiteStorage); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { - StorageUtil().cliUUID = ''; - StorageUtil().cliName = ''; - StorageUtil().ownerUUID = ''; + await StorageHelper.instance.set(SQLiteStorageKey.clientUUID.value, '', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.ownerUUID.value, '', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.clientName.value, '', Storage.SQLiteStorage); return false; } if (response.jsonBody['error'] == false) return await processData(context).then((value) => value); @@ -228,10 +225,10 @@ class LocalizationService { static Future _handleEnabled(BuildContext context, dynamic local) async { log('() => isEnabled'); - StorageUtil().cliName = local['CLI_NOME']; - StorageUtil().userName = local['USU_NOME']; - StorageUtil().cliUUID = local['CLI_ID']; - StorageUtil().ownerUUID = local['CLU_OWNER_ID']; + await StorageHelper.instance.set(SQLiteStorageKey.clientUUID.value, local['CLI_ID'], Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.ownerUUID.value, local['CLU_OWNER_ID'], Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.clientName.value, local['CLI_NOME'], Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.userName.value, local['USU_NOME'], Storage.SQLiteStorage); return await processData(context); } @@ -246,32 +243,39 @@ class LocalizationService { return locals.where((local) => local['CLU_STATUS'] == 'A').isNotEmpty; } - static bool _isInactived(List locals) { - return locals.where((local) => local['CLI_ID'] != StorageUtil().cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; + static Future _isInactived(List locals) async { + String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; } static bool _isPending(List locals) { return locals.where((local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A').isNotEmpty; } - static bool _isUnselected() { - return StorageUtil().cliUUID.isEmpty && StorageUtil().cliName.isEmpty && StorageUtil().ownerUUID.isEmpty; + static Future _isUnselected() async { + String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + String cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + String ownerUUID = (await StorageHelper.instance.get(SQLiteStorageKey.ownerUUID.value, Storage.SQLiteStorage)) ?? ''; + return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; } - static bool _isSelected(bool isInactived) { - return StorageUtil().cliUUID.isNotEmpty && StorageUtil().cliName.isNotEmpty && isInactived; + static Future _isSelected(bool isInactived) async { + String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + String cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; } - static bool _isAvailable() { - return StorageUtil().cliUUID.isNotEmpty && StorageUtil().cliName.isNotEmpty; + static Future _isAvailable() async { + String cliUUID = (await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + String cliName = (await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + return cliUUID.isNotEmpty && cliName.isNotEmpty; } - static void _updateStorageUtil(Map jsonBody) { - StorageUtil().whatsapp = jsonBody['whatsapp'] ?? false; - StorageUtil().provisional = jsonBody['provisional'] ?? false; - StorageUtil().pets = jsonBody['pet'] ?? false; - StorageUtil().petAmountRegister = - jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString(); - StorageUtil().userName = jsonBody['visitado']['VDO_NOME']; + static Future _updateStorageUtil(Map jsonBody) async { + await StorageHelper.instance.set(SQLiteStorageKey.whatsapp.value, jsonBody['whatsapp'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.provisional.value, jsonBody['provisional'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.pets.value, jsonBody['pet'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.petAmount.value, jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString(), Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage); } } diff --git a/lib/shared/utils/cache_util.dart b/lib/shared/utils/cache_util.dart deleted file mode 100644 index c28e0fb8..00000000 --- a/lib/shared/utils/cache_util.dart +++ /dev/null @@ -1,34 +0,0 @@ -class CacheUtil { - static final CacheUtil _instance = CacheUtil._internal(); - static final Map _cache = {}; - - CacheUtil._internal(); - - factory CacheUtil() => _instance; - - static CacheUtil get instance => _instance; - - void set(String key, dynamic value) { - _cache[key] = value; - } - - dynamic get(String key) { - return _cache[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); - } - - void clear() { - _cache.clear(); - } -} diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index 31cc52ef..c1584d29 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -1,10 +1,11 @@ -import 'package:hub/shared/utils/storage_util.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final cliName = StorageUtil().cliName; - final cliUUID = StorageUtil().cliUUID; + final cliName = await StorageHelper.instance.get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage); + final cliUUID = await StorageHelper.instance.get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage); 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 deleted file mode 100644 index ee6dca8e..00000000 --- a/lib/shared/utils/storage_util.dart +++ /dev/null @@ -1,439 +0,0 @@ -import 'dart:developer'; -import 'dart:ffi'; - -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:hub/shared/utils/dialog_util.dart'; -import 'package:hub/shared/utils/log_util.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - -enum StorageType { secureStorage, sharedPreferences, dbSQLite3 } - -abstract class Storage { - Future set(String key, dynamic value, Function(dynamic) cacheSetter); - Future get(String key); - Future delete(String key); - Future purge(); -} - -class StorageData { - final String key; - final dynamic value; - final StorageType type; - StorageData(this.key, this.value, this.type); -} - -class StorageUtil { - static final StorageUtil _instance = StorageUtil._internal(); - - factory StorageUtil() { - return _instance; - } - - StorageUtil._internal(); - - late final SQLiteStorageHelper _sqliteStorage; - late final SecureStorageHelper _secureStorage; - late final SharedPreferencesStorageHelper _sharedPreferences; - bool _initialized = true; - - 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) {}); - break; - case StorageType.sharedPreferences: - await SharedPreferencesStorageHelper().set(data.key, data.value, (v) {}); - break; - case StorageType.dbSQLite3: - await SQLiteStorageHelper().set(data.key, data.value, (v) {}); - break; - } - CacheUtil().set(data.key, data.value); - } catch (e) { - log('Error setting data: $e'); - } - } - - static Future get(StorageData data) async { - try { - var value = CacheUtil().get(data.key); - if (value == null) { - switch (data.type) { - case StorageType.secureStorage: - value = await SecureStorageHelper().get(data.key); - break; - case StorageType.sharedPreferences: - value = await SharedPreferencesStorageHelper().get(data.key); - break; - case StorageType.dbSQLite3: - value = await SQLiteStorageHelper().get(data.key); - break; - } - CacheUtil().set(data.key, value); - } - return value; - } catch (e) { - log('Error getting data: $e'); - return null; - } - } - - static Future delete(StorageData data) async { - try { - CacheUtil().delete(data.key); - switch (data.type) { - case StorageType.secureStorage: - await SecureStorageHelper().delete(data.key); - break; - case StorageType.sharedPreferences: - await SharedPreferencesStorageHelper().delete(data.key); - break; - case StorageType.dbSQLite3: - await SQLiteStorageHelper().delete(data.key); - break; - } - } catch (e) { - log('Error deleting data: $e'); - } - } - - static Future purge() async { - try { - await SecureStorageHelper().purge(); - await SQLiteStorageHelper().purge(); - // await SharedPreferencesStorageHelper().purge(); - } catch (e) { - log('Error purging data: $e'); - } - } - - Future ensureInitialization() async { - try { - log('StorageUtil: Starting initialization'); - if (!_initialized) return true; - await initSharedPreferences(); - await initSecureStorage(); - await initSQLiteStorage(); - if (_initialized) _initialized = false; - if (_initialized) return true; - return false; - } catch (e, s) { - log('Error initializing storage: $e'); - LogUtil.requestAPIFailed('$UniqueKey', '$UniqueKey', 'StorageUtil', e, s); - return false; - } - } - - Future initSharedPreferences() async { - try { - if (_initialized) _sharedPreferences = SharedPreferencesStorageHelper(); - _sharedPreferences.prefs ??= await SharedPreferences.getInstance(); - final bool milestone = _sharedPreferences.prefs?.getBool('fre_isFirstRun') ?? true; - if (milestone) { - isFirstRun = false; - await _sharedPreferences.prefs?.setBool('fre_isFirstRun', false); - isLogged = false; - final String message = ''; - - // _secureStorage.purge(); - // _sqliteStorage.purge(); - } - } catch (e, s) { - log('SharedPreferencesStorageHelper: Error during initialization'); - LogUtil.requestAPIFailed('$UniqueKey', '$UniqueKey', 'SharedPreferencesStorageHelper', e, s); - } - } - - Future initSecureStorage() async { - log('SecureStorageHelper: Starting initialization'); - try { - if (_initialized) _secureStorage = SecureStorageHelper(); - _email = await _secureStorage.getString('fre_email'); - _passwd = await _secureStorage.getString('fre_passwd'); - _deviceType = await _secureStorage.getString('fre_deviceType'); - _isLogged = await _secureStorage.getBool('fre_isLogged') ?? false; - _tokenAPNS = await _secureStorage.getString('fre_tokenAPNS'); - _accessPass = await _secureStorage.getString('fre_accessPass'); - _panicPass = await _secureStorage.getString('fre_panicPass'); - _fingerprintPass = await _secureStorage.getString('fre_fingerprintPass'); - _haveLocal = await _secureStorage.getBool('fre_have_local') ?? false; - _deviceDescription = await _secureStorage.getString('fre_deviceDescription'); - } catch (e, s) { - log('SecureStorageHelper: Error during initialization: $e'); - LogUtil.requestAPIFailed('$UniqueKey', '$UniqueKey', 'SecureStorageHelper', e, s); - } - log('SecureStorageHelper: Initialization complete'); - } - - Future initSQLiteStorage() async { - log('SQLiteStorageHelper: Starting initialization'); - try { - if (_initialized) _sqliteStorage = SQLiteStorageHelper(); - await _sqliteStorage.database; - _devUUID = await _sqliteStorage.get('fre_devUUID') ?? ''; - _userUUID = await _sqliteStorage.get('fre_userUUID') ?? ''; - _userDevUUID = await _sqliteStorage.get('fre_userDevUUID') ?? ''; - _status = await _sqliteStorage.get('fre_status') ?? ''; - _userName = await _sqliteStorage.get('fre_userName') ?? ''; - _cliUUID = await _sqliteStorage.get('fre_cliUUID') ?? ''; - _ownerUUID = await _sqliteStorage.get('fre_ownerUUID') ?? ''; - _cliName = await _sqliteStorage.get('fre_cliName') ?? ''; - _petAmountRegister = await _sqliteStorage.get('fre_petAmountRegister') ?? ''; - _whatsapp = await _sqliteStorage.getBoolean('fre_whatsapp'); - _provisional = await _sqliteStorage.getBoolean('fre_provisional'); - _pets = await _sqliteStorage.getBoolean('fre_pets'); - _local = await _sqliteStorage.getBoolean('fre_local'); - _notify = await _sqliteStorage.getBoolean('fre_notify'); - _fingerprint = await _sqliteStorage.getBoolean('fre_fingerprint'); - _access = await _sqliteStorage.getBoolean('fre_access'); - _panic = await _sqliteStorage.getBoolean('fre_panic'); - _person = await _sqliteStorage.getBoolean('fre_person'); - _requestOSnotification = await _sqliteStorage.getBoolean('fre_requestOSnotification'); - } catch (e, s) { - log('SQLiteStorageHelper: Error during initialization: $e'); - LogUtil.requestAPIFailed('$UniqueKey', '$UniqueKey', 'SQLiteStorageHelper', e, s); - } - log('SQLiteStorageHelper: Initialization complete'); - } - - bool _isRecovered = false; - bool get isRecovered => _isRecovered; - set isRecovered(bool value) => _isRecovered = value; - - bool _isFirstRun = true; - bool get isFirstRun => _isFirstRun; - set isFirstRun(bool value) { - _isFirstRun = value; - _sharedPreferences.set('fre_isFirstRun', value, (v) => _isFirstRun = v); - } - - String? _deviceDescription; - String get deviceDescription => _deviceDescription ?? ''; - set deviceDescription(String value) { - _deviceDescription = value; - _secureStorage.set('fre_deviceDescription', value, (v) => _deviceDescription = v); - } - - BuildContext? _context; - BuildContext? get context => _context; - set context(BuildContext? value) { - _context = value; - _secureStorage.set('fre_context', value.toString(), (v) => _context = value); - } - - bool _haveLocal = false; - bool get haveLocal => _haveLocal; - set haveLocal(bool value) { - _haveLocal = value; - _secureStorage.set('fre_have_local', value ?? false, (v) => _haveLocal = value); - } - - String? _fingerprintPass; - String get fingerprintPass => _fingerprintPass ?? ''; - set fingerprintPass(String value) { - _fingerprintPass = value; - _secureStorage.set('fre_fingerprintPass', value, (v) => _fingerprintPass = v); - } - - String? _accessPass; - String get accessPass => _accessPass ?? ''; - set accessPass(String value) { - _accessPass = value; - _secureStorage.set('fre_accessPass', value, (v) => _accessPass = v); - } - - String? _panicPass; - String get panicPass => _panicPass ?? ''; - set panicPass(String value) { - _panicPass = value; - _secureStorage.set('fre_panicPass', value, (v) => _panicPass = v); - } - - String? _tokenAPNS; - String? get tokenAPNS => _tokenAPNS; - set tokenAPNS(String? value) { - _tokenAPNS = value; - _secureStorage.set('fre_tokenAPNS', value ?? '', (v) => _tokenAPNS = v); - } - - String? _email; - String get email => _email ?? ''; - set email(String value) { - _email = value; - _secureStorage.set('fre_email', value, (v) => _email = v); - } - - String? _passwd; - String get passwd => _passwd ?? ''; - set passwd(String value) { - _passwd = value; - _secureStorage.set('fre_passwd', value, (v) => _passwd = v); - } - - String? _deviceType; - String get deviceType => _deviceType ?? ''; - set deviceType(String value) { - _deviceType = value; - _secureStorage.set('fre_deviceType', value, (v) => _deviceType = v); - } - - bool _isLogged = false; - bool get isLogged => _isLogged; - set isLogged(bool value) { - _isLogged = value; - _secureStorage.set('fre_isLogged', value, (v) => _isLogged = v); - } - - String? _token; - String get token => _token ?? ''; - set token(String value) { - _token = value; - _secureStorage.set('fre_token', value, (v) => _token = v); - } - - String _devUUID = ''; - String get devUUID => _devUUID; - set devUUID(String value) { - _devUUID = value; - _sqliteStorage.set('fre_devUUID', value, (v) {}); - } - - String _userUUID = ''; - String get userUUID => _userUUID; - set userUUID(String value) { - _userUUID = value; - _sqliteStorage.set('fre_userUUID', value, (v) {}); - } - - String _userDevUUID = ''; - String get userDevUUID => _userDevUUID; - set userDevUUID(String value) { - _userDevUUID = value; - _sqliteStorage.set('fre_userDevUUID', value, (v) {}); - } - - String _status = ''; - String get status => _status; - set status(String value) { - _status = value; - _sqliteStorage.set('fre_status', value, (v) {}); - } - - String _userName = ''; - String get userName => _userName; - set userName(String value) { - _userName = value; - _sqliteStorage.set('fre_userName', value, (v) {}); - } - - String _cliUUID = ''; - String get cliUUID => _cliUUID; - set cliUUID(String value) { - _cliUUID = value; - _sqliteStorage.set('fre_cliUUID', value, (v) {}); - } - - String _ownerUUID = ''; - String get ownerUUID => _ownerUUID; - set ownerUUID(String value) { - _ownerUUID = value; - _sqliteStorage.set('fre_ownerUUID', value, (v) {}); - } - - String _cliName = ''; - String get cliName => _cliName; - set cliName(String value) { - _cliName = value; - _sqliteStorage.set('fre_cliName', value, (v) {}); - } - - String _petAmountRegister = ''; - String get petAmountRegister => _petAmountRegister; - set petAmountRegister(String value) { - _petAmountRegister = value; - _sqliteStorage.set('fre_petAmountRegister', value, (v) {}); - } - - bool _whatsapp = false; - bool get whatsapp => _whatsapp; - set whatsapp(bool value) { - _whatsapp = value; - _sqliteStorage.set('fre_whatsapp', value, (v) {}); - } - - bool _provisional = false; - bool get provisional => _provisional; - set provisional(bool value) { - _provisional = value; - _sqliteStorage.set('fre_provisional', value, (v) {}); - } - - bool _pets = false; - bool get pets => _pets; - set pets(bool value) { - _pets = value; - _sqliteStorage.set('fre_pets', value, (v) {}); - } - - bool _local = false; - bool get local => _local; - set local(bool value) { - _local = value; - _sqliteStorage.set('fre_local', value, (v) {}); - } - - bool _notify = false; - bool get notify => _notify; - set notify(bool value) { - _notify = value; - _sqliteStorage.set('fre_notify', value, (v) {}); - } - - bool _fingerprint = false; - bool get fingerprint => _fingerprint; - set fingerprint(bool value) { - _fingerprint = value; - _sqliteStorage.set('fre_fingerprint', value, (v) {}); - } - - bool _access = false; - bool get access => _access; - set access(bool value) { - _access = value; - _sqliteStorage.set('fre_access', value, (v) {}); - } - - bool _panic = false; - bool get panic => _panic; - set panic(bool value) { - _panic = value; - _sqliteStorage.set('fre_panic', value, (v) {}); - } - - bool _person = false; - bool get person => _person; - set person(bool value) { - _person = value; - _sqliteStorage.set('fre_person', value, (v) {}); - } - - bool _requestOSnotification = false; - bool get requestOSnotification => _requestOSnotification; - set requestOSnotification(bool value) { - _requestOSnotification = value; - _sqliteStorage.set('fre_requestOSnotification', value, (v) {}); - } - - String get createdAt => '0000-00-00 00:00:00'; -} diff --git a/lib/shared/widgets/image_cropper_widget/image_cropper.dart b/lib/shared/widgets/image_cropper_widget/image_cropper.dart index 36cefae4..ac8dd871 100644 --- a/lib/shared/widgets/image_cropper_widget/image_cropper.dart +++ b/lib/shared/widgets/image_cropper_widget/image_cropper.dart @@ -12,7 +12,7 @@ // import 'package:crop_your_image/crop_your_image.dart'; // import 'package:google_fonts/google_fonts.dart'; -// import '/backend/firebase_storage/storage.dart'; +// import '/backend/firebase_storage/base_storage.dart'; // /////////////////