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..05bdabcf 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,8 @@ 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 +26,16 @@ 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/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 5aad7b29..b4ccddb3 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'; @@ -57,8 +58,10 @@ 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', @@ -85,9 +88,12 @@ 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( @@ -130,9 +136,12 @@ 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( @@ -176,9 +185,12 @@ 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( @@ -210,9 +222,12 @@ 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( @@ -253,9 +268,12 @@ 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( @@ -298,9 +316,12 @@ 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(); @@ -342,9 +363,12 @@ 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( @@ -376,8 +400,10 @@ 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( @@ -408,9 +434,12 @@ 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( @@ -444,9 +473,12 @@ 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( @@ -480,9 +512,12 @@ 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', @@ -514,9 +549,12 @@ 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( @@ -548,10 +586,14 @@ class UpdateIDE { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = StorageUtil().devUUID; - final String userUUID = StorageUtil().userUUID; - final String cliID = StorageUtil().cliUUID; - final String newIde = StorageUtil().userDevUUID; + 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)) ?? ''; + final String newIde = + (await StorageHelper.instance.get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -564,7 +606,7 @@ class UpdateIDE { params: { 'devUUID': devUUID, 'userUUID': userUUID, - 'cliID': cliID, + 'cliID': cliUUID, 'atividade': atividade, 'newIde': newIde, }, @@ -583,9 +625,11 @@ 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', @@ -612,11 +656,15 @@ 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( @@ -691,9 +739,12 @@ 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', @@ -752,8 +803,10 @@ 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', @@ -792,9 +845,12 @@ 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( @@ -847,9 +903,12 @@ 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( @@ -901,9 +960,12 @@ 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( @@ -1175,9 +1237,12 @@ 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( @@ -1408,9 +1473,12 @@ 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( @@ -1462,9 +1530,12 @@ 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( @@ -1501,9 +1572,12 @@ 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( @@ -1550,9 +1624,12 @@ 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( @@ -1813,9 +1890,12 @@ 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( @@ -1856,10 +1936,14 @@ 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', @@ -1922,9 +2006,12 @@ 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( @@ -1972,9 +2059,12 @@ 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( @@ -2221,9 +2311,12 @@ 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 { @@ -2413,9 +2506,12 @@ 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..9532c161 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,13 @@ 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..ca85162f 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,25 @@ 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..e6cfb14a 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,11 @@ 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 +140,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..0238d1a0 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,8 @@ 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 +79,8 @@ 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 +98,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 +207,8 @@ 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 +226,8 @@ 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 +343,8 @@ 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..999daa14 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..c5dfa64a 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,10 @@ 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 89226229..837ba3e9 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 @@ -4,7 +4,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 = ''; @@ -137,11 +138,12 @@ 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 65d64d64..e819966c 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'; @@ -565,9 +563,11 @@ class _ScheduleProvisionalVisitPageWidgetState extends State 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..252130d7 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,10 @@ 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/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 366f0ece..857dd4d1 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'; @@ -42,15 +43,6 @@ class AppStateNotifier extends ChangeNotifier { } 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; - - log('() => isLogged: $isLogged'); - log('() => haveLocal: $haveLocal'); - return GoRouter( initialLocation: '/', debugLogDiagnostics: true, @@ -86,16 +78,38 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { name: '_initialize', path: '/', builder: (context, _) { - try { - return isLogged && haveDevUUID && haveUserUUID - ? haveLocal == true - ? const HomePageWidget() - : const ReceptionPageWidget() - : const WelcomePageWidget(); - } catch (e) { - DialogUtil.error(context, e.toString()); - return const WelcomePageWidget(); - } + return FutureBuilder( + future: () 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; + + if (isLogged && haveDevUUID && haveUserUUID) { + return haveLocal ? const HomePageWidget() : const ReceptionPageWidget(); + } else { + return const WelcomePageWidget(); + } + }(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + DialogUtil.error(context, snapshot.error.toString()); + return const WelcomePageWidget(); + } else { + return snapshot.data!; + } + }, + ); }, ), FFRoute( diff --git a/lib/main.dart b/lib/main.dart index b39e9e8a..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,8 @@ void main() async { Future initializeApp() async { WidgetsFlutterBinding.ensureInitialized(); await _initializeTracking(); - await _initializeStorageHelpers(); + await StorageHelper.instance.init(); + await _initializeFirebase(); await _initializeNotificationService(); _initializeUrlStrategy(); @@ -43,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(); } @@ -87,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!, @@ -100,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'); } } @@ -186,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; @@ -216,7 +208,7 @@ class _AppState extends State with WidgetsBindingObserver { useSafeArea: true, enableDrag: true, // isDismissible: true, - ).whenComplete(() => StorageUtil().isRecovered = false); + ).whenComplete(() => StorageHelper.instance.isRecovered = false); } } @@ -229,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'); } } @@ -285,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..9519242f 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,15 @@ 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..7c4dc226 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,9 +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, automaticallyImplyLeading: false, diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index d4fe0614..03b421dd 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,13 @@ 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..d4c1cab6 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,11 @@ 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 7798e6c4..98a7c8a5 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,29 @@ import '../../shared/utils/snackbar_util.dart'; class PreferencesPageModel with ChangeNotifier { final unfocusNode = FocusNode(); - PreferencesPageModel() { - initVariables(); - } + late bool isFingerprint = false; + late bool isPerson = false; + late bool isNotify = false; + late bool isAccess = false; + late bool isPanic = false; - Future initVariables() async { + 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( @@ -45,33 +57,41 @@ class PreferencesPageModel with ChangeNotifier { enText: 'Are you sure you want to change your notification?', ptText: 'Tem certeza que deseja alterar sua notificação?', ); + onConfirm() async { String content; - String value = StorageUtil().notify ? 'N' : 'S'; - await PhpGroup.changeNotifica.call(notifica: value).then((value) async { - if (value.jsonBody['error'] == false) { - StorageUtil().notify = !StorageUtil().notify; - notifyListeners(); - content = FFLocalizations.of(context).getVariableText( - enText: 'Notification changed successfully', - ptText: 'Notificação alterada com sucesso', - ); - SnackBarUtil.showSnackBar(context, content); - } else { - content = FFLocalizations.of(context).getVariableText( - enText: 'Error changing notification', - ptText: 'Erro ao alterar notificação', - ); - SnackBarUtil.showSnackBar(context, content, isError: true); - } - }).catchError((e, s) { - log('toggleNotify', error: e, stackTrace: s); - content = FFLocalizations.of(context).getVariableText( - enText: 'Error changing notification', - ptText: 'Erro ao alterar notificação', - ); - SnackBarUtil.showSnackBar(context, content, isError: true); - }).whenComplete(() => notifyListeners()); + String value = !isNotify ? 'N' : 'S'; + await PhpGroup.changeNotifica + .call(notifica: value) + .then((value) async { + if (value.jsonBody['error'] == false) { + await StorageHelper.instance + .set(SQLiteStorageKey.notify.value, isNotify ? 'false' : 'true', Storage.SQLiteStorage); + content = FFLocalizations.of(context).getVariableText( + enText: 'Notification changed successfully', + ptText: 'Notificação alterada com sucesso', + ); + notifyListeners(); + SnackBarUtil.showSnackBar(context, content); + } else { + content = FFLocalizations.of(context).getVariableText( + enText: 'Error changing notification', + ptText: 'Erro ao alterar notificação', + ); + SnackBarUtil.showSnackBar(context, content, isError: true); + } + }) + .catchError((e, s) { + log('toggleNotify', error: e, stackTrace: s); + content = FFLocalizations.of(context).getVariableText( + enText: 'Error changing notification', + ptText: 'Erro ao alterar notificação', + ); + SnackBarUtil.showSnackBar(context, content, isError: true); + }) + .then((_) async => isNotify = + await StorageHelper.instance.get(SQLiteStorageKey.notify.value, Storage.SQLiteStorage) == 'true') + .whenComplete(() => notifyListeners()); context.pop(); } @@ -119,35 +139,38 @@ class PreferencesPageModel with ChangeNotifier { Future toggleAccess(BuildContext context) async { onChange(String key) async { - StorageUtil().accessPass = key; + await StorageHelper.instance.set(SecureStorageKey.accessPass.value, key, Storage.SecureStorage); await PhpGroup.changePass - .call( - newSenha: key, - ) + .call(newSenha: key) .then((value) async { - final String content; - if (jsonDecode(value.jsonBody['error'].toString()) == false) { - if (!StorageUtil().access) StorageUtil().access = !StorageUtil().access; - notifyListeners(); - content = FFLocalizations.of(context).getVariableText( - enText: 'Access pass changed successfully', - ptText: 'Senha de acesso alterada com sucesso', - ); - SnackBarUtil.showSnackBar(context, content); - } else { - content = FFLocalizations.of(context).getVariableText( - ptText: 'Erro ao alterar senha de acesso', - enText: 'Error changing access pass', - ); - SnackBarUtil.showSnackBar(context, content, isError: true); - } - }).catchError((e, s) { - final String content = FFLocalizations.of(context).getVariableText( - ptText: 'Erro ao alterar senha de acesso', - enText: 'Error changing access pass', - ); - SnackBarUtil.showSnackBar(context, content, isError: true); - }).whenComplete(() => notifyListeners()); + final String content; + if (jsonDecode(value.jsonBody['error'].toString()) == false) { + await StorageHelper.instance + .set(SQLiteStorageKey.access.value, isAccess ? 'false' : 'true', Storage.SQLiteStorage); + notifyListeners(); + content = FFLocalizations.of(context).getVariableText( + enText: 'Access pass changed successfully', + ptText: 'Senha de acesso alterada com sucesso', + ); + SnackBarUtil.showSnackBar(context, content); + } else { + content = FFLocalizations.of(context).getVariableText( + ptText: 'Erro ao alterar senha de acesso', + enText: 'Error changing access pass', + ); + SnackBarUtil.showSnackBar(context, content, isError: true); + } + }) + .catchError((e, s) { + final String content = FFLocalizations.of(context).getVariableText( + ptText: 'Erro ao alterar senha de acesso', + enText: 'Error changing access pass', + ); + SnackBarUtil.showSnackBar(context, content, isError: true); + }) + .then((_) async => isAccess = + await StorageHelper.instance.get(SQLiteStorageKey.access.value, Storage.SQLiteStorage) == 'true') + .whenComplete(() => notifyListeners()); } _showPassKey(context, onChange); @@ -155,35 +178,38 @@ 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); 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; - notifyListeners(); - content = FFLocalizations.of(context).getVariableText( - enText: 'Panic password changed successfully', - ptText: 'Senha de pânico alterada com sucesso', - ); - SnackBarUtil.showSnackBar(context, content); - } else { - content = FFLocalizations.of(context).getVariableText( - ptText: 'Erro ao alterar senha de pânico', - enText: 'Error changing panic password', - ); - SnackBarUtil.showSnackBar(context, content, isError: true); - } - }).catchError((e, s) { - final String content = FFLocalizations.of(context).getVariableText( - ptText: 'Erro ao alterar senha de pânico', - enText: 'Error changing panic password', - ); - SnackBarUtil.showSnackBar(context, content, isError: true); - }).whenComplete(() => notifyListeners()); + final String content; + if (jsonDecode(value.jsonBody['error'].toString()) == false) { + await StorageHelper.instance + .set(SQLiteStorageKey.panic.value, isPanic ? 'false' : 'true', Storage.SQLiteStorage); + notifyListeners(); + content = FFLocalizations.of(context).getVariableText( + enText: 'Panic password changed successfully', + ptText: 'Senha de pânico alterada com sucesso', + ); + SnackBarUtil.showSnackBar(context, content); + } else { + content = FFLocalizations.of(context).getVariableText( + ptText: 'Erro ao alterar senha de pânico', + enText: 'Error changing panic password', + ); + SnackBarUtil.showSnackBar(context, content, isError: true); + } + }) + .catchError((e, s) { + final String content = FFLocalizations.of(context).getVariableText( + ptText: 'Erro ao alterar senha de pânico', + enText: 'Error changing panic password', + ); + SnackBarUtil.showSnackBar(context, content, isError: true); + }) + .then((_) async => + isPanic = await StorageHelper.instance.get(SQLiteStorageKey.panic.value, Storage.SQLiteStorage) == 'true') + .whenComplete(() => notifyListeners()); } _showPassKey(context, onChange); @@ -196,16 +222,17 @@ class PreferencesPageModel with ChangeNotifier { ); 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, key ?? '', Storage.SecureStorage); + await StorageHelper.instance + .set(SQLiteStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false', Storage.SQLiteStorage); notifyListeners(); - SnackBarUtil.showSnackBar(context, content); + isFingerprint = + await StorageHelper.instance.get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; } - 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 b743c252..1249f1d0 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -5,7 +5,7 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/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:provider/provider.dart'; class PreferencesPageWidget extends StatefulWidget { @@ -101,7 +101,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 +110,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', @@ -128,7 +128,7 @@ class _PreferencesPageWidgetState extends State { case 3: 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', @@ -137,7 +137,7 @@ class _PreferencesPageWidgetState extends State { case 4: 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', @@ -146,7 +146,7 @@ class _PreferencesPageWidgetState extends State { case 5: 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..d52488dd 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -4,19 +4,20 @@ 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 { /// Local state fields for this page. - bool isAccess = false; - String? key; DateTime? time; + bool isAccess = false; late final bool isFingerprint; late final String userDevUUID; + late final VoidCallback? safeSetState; /// State fields for stateful widgets in this page. @@ -28,8 +29,10 @@ 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) ?? ''; + safeSetState?.call(); } @override @@ -79,8 +82,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..d4723892 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -1,4 +1,7 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:async'; +import 'dart:developer'; import 'package:barcode_widget/barcode_widget.dart'; import 'package:flutter/material.dart'; @@ -14,9 +17,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'; @@ -39,8 +43,8 @@ class _QrCodePageWidgetState extends State with TickerProvider void initState() { super.initState(); _model = createModel(context, () => QrCodePageModel()); + _model.safeSetState = () => safeSetState(() {}); - // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { animationsMap['barcodeOnActionTriggerAnimation']!.controller.fling(); @@ -67,14 +71,6 @@ class _QrCodePageWidgetState extends State with TickerProvider animationsMap.values.where((anim) => anim.trigger == AnimationTrigger.onActionTrigger || !anim.applyInitialState), this, ); - - // // Adicionando um ouvinte de status à animação para reiniciá-la após a conclusão - // animationsMap['barcodeOnActionTriggerAnimation']?.controller.addStatusListener((status) { - // if (status == AnimationStatus.completed) { - // animationsMap['barcodeOnActionTriggerAnimation']!.controller.reset(); - // animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward(); - // } - // }); } @override @@ -130,10 +126,8 @@ class _QrCodePageWidgetState extends State with TickerProvider alignment: const AlignmentDirectional(0.0, 0.0), child: InkWell( onTap: () async { - safeSetState(() async { - _resetAnimationAndToggleAccess(); - }); - + _resetAnimationAndToggleAccess(); + log('isFingerprint: ${_model.isFingerprint}'); _model.isFingerprint ? await _showBiometricsAuth(context) : await _showQrCodeBottomSheet(context); }, child: _model.buildQrCode( @@ -187,6 +181,7 @@ class _QrCodePageWidgetState extends State with TickerProvider alignment: const AlignmentDirectional(0.0, 0.0), child: FFButtonWidget( onPressed: () async { + log('isFingerprint: ${_model.isFingerprint}'); _model.isFingerprint ? await _showBiometricsAuth(context) : await _showQrCodeBottomSheet(context); @@ -261,7 +256,6 @@ class _QrCodePageWidgetState extends State with TickerProvider FFLocalizations.of(context).getVariableText( ptText: 'Expirando QR code em', enText: 'Expiring QR code in', - // 'wkjkxd2e' /* Trocando QR code em */, ), textAlign: TextAlign.center, style: FlutterFlowTheme.of(context).bodyMedium.override( @@ -328,19 +322,22 @@ class _QrCodePageWidgetState extends State with TickerProvider } Future _showBiometricsAuth(BuildContext context) async { - BiometricHelper.checkBiometrics() - .then((value) => BiometricHelper.authenticateBiometric().then((value) { + await BiometricHelper.checkBiometrics() + .then((value) async => await BiometricHelper.authenticateBiometric().then((value) async { + final key = + await StorageHelper.instance.get(SecureStorageKey.fingerprintPass.value, Storage.SecureStorage) ?? ''; safeSetState(() { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { animationsMap['barcodeOnActionTriggerAnimation']!.controller.stop(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.reverse(); } _model.isAccess = !_model.isAccess; - _model.key = StorageUtil().fingerprintPass; + _model.key = key; }); })) - .onError((error, StackTrace) { - _showQrCodeBottomSheet(context); + .onError((error, stackTrace) { + log('Error', error: error, stackTrace: stackTrace); + if (mounted) _showQrCodeBottomSheet(context); }); } @@ -372,26 +369,19 @@ class _QrCodePageWidgetState extends State with TickerProvider ), ); }, - ).catchError((error) => safeSetState(() { - _resetAnimationAndToggleAccess(); - })); + ).catchError((error) => safeSetState(() => _resetAnimationAndToggleAccess())); unawaited( () async { - await _model.qrCodeEncoder( - context, - key: _model.key, - ); - setState(() {}); + await _model.qrCodeEncoder(context, key: _model.key); + safeSetState(() {}); }(), ); } void _resetAnimationAndToggleAccess() { safeSetState(() { - // Reinicia a animação animationsMap['barcodeOnActionTriggerAnimation']!.controller.reset(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward(); - // Alterna o estado de acesso _model.isAccess = !_model.isAccess; _model.key = null; }); @@ -416,9 +406,7 @@ class _QrCodePageWidgetState extends State with TickerProvider }, ), title: Text( - FFLocalizations.of(context).getText( - 'ku7jqe53' /* QR Code de Acesso */, - ), + FFLocalizations.of(context).getText('ku7jqe53'), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: FlutterFlowTheme.of(context).headlineMediumFamily, color: FlutterFlowTheme.of(context).primaryText, diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index 0c99841c..02823e9f 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -1,11 +1,13 @@ 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..e6474a14 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,16 @@ 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..ba38941e 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,13 @@ 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..11bc2509 --- /dev/null +++ b/lib/shared/helpers/base_storage.dart @@ -0,0 +1,143 @@ +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 ''; + } + } +} diff --git a/lib/shared/helpers/secure_storage.dart b/lib/shared/helpers/secure_storage.dart new file mode 100644 index 00000000..24181fc9 --- /dev/null +++ b/lib/shared/helpers/secure_storage.dart @@ -0,0 +1,39 @@ +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(); + } +} 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..0dd19da1 --- /dev/null +++ b/lib/shared/helpers/shared_preferences_storage.dart @@ -0,0 +1,39 @@ +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(); + } +} 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..6f387759 --- /dev/null +++ b/lib/shared/helpers/sqlite_storage.dart @@ -0,0 +1,128 @@ +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(); + } +} 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..e93cfbdf --- /dev/null +++ b/lib/shared/helpers/storage_helper.dart @@ -0,0 +1,80 @@ +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(); + } + } +} diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 4b262d98..85770e80 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,9 @@ 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 +60,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 +71,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 +138,8 @@ class AuthenticationService { alignment: Alignment.bottomCenter, ), }; - await StorageUtil.purge(); + await StorageHelper.instance.clearAll(Storage.SecureStorage); + await StorageHelper.instance.clearAll(Storage.SQLiteStorage); context.go('/welcomePage', extra: extra); } @@ -188,7 +187,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 +200,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..1e38d0f6 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -1,9 +1,12 @@ +// ignore_for_file: curly_braces_in_flow_control_structures + 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 +33,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 +47,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 +61,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 +111,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 +120,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 +162,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 +201,20 @@ 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 +228,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 +246,49 @@ 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'] != null && jsonBody['whatsapp'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.provisional.value, + jsonBody['provisional'] != null && jsonBody['provisional'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper.instance.set(SQLiteStorageKey.pets.value, + jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper.instance.set( + SQLiteStorageKey.petAmount.value, + jsonBody['petAmountRegister'] != null && 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'; // /////////////////