diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index b66aeb0f..71181fe7 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -4,6 +4,7 @@ import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:hub/backend/notifications/firebase_messaging_service.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/utils/cache_util.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; @@ -61,8 +62,8 @@ class UnregisterDevice { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; return ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -92,9 +93,9 @@ class DeletePet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'excluirPet'; return ApiManager.instance.makeApiCall( @@ -137,9 +138,9 @@ class UpdatePet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'atualizarPet'; return ApiManager.instance.makeApiCall( @@ -185,9 +186,9 @@ class GetPets { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'consultaPets'; return ApiManager.instance.makeApiCall( @@ -221,9 +222,9 @@ class GetPetPhoto { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'consultaFotoPet'; return ApiManager.instance.makeApiCall( @@ -264,9 +265,9 @@ class RegisterPet { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'cadastrarPet'; return ApiManager.instance.makeApiCall( @@ -311,9 +312,9 @@ class BuscaEnconcomendas { String? adresseeType = '', String? status = '', }) async { - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getEncomendas'; final baseUrl = PhpGroup.getBaseUrl(); @@ -355,9 +356,9 @@ class CancelaVisita { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -389,8 +390,8 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; final baseUrl = PhpGroup.getBaseUrl(); return ApiManager.instance.makeApiCall( @@ -421,9 +422,9 @@ class ChangePanic { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -457,9 +458,9 @@ class ChangePass { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -494,8 +495,8 @@ class RespondeVinculo { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; return ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -527,9 +528,9 @@ class ChangeNotifica { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); - final cliID = CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -561,9 +562,9 @@ class UpdToken { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final token = AppState().token; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final token = SecureStorageHelper().token; return ApiManager.instance.makeApiCall( callName: 'updToken', @@ -590,12 +591,12 @@ class UpdToken { class LoginCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = CacheUtil.get('devUUID'); + final devUUID = SQLiteStorageHelper().devUUID; - final email = AppState().email; - final password = AppState().passwd; - final type = AppState().deviceType; - final description = AppState().deviceDescription; + final email = SecureStorageHelper().email; + final password = SecureStorageHelper().passwd; + final type = SecureStorageHelper().deviceType; + final description = SecureStorageHelper().deviceDescription; final token = FirebaseMessagingService.getToken(); return ApiManager.instance.makeApiCall( @@ -694,8 +695,8 @@ class GetLocalsCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; return ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -734,9 +735,9 @@ class PostScheduleVisitorCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'putVisitante'; return ApiManager.instance.makeApiCall( @@ -789,9 +790,9 @@ class PostScheduleVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'putVisita'; return ApiManager.instance.makeApiCall( @@ -843,9 +844,9 @@ class GetScheduleVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1117,9 +1118,9 @@ class GetDadosCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getDados'; return ApiManager.instance.makeApiCall( @@ -1360,9 +1361,9 @@ class GetVisitorByDocCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getVisitante'; return ApiManager.instance.makeApiCall( @@ -1414,9 +1415,9 @@ class GetFotoVisitanteCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getFotoVisitante'; return ApiManager.instance.makeApiCall( @@ -1453,9 +1454,9 @@ class PostProvVisitSchedulingCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'putAgendamentoProv'; return ApiManager.instance.makeApiCall( @@ -1502,9 +1503,9 @@ class GetVisitsCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1765,9 +1766,9 @@ class DeleteVisitCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliID = SQLiteStorageHelper().cliUUID; const atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -1808,10 +1809,10 @@ class GetPessoasLocalCall { Future call() async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final ownerUUID = await CacheUtil.get('ownerUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final ownerUUID = SQLiteStorageHelper().ownerUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; return ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -1874,9 +1875,9 @@ class RespondeSolicitacaoCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'respondeSolicitacao'; return ApiManager.instance.makeApiCall( @@ -1924,9 +1925,9 @@ class GetAccessCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = await CacheUtil.get('devUUID'); - final userUUID = await CacheUtil.get('userUUID'); - final cliUUID = await CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getAcessos'; return ApiManager.instance.makeApiCall( @@ -2173,10 +2174,10 @@ class GetLiberationsCall { final StreamController controller = StreamController(); Future.microtask(() async { - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); - final cliUUID = CacheUtil.get('cliUUID'); - const atividade = 'getLiberacoes'; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; + const atividade = 'getSolicitacoes'; try { final response = await ApiManager.instance.makeApiCall( @@ -2365,9 +2366,9 @@ class GetMessagesCall { }) async { final baseUrl = PhpGroup.getBaseUrl(); - final devUUID = CacheUtil.get('devUUID'); - final userUUID = CacheUtil.get('userUUID'); - final cliUUID = CacheUtil.get('cliUUID'); + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; const atividade = 'getMensagens'; return ApiManager.instance.makeApiCall( diff --git a/lib/backend/api_requests/api_manager.dart b/lib/backend/api_requests/api_manager.dart index aaaef549..00e12f5e 100644 --- a/lib/backend/api_requests/api_manager.dart +++ b/lib/backend/api_requests/api_manager.dart @@ -1,5 +1,3 @@ -// ignore_for_file: constant_identifier_names, depend_on_referenced_packages, prefer_final_fields - import 'dart:convert'; import 'dart:core'; import 'dart:developer'; @@ -107,11 +105,8 @@ class ApiCallResponse { final http.Response? response; final http.StreamedResponse? streamedResponse; final Object? exception; - // Whether we received a 2xx status (which generally marks success). bool get succeeded => statusCode >= 200 && statusCode < 300; String getHeader(String headerName) => headers[headerName] ?? ''; - // Return the raw body from the response, or if this came from a cloud call - // and the body is not a string, then the json encoded body. String get bodyText => response?.body ?? (jsonBody is String ? jsonBody as String : jsonEncode(jsonBody)); @@ -126,7 +121,7 @@ class ApiCallResponse { dynamic jsonBody; try { if (bodyType == BodyType.BLOB) { - jsonBody = response.bodyBytes; // Armazenar os bytes diretamente + jsonBody = response.bodyBytes; } else { final responseBody = decodeUtf8 && returnBody ? const Utf8Decoder().convert(response.bodyBytes) @@ -153,19 +148,13 @@ class ApiCallResponse { class ApiManager { ApiManager._(); - // Cache that will ensure identical calls are not repeatedly made. static Map _apiCache = {}; static ApiManager? _instance; static ApiManager get instance => _instance ??= ApiManager._(); - // If your API calls need authentication, populate this field once - // the user has authenticated. Alter this as needed. static String? _accessToken; - // You may want to call this if, for example, you make a change to the - // database and no longer want the cached result of a call that may - // have changed. static void clearCache(String callName) => _apiCache.keys .toSet() .forEach((k) => k.callName == callName ? _apiCache.remove(k) : null); @@ -187,7 +176,7 @@ class ApiManager { bool decodeUtf8, bool isStreamingApi, { http.Client? client, - BodyType? bodyType, // Adicionado para verificar o tipo de corpo + BodyType? bodyType, }) async { if (params.isNotEmpty) { final specifier = @@ -213,7 +202,7 @@ class ApiManager { final response = await makeRequest(Uri.parse(apiUrl), headers: toStringMap(headers)); return ApiCallResponse.fromHttpResponse( - response, returnBody, decodeUtf8, bodyType); // Passar bodyType + response, returnBody, decodeUtf8, bodyType); } static Future requestWithBody( @@ -368,7 +357,6 @@ class ApiManager { case null: break; } - // Set "Content-Type" header if it was previously unset. if (contentType != null && !headers.keys.any((h) => h.toLowerCase() == 'content-type')) { headers['Content-Type'] = contentType; @@ -428,7 +416,6 @@ class ApiManager { cache: cache, isStreamingApi: isStreamingApi, ); - // Modify for your specific needs if this differs from your API. if (_accessToken != null) { headers[HttpHeaders.authorizationHeader] = 'Bearer $_accessToken'; } @@ -436,8 +423,6 @@ class ApiManager { apiUrl = 'https://$apiUrl'; } - // If we've already made this exact call before and caching is on, - // return the cached result. if (cache && _apiCache.containsKey(callOptions)) { return _apiCache[callOptions]!; } @@ -504,7 +489,6 @@ class ApiManager { break; } - // If caching is on, cache the result (if present). if (cache) { _apiCache[callOptions] = result; } diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index e8492f5a..963caef3 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -4,6 +4,7 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:hub/app_state.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/log_util.dart'; @@ -64,7 +65,7 @@ class FirebaseMessagingService { final String? deviceToken = await _firebaseMessaging.getToken(); if (deviceToken != null) { - AppState().token = deviceToken; + SecureStorageHelper().token = deviceToken; final ApiCallResponse? response; response = await PhpGroup.updToken.call(); diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index 448760dc..95a587f4 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -13,6 +13,7 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:sqflite/sqflite.dart'; @@ -20,10 +21,8 @@ import 'package:sqflite/sqflite.dart'; Future onMessageReceived( Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + + final cliUUID = SQLiteStorageHelper().cliUUID; answersRequest( {required BuildContext context, required String? ref, @@ -50,7 +49,7 @@ Future onMessageReceived( switch (handleClick) { case 'visit_request': showDialog( - context: AppState().context!, + context: SecureStorageHelper().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -173,7 +172,7 @@ Future onMessageReceived( break; case 'access': showDialog( - context: AppState().context!, + context: SecureStorageHelper().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -232,7 +231,7 @@ Future onMessageReceived( break; case 'mensagem': showDialog( - context: AppState().context!, + context: SecureStorageHelper().context!, barrierColor: Colors.transparent, barrierDismissible: true, builder: (BuildContext context) { @@ -255,8 +254,8 @@ Future onMessageReceived( break; case 'enroll_cond': - AppState().haveLocal = true; - AppState().context!.go('/homePage'); + SecureStorageHelper().haveLocal = true; + SecureStorageHelper().context!.go('/homePage'); break; default: break; @@ -292,14 +291,12 @@ class NotificationService { await AwesomeNotifications() .isNotificationAllowed() .then((isAllowed) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final bool requestOSnotification = await db - .get(key: 'requestOSnotification', field: 'value') - .then((value) => value.toString() == 'true'); + final bool requestOSnotification = + SQLiteStorageHelper().requestOSnotification; if (!requestOSnotification) { if (!isAllowed) { - await db.update('requestOSnotification', 'true', 'util'); + SQLiteStorageHelper().requestOSnotification = true; await AwesomeNotifications().requestPermissionToSendNotifications(); } } diff --git a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart index c9e0c559..7f1a787b 100644 --- a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart +++ b/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart @@ -34,10 +34,7 @@ class _MenuButtonWidgetState extends State { hoverColor: Colors.transparent, highlightColor: Colors.transparent, onTap: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; if (cliUUID.isEmpty) { return DialogUtil.warningDefault(context); diff --git a/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart b/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart index ddd13a38..ebae1e35 100644 --- a/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart +++ b/lib/components/molecular_components/order_filter_modal/order_filter_modal_widget.dart @@ -4,6 +4,7 @@ import 'package:hub/components/molecular_components/order_filter_modal/order_fil import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; class OrderFilterModalWidget extends StatefulWidget { final String defaultAdresseeType; @@ -25,24 +26,25 @@ class _OrderFilterModalWidgetState extends State { late Map selected; final List> adresseeTypeOptions = [ { - 'title': FFLocalizations.of(AppState().context!) + 'title': FFLocalizations.of(SecureStorageHelper().context!) .getVariableText(enText: 'Resident', ptText: 'Morador'), 'value': 'MOR' }, { - 'title': FFLocalizations.of(AppState().context!) + 'title': FFLocalizations.of(SecureStorageHelper().context!) .getVariableText(enText: 'Property', ptText: 'Propriedade'), 'value': 'PRO' }, ]; final List> statusOptions = [ { - 'title': FFLocalizations.of(AppState().context!).getVariableText( - ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'), + 'title': FFLocalizations.of(SecureStorageHelper().context!) + .getVariableText( + ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'), 'value': 'notPickedUp' }, { - 'title': FFLocalizations.of(AppState().context!) + 'title': FFLocalizations.of(SecureStorageHelper().context!) .getVariableText(ptText: 'Retirado', enText: 'Picked Up'), 'value': 'pickedUp' }, diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index a6b10092..322184b3 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -65,10 +65,6 @@ class _BottomArrowLinkedLocalsComponentWidgetState Future _fetchLocals() async { try { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final devUUID = await db.get(key: 'devUUID', field: 'value'); - final userUUID = await db.get(key: 'userUUID', field: 'value'); - setState(() => _loading = true); var response = await PhpGroup.getLocalsCall.call(); @@ -84,9 +80,9 @@ class _BottomArrowLinkedLocalsComponentWidgetState // Verifica se há apenas um local e se o status é 'A' if (locals.length == 1 && locals[0]['CLU_STATUS'] == 'A') { final local = locals[0]; - db.update('cliUUID', local['CLI_ID'], 'local'); - db.update('cliName', local['CLI_NOME'], 'local'); - db.update('ownerUUID', local['CLU_OWNER_ID'], 'local'); + SQLiteStorageHelper().cliName = local['CLI_NOME']; + SQLiteStorageHelper().cliUUID = local['CLI_ID']; + SQLiteStorageHelper().ownerUUID = local['CLU_OWNER_ID']; context.pop(); } @@ -173,12 +169,10 @@ class _BottomArrowLinkedLocalsComponentWidgetState labelsHashMap: _labelsHashMap(local), statusHashMap: [_statusHashMap(local)], onTapCardItemAction: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - if (local['CLU_STATUS'] == 'A') { - db.update('cliUUID', local['CLI_ID'], 'local'); - db.update('cliName', local['CLI_NOME'], 'local'); - db.update('ownerUUID', local['CLU_OWNER_ID'], 'local'); + SQLiteStorageHelper().cliUUID = local['CLI_ID']; + SQLiteStorageHelper().cliName = local['CLI_NOME']; + SQLiteStorageHelper().ownerUUID = local['CLU_OWNER_ID']; context.pop(); } else if (local['CLU_STATUS'] == 'B') { @@ -247,8 +241,6 @@ class _BottomArrowLinkedLocalsComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - double height = MediaQuery.sizeOf(context).height; return Align( diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart index c5517351..efd60746 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart +++ b/lib/components/organism_components/local_profile_component/local_profile_component_model.dart @@ -1,4 +1,3 @@ -import 'dart:ffi'; import 'dart:math'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; @@ -11,7 +10,6 @@ import 'package:flutter/material.dart'; class LocalProfileComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); String cliName = ''; String cliUUID = ''; VoidCallback? setStateCallback; @@ -22,12 +20,8 @@ class LocalProfileComponentModel } Future getData() async { - cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + cliName = SQLiteStorageHelper().cliName; + cliUUID = SQLiteStorageHelper().cliUUID; setStateCallback?.call(); } diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart b/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart index a5a164b3..5f0717b3 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart +++ b/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart @@ -16,8 +16,6 @@ import 'local_profile_component_model.dart'; export 'local_profile_component_model.dart'; -//// - class LocalProfileComponentWidget extends StatefulWidget { LocalProfileComponentWidget({Key? key}) : super(key: key); @@ -29,7 +27,6 @@ class LocalProfileComponentWidget extends StatefulWidget { class _LocalProfileComponentWidgetState extends State { late LocalProfileComponentModel _model; - final SQLiteStorageHelper db = SQLiteStorageHelper(); @override void setState(VoidCallback callback) { @@ -45,9 +42,7 @@ class _LocalProfileComponentWidgetState _model.setStateCallback = () => safeSetState(() {}); () async { - _model.cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + _model.cliUUID = SQLiteStorageHelper().cliUUID; if (_model.cliUUID.isEmpty) { await processLocals(); @@ -78,11 +73,11 @@ class _LocalProfileComponentWidgetState final petAmountRegister = response.jsonBody['petAmountRegister'] ?? '0'; final name = response.jsonBody['visitado']['VDO_NOME']; - await db.update('whatsapp', whatsapp.toString(), 'local'); - await db.update('provisional', provisional.toString(), 'local'); - await db.update('pets', pets.toString(), 'local'); - await db.update('petAmountRegister', petAmountRegister, 'local'); - await db.update('name', name, 'local'); + SQLiteStorageHelper().whatsapp = whatsapp; + SQLiteStorageHelper().provisional = provisional; + SQLiteStorageHelper().pets = pets; + SQLiteStorageHelper().petAmountRegister = petAmountRegister; + SQLiteStorageHelper().cliName = name; safeSetState(() {}); return; @@ -100,9 +95,7 @@ class _LocalProfileComponentWidgetState try { final GetLocalsCall callback = PhpGroup.getLocalsCall; - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; var response = await callback.call(); List locals = response.jsonBody['locais'] ?? []; @@ -146,8 +139,6 @@ class _LocalProfileComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Container( decoration: const BoxDecoration(), child: Align( diff --git a/lib/components/organism_components/menu_component/menu_component_model.dart b/lib/components/organism_components/menu_component/menu_component_model.dart index 31e6e01a..0d61b860 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -3,7 +3,9 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:sqflite/sqflite.dart'; import '/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart'; @@ -70,11 +72,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future deliverySchedule(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - - final bool isProvisional = await db - .get(key: 'provisional', field: 'value') - .then((value) => value.toString() == 'true') as bool; + final bool isProvisional = SQLiteStorageHelper().provisional; if (isProvisional == true) { context.push( @@ -93,11 +91,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future provisionalSchedule(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - - final isProvisional = await db - .get(key: 'provisional', field: 'value') - .then((value) => value.toString() == 'true') as bool; + final isProvisional = SQLiteStorageHelper().provisional; if (isProvisional == true) { context.push( '/provisionalSchedule', @@ -115,10 +109,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future fastPassAction(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + final isWpp = SQLiteStorageHelper().whatsapp; if (isWpp) { context.push( '/fastPassPage', @@ -202,8 +193,6 @@ class MenuComponentModel extends FlutterFlowModel { } Future signOut(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - showAlertDialog( context, 'Logout', @@ -212,7 +201,7 @@ class MenuComponentModel extends FlutterFlowModel { ptText: 'Tem certeza', ), () async { PhpGroup.unregisterDevice.call(); - AppState().deleteAll(); + StorageManager.purge(); context.go( '/welcomePage', @@ -224,7 +213,7 @@ class MenuComponentModel extends FlutterFlowModel { ), }, ); - await db.purge(); + await SQLiteStorageHelper().purge(); }); } @@ -242,10 +231,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future packageOrder(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + final isWpp = SQLiteStorageHelper().whatsapp; if (isWpp) { context.push( @@ -264,10 +250,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future reservation(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final isWpp = await db.get(key: 'whatsapp', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + final isWpp = SQLiteStorageHelper().whatsapp; if (isWpp) { context.push( '/reservation', @@ -383,10 +366,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future petsAction(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - bool isPet = await db.get(key: 'pets', field: 'value').then((value) { - return value.toString() == 'true'; - }) as bool; + bool isPet = SQLiteStorageHelper().pets; if (isPet) { context.push( '/petsPage', diff --git a/lib/components/organism_components/message_well_component/message_well_component_widget.dart b/lib/components/organism_components/message_well_component/message_well_component_widget.dart index 1965a718..81de018c 100644 --- a/lib/components/organism_components/message_well_component/message_well_component_widget.dart +++ b/lib/components/organism_components/message_well_component/message_well_component_widget.dart @@ -339,7 +339,6 @@ class MessageWellState { class MessageWellNotifier extends StateNotifier { var _totalPageNumber = 1; int get totalPageNumber => _totalPageNumber; - final SQLiteStorageHelper db = SQLiteStorageHelper(); set totalPageNumber(int value) { _totalPageNumber = value; diff --git a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart index 86911a2b..1edff6aa 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart @@ -10,7 +10,6 @@ import 'package:intl/intl.dart'; class ScheduleVisitDetailModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -60,9 +59,9 @@ class ScheduleVisitDetailModel } Future initDB() async { - devUUID = await db.get(key: 'devUUID', field: 'value'); - userUUID = await db.get(key: 'userUUID', field: 'value'); - cliUUID = await db.get(key: 'cliUUID', field: 'value'); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart index b347c157..9051c4d5 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart @@ -94,7 +94,6 @@ class _ScheduleVisitDetailWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); final visitorsData = widget.visitorJsonList!.toList().take(2).toList(); final visitorsDataItem = visitorsData[0]; diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart index bbfbdbda..fff98ee1 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart @@ -6,7 +6,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -18,18 +17,10 @@ class UpArrowLinkedLocalsComponentModel } Future initDB() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + cliName = SQLiteStorageHelper().cliName; } @override diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart index 85ca7b2c..d2a448e5 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart @@ -42,8 +42,6 @@ class _UpArrowLinkedLocalsComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Align( alignment: const AlignmentDirectional(0.0, -1.0), child: Container( diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart index 267e858b..a24124ac 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart @@ -9,7 +9,6 @@ import 'access_notification_modal_template_component_widget.dart' class AccessNotificationModalTemplateComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -33,15 +32,9 @@ class AccessNotificationModalTemplateComponentModel } Future initDB() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart index ffb2bd97..999fcf5b 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_widget.dart @@ -67,8 +67,6 @@ class _AccessNotificationModalTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - String labelTypeResident = FFLocalizations.of(context) .getVariableText(enText: 'Resident', ptText: 'Morador'); diff --git a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart index 01386be5..80be7d12 100644 --- a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart +++ b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart @@ -208,8 +208,6 @@ class _CardItemTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return InkWell( splashColor: Colors.transparent, focusColor: Colors.transparent, diff --git a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart index 36f51006..832f2cd6 100644 --- a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart +++ b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; @@ -129,7 +130,7 @@ class _PassKeyTemplateWidgetState extends State { child: Text( FFLocalizations.of(context).getVariableText( enText: 'INSERT PASSWORD', - ptText: AppState().accessPass != '' + ptText: SecureStorageHelper().accessPass != '' ? 'ALTERAR SENHA' : 'ADICIONAR SENHA', ), @@ -316,9 +317,12 @@ class _PassKeyTemplateWidgetState extends State { context.pop(true); }, text: FFLocalizations.of(context).getVariableText( - ptText: - AppState().accessPass != '' ? 'Alterar' : 'Adicionar', - enText: AppState().accessPass != '' ? 'Change' : 'Add', + ptText: SecureStorageHelper().accessPass != '' + ? 'Alterar' + : 'Adicionar', + enText: SecureStorageHelper().accessPass != '' + ? 'Change' + : 'Add', ), options: FFButtonOptions( width: 270.0, diff --git a/lib/components/templates_components/details_component/details_component_widget.dart b/lib/components/templates_components/details_component/details_component_widget.dart index 48bf6691..ee959e7f 100644 --- a/lib/components/templates_components/details_component/details_component_widget.dart +++ b/lib/components/templates_components/details_component/details_component_widget.dart @@ -64,7 +64,6 @@ class _DetailsComponentWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); // CachedNetworkImage.evictFromCache(widget.imagePath ?? ''); return Container( diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart index 928bcbd4..e6653c0b 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart @@ -9,7 +9,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class LiberationHistoryItemDetailsTemplateComponentModel extends FlutterFlowModel< LiberationHistoryItemDetailsTemplateComponentWidget> { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -31,15 +30,9 @@ class LiberationHistoryItemDetailsTemplateComponentModel void initState(BuildContext context) {} Future initDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart index 23c6a71e..23a0d124 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart @@ -68,8 +68,6 @@ class _LiberationHistoryItemDetailsTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Align( alignment: const AlignmentDirectional(0.0, 0.0), child: Padding( diff --git a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart index 31b859f5..303780ca 100644 --- a/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart +++ b/lib/components/templates_components/message_notificaion_modal_template_component/message_notification_widget.dart @@ -59,8 +59,6 @@ class _MessageNotificationModalTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart index 0f3ad802..d62becb1 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart @@ -7,7 +7,6 @@ import 'package:sqflite/sqflite.dart'; class ScheduleProvisionalVisitPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); String cliUUID = ''; String devUUID = ''; String userUUID = ''; @@ -125,11 +124,11 @@ class ScheduleProvisionalVisitPageModel } Future init() async { - cliUUID = await db.get(key: 'cliUUID', field: 'value'); - devUUID = await db.get(key: 'devUUID', field: 'value'); - userUUID = await db.get(key: 'userUUID', field: 'value'); - cliName = await db.get(key: 'cliName', field: 'value'); - ownerUUID = await db.get(key: 'ownerUUID', field: 'value'); + cliUUID = SQLiteStorageHelper().cliUUID; + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliName = SQLiteStorageHelper().cliName; + ownerUUID = SQLiteStorageHelper().ownerUUID; setState?.call(); } diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart index b2b1b4cd..d3041fa1 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart @@ -42,8 +42,6 @@ class _ScheduleProvisionalVisitPageWidgetState @override Widget build(BuildContext context) { - context.watch(); - return GestureDetector( onTap: () => FocusScope.of(context).unfocus(), child: SingleChildScrollView( diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart index 9328aa5b..cd667c8e 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart @@ -12,7 +12,6 @@ import 'regisiter_vistor_template_component_widget.dart'; class RegisiterVistorTemplateComponentModel extends FlutterFlowModel { Timer? _debounceTimer; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -135,9 +134,9 @@ class RegisiterVistorTemplateComponentModel } Future initializeDatabase() async { - devUUID = await db.get(key: 'devUUID', field: 'value'); - userUUID = await db.get(key: 'userUUID', field: 'value'); - cliUUID = await db.get(key: 'cliUUID', field: 'value'); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart index eeb79823..3bd63a0e 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart @@ -121,7 +121,6 @@ class _RegisiterVistorTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); return Align( alignment: const AlignmentDirectional(0.0, 1.0), child: Container( diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart index 1a2eb353..677dac66 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart @@ -3,6 +3,7 @@ import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/flutter_flow/random_data_util.dart'; import 'package:hub/pages/home_page/home_page_model.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/device_util.dart'; import 'package:hub/shared/utils/dialog_util.dart'; @@ -86,9 +87,8 @@ class SignInTemplateComponentModel }) async { try { final ApiCallResponse? response; - final SQLiteStorageHelper db = SQLiteStorageHelper(); final LoginCall callback = PhpGroup.loginCall; - AppState().deviceDescription = randomString( + SecureStorageHelper().deviceDescription = randomString( 10, 10, true, @@ -111,8 +111,8 @@ class SignInTemplateComponentModel devUUID = await DeviceUtil.getDevUUID(); if ((email != '') && (passwd != '')) { - AppState().email = email; - AppState().passwd = passwd; + SecureStorageHelper().email = email; + SecureStorageHelper().passwd = passwd; response = await callback.call(); if (response.jsonBody['error'] == false) { @@ -122,17 +122,17 @@ class SignInTemplateComponentModel userDevUUID = response.jsonBody['user']['dev_id']; userName = response.jsonBody['user']['name']; - db.update('devUUID', devUUID, 'user'); - db.update('userUUID', userUUID, 'user'); - db.update('userDevUUID', userDevUUID, 'user'); - db.update('status', status, 'user'); - db.update('userName', userName, 'user'); + SQLiteStorageHelper().devUUID = devUUID!; + SQLiteStorageHelper().userUUID = userUUID; + SQLiteStorageHelper().userDevUUID = userDevUUID; + SQLiteStorageHelper().status = status; + SQLiteStorageHelper().userName = userName; isLogged = true; await checkLocals(context: context, model: model).then((value) { - AppState().haveLocal = value; - AppState().isLogged = isLogged; - AppState().update(() {}); + SecureStorageHelper().haveLocal = value; + SecureStorageHelper().isLogged = isLogged; + SecureStorageHelper().update(() {}); toggleApp(context); }); } else { @@ -154,7 +154,7 @@ class SignInTemplateComponentModel } Future toggleApp(BuildContext context) async { - final haveLocal = AppState().haveLocal; + final haveLocal = SecureStorageHelper().haveLocal; if (haveLocal == true) { context.go('/homePage'); } else if (haveLocal == false) { diff --git a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart index fe35911d..59fc1cc5 100644 --- a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart +++ b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter_animate/flutter_animate.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/atom_image_svg_theme.dart'; import 'package:hub/shared/components/atoms/atom_terms_of_use.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import 'package:provider/provider.dart'; @@ -124,8 +125,6 @@ class _SignUpTemplateComponentWidgetState return false; } - context.watch(); - return Row( mainAxisSize: MainAxisSize.max, children: [ @@ -702,7 +701,8 @@ class _SignUpTemplateComponentWidgetState .emailRegisterFormTextController .text, device: - AppState().deviceType, + SecureStorageHelper() + .deviceType, ); shouldSetState = true; if (_model.signUp == true) { diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart index 046448b1..8bb70b0d 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart @@ -6,7 +6,6 @@ import 'view_visit_detail_widget.dart' show ViewVisitDetailWidget; import 'package:flutter/material.dart'; class ViewVisitDetailModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -37,15 +36,9 @@ class ViewVisitDetailModel extends FlutterFlowModel { } Future initializeDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart b/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart index 65c992c0..d58b7043 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_widget.dart @@ -121,8 +121,6 @@ class _ViewVisitDetailWidgetState extends State { var filteredVisitorJsonList = findVisitorById(widget.visitorJsonList, widget.visitIdStr) ?? 'null'; - context.watch(); - return Padding( padding: const EdgeInsetsDirectional.fromSTEB(0.0, 200.0, 0.0, 0.0), child: Container( diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart index f1efb91a..7c06018b 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart @@ -7,7 +7,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -40,15 +39,9 @@ class VisitorSearchModalTemplateComponentModel } Future initDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart index e1982ac3..713cc6f8 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart @@ -59,8 +59,6 @@ class _VisitorSearchModalTemplateComponentWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Padding( padding: const EdgeInsetsDirectional.fromSTEB(0.0, 10.0, 0.0, 0.0), child: Container( diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 3947cd2b..013fcb8f 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -10,6 +10,7 @@ import 'package:hub/pages/pets_page/pets_page_widget.dart'; import 'package:hub/pages/provisional_schedule_page/provisional_schedule_widget.dart'; import 'package:hub/pages/reception_page/reception_page_widget.dart'; import 'package:hub/pages/reservation_page/reservation_page_widget.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:provider/provider.dart'; import '/backend/schema/structs/index.dart'; @@ -72,8 +73,8 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter( FFRoute( name: '_initialize', path: '/', - builder: (context, _) => AppState().isLogged - ? AppState().haveLocal == true + builder: (context, _) => SecureStorageHelper().isLogged + ? SecureStorageHelper().haveLocal == true ? const HomePageWidget() : const ReceptionPageWidget() : const WelcomePageWidget(), diff --git a/lib/main.dart b/lib/main.dart index b75c9dda..bb8f1ff7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -26,18 +26,20 @@ final GlobalKey navigatorKey = GlobalKey(); Future initializeApp() async { WidgetsFlutterBinding.ensureInitialized(); await SQLiteStorageHelper().database; - final sharedPreferencesHelper = SharedPreferencesStorageHelper(); + SQLiteStorageHelper().deleteDatabaseDB(); + final SharedPreferencesStorageHelper sharedPreferencesHelper = + SharedPreferencesStorageHelper(); final SecureStorageHelper secureStorageHelper = SecureStorageHelper(); - await sharedPreferencesHelper.initialize(); + await sharedPreferencesHelper.ensureInitialization(); + await secureStorageHelper.ensureInitilization(); if (sharedPreferencesHelper.isFirstRun) { - // Execute actions for the first run sharedPreferencesHelper.isFirstRun = false; - secureStorageHelper.deleteAll(); + secureStorageHelper.purge(); } - final status = await AppTrackingTransparency.requestTrackingAuthorization(); + await AppTrackingTransparency.requestTrackingAuthorization(); await Firebase.initializeApp(); await NotificationService.initialize(); @@ -61,7 +63,7 @@ Future initializeApp() async { Future foregroundHandleMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - SecureStorageHelper().set('haveLocal', 'true'); + SecureStorageHelper().haveLocal = true; SecureStorageHelper().context?.go('/homePage'); } if (!Platform.isIOS) { @@ -123,6 +125,8 @@ class _AppState extends State { _backgroundHandleMessage(message); } }); + + // SecureStorageHelper().isLogged = false; } void setLocale(String language) { @@ -139,67 +143,62 @@ class _AppState extends State { @override Widget build(BuildContext context) { - return MultiProvider( - providers: const [], - // ChangeNotifierProvider(create: (_) => {AppState()}), - - child: MaterialApp.router( - title: 'FRE ACCESS HUB', - builder: (context, widget) => ResponsiveBreakpoints.builder( - child: BouncingScrollWrapper.builder(context, widget!), - breakpoints: [ - const Breakpoint(start: 0, end: 450, name: MOBILE), - const Breakpoint(start: 451, end: 800, name: TABLET), - const Breakpoint(start: 801, end: 1920, name: DESKTOP), - const Breakpoint(start: 1921, end: double.infinity, name: '4K'), - ], - ), - localizationsDelegates: const [ - FFLocalizationsDelegate(), - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, + return MaterialApp.router( + title: 'FRE ACCESS HUB', + builder: (context, widget) => ResponsiveBreakpoints.builder( + child: BouncingScrollWrapper.builder(context, widget!), + breakpoints: [ + const Breakpoint(start: 0, end: 450, name: MOBILE), + const Breakpoint(start: 451, end: 800, name: TABLET), + const Breakpoint(start: 801, end: 1920, name: DESKTOP), + const Breakpoint(start: 1921, end: double.infinity, name: '4K'), ], - locale: _locale, - supportedLocales: const [ - Locale('pt'), - Locale('en'), - ], - theme: ThemeData( - brightness: Brightness.light, - scrollbarTheme: ScrollbarThemeData( - thumbVisibility: WidgetStateProperty.all(false), - interactive: false, - thumbColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.dragged)) { - return const Color(0xff1aab5f); - } - if (states.contains(WidgetState.hovered)) { - return const Color(0xff1aab5f); - } - return const Color(0xff1aab5f); - }), - ), - ), - darkTheme: ThemeData( - brightness: Brightness.dark, - scrollbarTheme: ScrollbarThemeData( - thumbVisibility: WidgetStateProperty.all(false), - interactive: false, - thumbColor: WidgetStateProperty.resolveWith((states) { - if (states.contains(WidgetState.dragged)) { - return const Color(0xff1aab5f); - } - if (states.contains(WidgetState.hovered)) { - return const Color(0xff1aab5f); - } - return const Color(0xff1aab5f); - }), - ), - ), - themeMode: _themeMode, - routerConfig: _router, ), + localizationsDelegates: const [ + FFLocalizationsDelegate(), + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + locale: _locale, + supportedLocales: const [ + Locale('pt'), + Locale('en'), + ], + theme: ThemeData( + brightness: Brightness.light, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: WidgetStateProperty.all(false), + interactive: false, + thumbColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.dragged)) { + return const Color(0xff1aab5f); + } + if (states.contains(WidgetState.hovered)) { + return const Color(0xff1aab5f); + } + return const Color(0xff1aab5f); + }), + ), + ), + darkTheme: ThemeData( + brightness: Brightness.dark, + scrollbarTheme: ScrollbarThemeData( + thumbVisibility: WidgetStateProperty.all(false), + interactive: false, + thumbColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.dragged)) { + return const Color(0xff1aab5f); + } + if (states.contains(WidgetState.hovered)) { + return const Color(0xff1aab5f); + } + return const Color(0xff1aab5f); + }), + ), + ), + themeMode: _themeMode, + routerConfig: _router, ); } } diff --git a/lib/pages/acess_history_page/acess_history_page_model.dart b/lib/pages/acess_history_page/acess_history_page_model.dart index db3be583..93e9de78 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -7,7 +7,6 @@ import 'package:hub/pages/acess_history_page/acess_history_page_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class AcessHistoryPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -34,15 +33,9 @@ class AcessHistoryPageModel extends FlutterFlowModel { } Future initDatabase() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart b/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart index cfe5ef5e..357b751f 100644 --- a/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart +++ b/lib/pages/delivery_schedule_page/delivery_schedule_widget.dart @@ -31,7 +31,6 @@ class _DeliveryScheduleState extends State { @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/fast_pass_page/fast_pass_page_widget.dart b/lib/pages/fast_pass_page/fast_pass_page_widget.dart index 448b7219..1a732254 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -5,6 +5,7 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:url_launcher/url_launcher_string.dart'; @@ -18,30 +19,19 @@ class FastPassPageWidget extends StatefulWidget { class _FastPassPageWidgetState extends State { late InAppWebViewController _controllerIOS; late WebViewController _controllerAll; - final SQLiteStorageHelper db = SQLiteStorageHelper(); Future> initVariables() async { - final email = AppState().email; - final name = await db - .get(key: 'userName', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - final createdAt = await db - .get(key: 'devUUID', field: 'createdAt') - .then((value) => value.toString()); + final email = SecureStorageHelper().email; + final name = SQLiteStorageHelper().userName; + final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = SQLiteStorageHelper().devUUID; + final cliUUID = SQLiteStorageHelper().cliUUID; + final createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; final freUserData = "{\"name\": \"$name\", " + "\"email\": \"$email\"," + "\"dev_id\": \"$devUUID\"," + - "\"created_at\": \"$createdAt\"," + + "\"created_at\":\"$createdAt\"," + "\"updated_at\": \"0000-00-00 00:00:00\"," + "\"status\": \"A\" }"; diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index 242aa1d8..99505b0e 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -5,11 +5,11 @@ import 'package:hub/components/organism_components/menu_component/menu_component import 'package:hub/components/organism_components/message_well_component/message_well_component_model.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/home_page/home_page_widget.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class HomePageModel extends FlutterFlowModel { bool isGrid = false; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String cliUUID; late final String userUUID; @@ -25,19 +25,11 @@ class HomePageModel extends FlutterFlowModel { late MessageWellComponentModel messageWellComponentModel; Future _initVariable() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - userName = await db - .get(key: 'userName', field: 'value') - .then((value) => value.toString()); - userEmail = AppState().email; + devUUID = SQLiteStorageHelper().devUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + userUUID = SQLiteStorageHelper().userUUID; + userName = SQLiteStorageHelper().cliName; + userEmail = SecureStorageHelper().email; } @override diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index dc634217..949e94d0 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -11,6 +11,7 @@ import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/home_page/home_page_model.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart'; @@ -25,7 +26,6 @@ class _HomePageWidgetState extends State { late HomePageModel _model; final scaffoldKey = GlobalKey(); late LocalProfileComponentWidget _localProfileComponentWidget; - final SQLiteStorageHelper db = SQLiteStorageHelper(); _HomePageWidgetState() { _localProfileComponentWidget = LocalProfileComponentWidget(); @@ -52,7 +52,7 @@ class _HomePageWidgetState extends State { @override Widget build(BuildContext context) { - AppState().context = context; + SecureStorageHelper().context = context; return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index 23db4207..e0d075ed 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -8,7 +8,6 @@ import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class LiberationHistoryModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -39,15 +38,9 @@ class LiberationHistoryModel extends FlutterFlowModel { } Future init() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliName; } Future answersRequest( diff --git a/lib/pages/liberation_history/liberation_history_widget.dart b/lib/pages/liberation_history/liberation_history_widget.dart index 42bda80d..65811564 100644 --- a/lib/pages/liberation_history/liberation_history_widget.dart +++ b/lib/pages/liberation_history/liberation_history_widget.dart @@ -90,7 +90,6 @@ class _LiberationHistoryWidgetState extends State { @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/message_history_page/message_history_page_model.dart b/lib/pages/message_history_page/message_history_page_model.dart index 49857b82..f2b8300b 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -9,7 +9,6 @@ import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; class MessageHistoryPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -44,15 +43,9 @@ class MessageHistoryPageModel } Future init() async { - devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/pages/message_history_page/message_history_page_widget.dart b/lib/pages/message_history_page/message_history_page_widget.dart index 12407eed..625d274c 100644 --- a/lib/pages/message_history_page/message_history_page_widget.dart +++ b/lib/pages/message_history_page/message_history_page_widget.dart @@ -85,7 +85,6 @@ class _MessageHistoryPageWidgetState extends State @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index a4d9898d..fae8194d 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -28,7 +28,6 @@ class _PackageOrderPage extends State { final int _pageSize = 10; bool _hasData = false; bool _loading = false; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String cliUUID; late Future _orderFuture; @@ -64,9 +63,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); + cliUUID = SQLiteStorageHelper().cliUUID; } @override diff --git a/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart b/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart index 04097a0d..f2f8ceac 100644 --- a/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart +++ b/lib/pages/people_on_the_property_page/people_on_the_property_page_widget.dart @@ -41,8 +41,6 @@ class _PeopleOnThePropertyPageWidgetState @override Widget build(BuildContext context) { - context.watch(); - return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index bee6cf74..8bbff0a5 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -243,19 +243,10 @@ class _PetsHistoryScreenState extends State } ], onTapCardItemAction: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = await db - .get(key: 'cliUUID', field: 'value') - .then((value) => value.toString()); - final cliName = await db - .get(key: 'cliName', field: 'value') - .then((value) => value.toString()); - final devUUID = await db - .get(key: 'devUUID', field: 'value') - .then((value) => value.toString()); - final userUUID = await db - .get(key: 'userUUID', field: 'value') - .then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; + final cliName = SQLiteStorageHelper().cliName; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; await showDialog( useSafeArea: true, context: context, diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index 927333aa..c024e854 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -19,7 +19,6 @@ import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; class PetsPageModel extends FlutterFlowModel { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -103,18 +102,10 @@ class PetsPageModel extends FlutterFlowModel { String? Function(BuildContext, String?)? textControllerObservationValidator; Future initAsync() async { - devUUID = await db.get(key: 'devUUID', field: 'value').then((value) { - return value.toString(); - }); - userUUID = await db.get(key: 'userUUID', field: 'value').then((value) { - return value.toString(); - }); - cliUUID = await db.get(key: 'cliUUID', field: 'value').then((value) { - return value.toString(); - }); - petAmountRegister = await db - .get(key: 'petAmountRegister', field: 'value') - .then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + petAmountRegister = SQLiteStorageHelper().petAmountRegister.toString(); safeSetState?.call(); } diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 7fa32d78..443c28b0 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -6,13 +6,14 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:share_plus/share_plus.dart'; import 'package:sqflite/sqflite.dart'; class PreferencesPageModel with ChangeNotifier { final unfocusNode = FocusNode(); - final SQLiteStorageHelper db = SQLiteStorageHelper(); bool fingerprint = false; bool person = false; bool notify = false; @@ -24,7 +25,7 @@ class PreferencesPageModel with ChangeNotifier { } Future enablePerson(BuildContext context) async { - final String userDevUUID = await db.get(key: 'userDevUUID', field: 'value'); + final String userDevUUID = SQLiteStorageHelper().userDevUUID; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( @@ -69,7 +70,7 @@ class PreferencesPageModel with ChangeNotifier { Future toggleAccess(BuildContext context) async { onChange(String key) async { - AppState().accessPass = key; + SecureStorageHelper().accessPass = key; await PhpGroup.changePass .call( newSenha: key, @@ -105,10 +106,10 @@ class PreferencesPageModel with ChangeNotifier { Future togglePanic(BuildContext context) async { onChange(String key) async { - AppState().panicPass = key; + SecureStorageHelper().panicPass = key; await PhpGroup.changePanic .call( - newSenhaPanico: AppState().panicPass, + newSenhaPanico: SecureStorageHelper().panicPass, ) .then((value) async { final String content; @@ -146,8 +147,8 @@ class PreferencesPageModel with ChangeNotifier { ); onChange(String? key) async { - if (!fingerprint) AppState().fingerprintPass = key ?? ''; - if (fingerprint) AppState().deleteFingerprintPass(); + if (!fingerprint) SecureStorageHelper().fingerprintPass = key ?? ''; + if (fingerprint) SecureStorageHelper().delete('fingerprintPass'); fingerprint = await _toggleBoolInDb('fingerprint'); notifyListeners(); @@ -177,7 +178,7 @@ class PreferencesPageModel with ChangeNotifier { ptText: 'Conta deletada com sucesso', ); - AppState().deleteAll(); + StorageManager.purge(); context.pop(); context.go( @@ -223,7 +224,7 @@ class PreferencesPageModel with ChangeNotifier { ptText: 'Tem certeza que deseja sair?', ); onConfirm() async { - AppState().deleteAll(); + StorageManager.purge(); context.go( '/welcomePage', @@ -259,9 +260,9 @@ class PreferencesPageModel with ChangeNotifier { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) { if (value.jsonBody['error'] == false) { - db.clear('cliName'); - db.clear('cliUUID'); - db.clear('ownerUUID'); + SQLiteStorageHelper().cliName = ''; + SQLiteStorageHelper().cliUUID = ''; + SQLiteStorageHelper().ownerUUID = ''; context.pop(); @@ -310,14 +311,15 @@ class PreferencesPageModel with ChangeNotifier { } Future _getBoolFromDb(String key) async { - final value = await db.get(key: key, field: 'value'); + final value = SQLiteStorageHelper().get(key); return value.toString() == 'true'; } Future _toggleBoolInDb(String key) async { final currentValue = await _getBoolFromDb(key); final newValue = !currentValue; - await db.update(key, newValue.toString(), 'util'); + await SQLiteStorageHelper().set(key, newValue.toString()); + return newValue; } diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index 12a3fedb..e58d1dd8 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -7,6 +7,7 @@ import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/preferences_settings_page/preferences_settings_model.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; +import 'package:hub/shared/utils/storage_util.dart'; import 'package:provider/provider.dart'; class PreferencesPageWidget extends StatefulWidget { @@ -17,8 +18,6 @@ class PreferencesPageWidget extends StatefulWidget { } class _PreferencesPageWidgetState extends State { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - @override void initState() { super.initState(); @@ -240,7 +239,7 @@ class _PreferencesPageWidgetState extends State { enText: 'Are you sure you want to logout?', ptText: 'Tem certeza', ), () async { - AppState().deleteAll(); + StorageManager.purge(); // setState(() {}); context.go( diff --git a/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart b/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart index 42afd259..d7a11ba3 100644 --- a/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart +++ b/lib/pages/provisional_schedule_page/provisional_schedule_widget.dart @@ -31,7 +31,6 @@ class _ProvisionalScheduleState extends State { @override Widget build(BuildContext context) { - context.watch(); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/pages/qr_code_page/qr_code_page_model.dart b/lib/pages/qr_code_page/qr_code_page_model.dart index af6298d5..eca74dac 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -14,7 +14,6 @@ class QrCodePageModel extends FlutterFlowModel { String? key = null; DateTime? time; - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final bool isFingerprint; late final String userDevUUID; @@ -28,9 +27,8 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = - await db.get('fingerprint').then((value) => value.toString() == 'true'); - userDevUUID = await db.get('userDevUUID').then((value) => value.toString()); + isFingerprint = SQLiteStorageHelper().fingerprint; + userDevUUID = SQLiteStorageHelper().userDevUUID; } @override diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index 89343a1c..a1c9f048 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -6,9 +6,7 @@ import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final String userDevUUID = - await db.get('userDevUUID').then((value) => value.toString()); + final String userDevUUID = SQLiteStorageHelper().userDevUUID; notifyListeners(); Share.share( diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index e9e87ed6..6d47a096 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -6,6 +6,7 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/app_state.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/secure_storage_helper.dart'; import 'package:hub/shared/helpers/sqlite_storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:sqflite/sqflite.dart'; @@ -18,26 +19,23 @@ class ReservationPageWidget extends StatefulWidget { } class _ReservationPageWidgetState extends State { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late InAppWebViewController _controllerIOS; late WebViewController _controllerAll; Future> initVariables() async { - final email = await db.get('email').then((value) => value.toString()); - final name = await db.get('userName').then((value) => value.toString()); - final userUUID = await db.get('userUUID').then((value) => value.toString()); - final devUUID = await db.get('devUUID').then((value) => value.toString()); - final createdAt = await db - .getByField(key: 'devUUID', field: 'createdAt') - .then((value) => value.toString()); - final clientId = await db.get('cliUUID').then((value) => value.toString()); + final email = SecureStorageHelper().email; + final name = SQLiteStorageHelper().cliName; + final userUUID = SQLiteStorageHelper().userUUID; + final devUUID = SQLiteStorageHelper().devUUID; + final createdAt = SQLiteStorageHelper().createdAt; + final clientId = SQLiteStorageHelper().cliUUID; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; final freUserData = "{\"name\": \"$name\", " + "\"email\": \"$email\"," + "\"dev_id\": \"$devUUID\"," + - "\"created_at\": \"$createdAt\"," + + "\"created_at\": \"0000-00-00 00:00:00\"," + "\"updated_at\": \"0000-00-00 00:00:00\"," + "\"status\": \"A\" }"; diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart index 50ed979b..3c0aafd5 100644 --- a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart +++ b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart @@ -1,5 +1,3 @@ -import 'dart:ffi'; - import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/templates_components/details_component/details_component_widget.dart'; @@ -26,7 +24,6 @@ class ScheduleCompleteVisitPageModel late VoidCallback safeSetState; late Function(Function) updateState; final _visitHistoryManager = FutureRequestManager(); - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String cliUUID; late final String userUUID; @@ -184,9 +181,9 @@ class ScheduleCompleteVisitPageModel } Future _initVariables() async { - devUUID = await db.get('devUUID').then((value) => value.toString()); - cliUUID = await db.get('cliUUID').then((value) => value.toString()); - userUUID = await db.get('userUUID').then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + cliUUID = SQLiteStorageHelper().cliUUID; + userUUID = SQLiteStorageHelper().userUUID; } @override diff --git a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart index 292f212b..d07f5759 100644 --- a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart @@ -20,7 +20,6 @@ class VisitHistoryWidget extends ScheduleComplete { class _VisitHistoryWidgetState extends State with TickerProviderStateMixin, Status { - final SQLiteStorageHelper db = SQLiteStorageHelper(); late final String devUUID; late final String userUUID; late final String cliUUID; @@ -35,9 +34,9 @@ class _VisitHistoryWidgetState extends State List _visitWrap = []; Future _initVariables() async { - devUUID = await db.get('devUUID').then((value) => value.toString()); - userUUID = await db.get('userUUID').then((value) => value.toString()); - cliUUID = await db.get('cliUUID').then((value) => value.toString()); + devUUID = SQLiteStorageHelper().devUUID; + userUUID = SQLiteStorageHelper().userUUID; + cliUUID = SQLiteStorageHelper().cliUUID; } @override @@ -246,15 +245,11 @@ class _VisitHistoryWidgetState extends State }, ], onTapCardItemAction: () async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliUUID = - await db.get('cliUUID').then((value) => value.toString()); - final cliName = - await db.get('cliName').then((value) => value.toString()); - final devUUID = - await db.get('devUUID').then((value) => value.toString()); - final userUUID = - await db.get('userUUID').then((value) => value.toString()); + final cliUUID = SQLiteStorageHelper().cliUUID; + final cliName = SQLiteStorageHelper().cliName; + final devUUID = SQLiteStorageHelper().devUUID; + final userUUID = SQLiteStorageHelper().userUUID; + await showDialog( useSafeArea: true, context: context, diff --git a/lib/shared/helpers/secure_storage_helper.dart b/lib/shared/helpers/secure_storage_helper.dart index c46ce274..d01ece8e 100644 --- a/lib/shared/helpers/secure_storage_helper.dart +++ b/lib/shared/helpers/secure_storage_helper.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/utils/storage_util.dart'; import 'package:synchronized/synchronized.dart'; @@ -12,7 +13,91 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { SecureStorageHelper._internal(); - Future initializePersistedState() async { + String _deviceDescription = ''; + String get deviceDescription => _deviceDescription; + set deviceDescription(String value) { + _setString('deviceDescription', value); + _deviceDescription = value; + } + + BuildContext? _context; + BuildContext? get context => _context; + set context(BuildContext? value) { + _setString('ff_context', value.toString()); + _context = value; + } + + bool? _haveLocal; + bool? get haveLocal => _haveLocal; + set haveLocal(bool? value) { + _setBool('ff_have_local', value); + _haveLocal = value; + } + + String _fingerprintPass = ''; + String get fingerprintPass => _fingerprintPass; + set fingerprintPass(String value) { + _setString('fingerprintPass', value); + _fingerprintPass = value; + } + + String _accessPass = ''; + String get accessPass => _accessPass; + set accessPass(String value) { + _setString('accessPass', value); + _accessPass = value; + } + + String _panicPass = ''; + String get panicPass => _panicPass; + set panicPass(String value) { + _setString('panicPass', value); + _panicPass = value; + } + + String? _tokenAPNS = ''; + String? get tokenAPNS => _tokenAPNS; + set tokenAPNS(String? value) { + _setString('ff_tokenAPNS', value ?? ''); + _tokenAPNS = value; + } + + String _email = ''; + String get email => _email; + set email(String value) { + _setString('ff_email', value); + _email = value; + } + + String _passwd = ''; + String get passwd => _passwd; + set passwd(String value) { + _setString('ff_passwd', value); + _passwd = value; + } + + String _deviceType = ''; + String get deviceType => _deviceType; + set deviceType(String value) { + _setString('ff_deviceType', value); + _deviceType = value; + } + + bool _isLogged = false; + bool get isLogged => _isLogged; + set isLogged(bool value) { + _setBool('ff_isLogged', value); + _isLogged = value; + } + + String _token = ''; + String get token => _token; + set token(String value) { + _setString('ff_token', value); + _token = value; + } + + Future ensureInitilization() async { await _safeInitAsync(() async { _email = await _getString('ff_email'); _passwd = await _getString('ff_passwd'); @@ -56,55 +141,6 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { notifyListeners(); } - String _deviceDescription = ''; - String get deviceDescription => _deviceDescription; - set deviceDescription(String value) => _setString('deviceDescription', value); - - BuildContext? _context; - BuildContext? get context => _context; - set context(BuildContext? value) => - _setString('ff_context', value.toString()); - - bool? _haveLocal; - bool? get haveLocal => _haveLocal; - set haveLocal(bool? value) => _setBool('ff_have_local', value); - - String _fingerprintPass = ''; - String get fingerprintPass => _fingerprintPass; - set fingerprintPass(String value) => _setString('fingerprintPass', value); - - String _accessPass = ''; - String get accessPass => _accessPass; - set accessPass(String value) => _setString('accessPass', value); - - String _panicPass = ''; - String get panicPass => _panicPass; - set panicPass(String value) => _setString('panicPass', value); - - String? _tokenAPNS = ''; - String? get tokenAPNS => _tokenAPNS; - set tokenAPNS(String? value) => _setString('ff_tokenAPNS', value ?? ''); - - String _email = ''; - String get email => _email; - set email(String value) => _setString('ff_email', value); - - String _passwd = ''; - String get passwd => _passwd; - set passwd(String value) => _setString('ff_passwd', value); - - String _deviceType = ''; - String get deviceType => _deviceType; - set deviceType(String value) => _setString('ff_deviceType', value); - - bool _isLogged = false; - bool get isLogged => _isLogged; - set isLogged(bool value) => _setBool('ff_isLogged', value); - - String _token = ''; - String get token => _token; - set token(String value) => _setString('ff_token', value); - Future _setString(String key, String value) async { await _secureStorage.write(key: key, value: value); } @@ -115,6 +151,7 @@ class SecureStorageHelper extends ChangeNotifier implements Storage { Future purge() async { _secureStorage.deleteAll(); + await ensureInitilization(); } @override diff --git a/lib/shared/helpers/shared_preferences_storage_helper.dart b/lib/shared/helpers/shared_preferences_storage_helper.dart index 99cacead..3fa85748 100644 --- a/lib/shared/helpers/shared_preferences_storage_helper.dart +++ b/lib/shared/helpers/shared_preferences_storage_helper.dart @@ -13,7 +13,7 @@ class SharedPreferencesStorageHelper implements Storage { SharedPreferencesStorageHelper._internal(); - Future initialize() async { + Future ensureInitialization() async { _prefs = await SharedPreferences.getInstance(); _isFirstRun = _prefs.getBool('first_run') ?? true; } @@ -61,5 +61,6 @@ class SharedPreferencesStorageHelper implements Storage { Future purge() async { await _prefs.clear(); + await ensureInitialization(); } } diff --git a/lib/shared/helpers/sqlite_storage_helper.dart b/lib/shared/helpers/sqlite_storage_helper.dart index d32e745c..57847414 100644 --- a/lib/shared/helpers/sqlite_storage_helper.dart +++ b/lib/shared/helpers/sqlite_storage_helper.dart @@ -1,3 +1,9 @@ +import 'package:hub/shared/utils/cache_util.dart'; +import 'package:sqflite/sqflite.dart'; +import 'dart:developer'; +import 'package:flutter/foundation.dart'; +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:path/path.dart'; @@ -14,11 +20,34 @@ class DatabaseConfig { static const String columnUpdateAt = 'updateAt'; static const String columnResolvedAt = 'resolvedAt'; static const String columnCreatedAt = 'createdAt'; + + static const List> initialData = [ + {'key': 'devUUID', 'value': '', 'type': 'user'}, + {'key': 'userUUID', 'value': '', 'type': 'user'}, + {'key': 'userDevUUID', 'value': '', 'type': 'user'}, + {'key': 'status', 'value': '', 'type': 'user'}, + {'key': 'userName', 'value': '', 'type': 'user'}, + {'key': 'cliUUID', 'value': '', 'type': 'local'}, + {'key': 'ownerUUID', 'value': '', 'type': 'local'}, + {'key': 'cliName', 'value': '', 'type': 'local'}, + {'key': 'whatsapp', 'value': 'false', 'type': 'util'}, + {'key': 'provisional', 'value': 'false', 'type': 'util'}, + {'key': 'pets', 'value': 'false', 'type': 'util'}, + {'key': 'local', 'value': 'false', 'type': 'util'}, + {'key': 'notify', 'value': 'false', 'type': 'util'}, + {'key': 'fingerprint', 'value': 'false', 'type': 'util'}, + {'key': 'access', 'value': 'false', 'type': 'util'}, + {'key': 'panic', 'value': 'false', 'type': 'util'}, + {'key': 'person', 'value': 'false', 'type': 'util'}, + {'key': 'requestOSnotification', 'value': 'false', 'type': 'util'}, + {'key': 'petAmountRegister', 'value': '', 'type': 'local'}, + ]; } class SQLiteStorageHelper { static final SQLiteStorageHelper _instance = SQLiteStorageHelper._internal(); static Database? _database; + static String? _databasePath; factory SQLiteStorageHelper() => _instance; @@ -30,9 +59,16 @@ class SQLiteStorageHelper { return _database!; } + Future _getDatabasePath() async { + if (_databasePath != null) return _databasePath!; + final databasesPath = await getDatabasesPath(); + _databasePath = join(databasesPath, DatabaseConfig.dbName); + log('Database path: $_databasePath'); + return _databasePath!; + } + Future _initDatabase() async { final path = await _getDatabasePath(); - log('Database path: $path'); return await openDatabase( path, version: DatabaseConfig.dbVersion, @@ -42,15 +78,9 @@ class SQLiteStorageHelper { onDowngrade: _onDowngrade, onConfigure: _onConfigure, ).catchError((error) { + log('Error initializing database: $error'); throw error; - }).whenComplete(() => log('Database initialized')); - } - - Future _getDatabasePath() async { - final databasesPath = await getDatabasesPath(); - final path = join(databasesPath, DatabaseConfig.dbName); - log('Database path: $path'); - return path; + }).whenComplete(() async => await setupLocalVariables()); } Future _onCreate(Database db, int version) async { @@ -70,31 +100,11 @@ class SQLiteStorageHelper { } Future _insertInitialData(Database db) async { - final initialData = [ - {'key': 'devUUID', 'value': '', 'type': 'user'}, - {'key': 'userUUID', 'value': '', 'type': 'user'}, - {'key': 'userDevUUID', 'value': '', 'type': 'user'}, - {'key': 'status', 'value': '', 'type': 'user'}, - {'key': 'userName', 'value': '', 'type': 'user'}, - {'key': 'cliUUID', 'value': '', 'type': 'local'}, - {'key': 'ownerUUID', 'value': '', 'type': 'local'}, - {'key': 'cliName', 'value': '', 'type': 'local'}, - {'key': 'whatsapp', 'value': 'false', 'type': 'util'}, - {'key': 'provisional', 'value': 'false', 'type': 'util'}, - {'key': 'pets', 'value': 'false', 'type': 'util'}, - {'key': 'local', 'value': 'false', 'type': 'util'}, - {'key': 'notify', 'value': 'false', 'type': 'util'}, - {'key': 'fingerprint', 'value': 'false', 'type': 'util'}, - {'key': 'access', 'value': 'false', 'type': 'util'}, - {'key': 'panic', 'value': 'false', 'type': 'util'}, - {'key': 'person', 'value': 'false', 'type': 'util'}, - {'key': 'requestOSnotification', 'value': 'false', 'type': 'util'}, - {'key': 'petAmountRegister', 'value': '', 'type': 'local'}, - ]; - - for (var data in initialData) { - await db.insert(DatabaseConfig.tableKeychain, data); + final batch = db.batch(); + for (var data in DatabaseConfig.initialData) { + batch.insert(DatabaseConfig.tableKeychain, data); } + await batch.commit(noResult: true); } Future _onOpen(Database db) async { @@ -123,151 +133,184 @@ class SQLiteStorageHelper { } } + String _devUUID = ''; + String _userUUID = ''; + String _userDevUUID = ''; + String _status = ''; + String _userName = ''; + String _cliUUID = ''; + String _ownerUUID = ''; + String _cliName = ''; + String _petAmountRegister = ''; + bool _whatsapp = false; + bool _provisional = false; + bool _pets = false; + bool _local = false; + bool _notify = false; + bool _fingerprint = false; + bool _access = false; + bool _panic = false; + bool _person = false; + bool _requestOSnotification = false; + + String get createdAt => '0000-00-00 00:00:00'; + String get devUUID => _devUUID; + String get userUUID => _userUUID; + String get userDevUUID => _userDevUUID; + String get status => _status; + String get userName => _userName; + String get cliUUID => _cliUUID; + String get ownerUUID => _ownerUUID; + String get cliName => _cliName; + String get petAmountRegister => _petAmountRegister; + bool get whatsapp => _whatsapp; + bool get provisional => _provisional; + bool get pets => _pets; + bool get local => _local; + bool get notify => _notify; + bool get fingerprint => _fingerprint; + bool get access => _access; + bool get panic => _panic; + bool get person => _person; + bool get requestOSnotification => _requestOSnotification; + + set devUUID(String value) => set('devUUID', value); + set userUUID(String value) => set('userUUID', value); + set userDevUUID(String value) => set('userDevUUID', value); + set status(String value) => set('status', value); + set userName(String value) => set('userName', value); + set cliUUID(String value) => set('cliUUID', value); + set ownerUUID(String value) => set('ownerUUID', value); + set cliName(String value) => set('cliName', value); + set petAmountRegister(String value) => set('petAmountRegister', value); + set whatsapp(bool value) => set('whatsapp', value); + set provisional(bool value) => set('provisional', value); + set pets(bool value) => set('pets', value); + set local(bool value) => set('local', value); + set notify(bool value) => set('notify', value); + set fingerprint(bool value) => set('fingerprint', value); + set access(bool value) => set('access', value); + set panic(bool value) => set('panic', value); + set person(bool value) => set('person', value); + set requestOSnotification(bool value) => set('requestOSnotification', value); + + Future setupLocalVariables() async { + log('Setting up local variables...'); + await _database?.transaction((txn) async { + final keys = [ + 'devUUID', + 'userUUID', + 'userDevUUID', + 'status', + 'userName', + 'cliUUID', + 'ownerUUID', + 'cliName', + 'whatsapp', + 'provisional', + 'pets', + 'local', + 'notify', + 'fingerprint', + 'access', + 'panic', + 'person', + 'requestOSnotification' + ]; + + final results = await Future.wait(keys.map((key) => get(key))); + + _devUUID = results[0]?.toString() ?? ''; + _userUUID = results[1]?.toString() ?? ''; + _userDevUUID = results[2]?.toString() ?? ''; + _status = results[3]?.toString() ?? ''; + _userName = results[4]?.toString() ?? ''; + _cliUUID = results[5]?.toString() ?? ''; + _ownerUUID = results[6]?.toString() ?? ''; + _cliName = results[7]?.toString() ?? ''; + _whatsapp = results[8] == 'true'; + _provisional = results[9] == 'true'; + _pets = results[10] == 'true'; + _local = results[11] == 'true'; + _notify = results[12] == 'true'; + _fingerprint = results[13] == 'true'; + _access = results[14] == 'true'; + _panic = results[15] == 'true'; + _person = results[16] == 'true'; + _requestOSnotification = results[17] == 'true'; + }); + } + + Future getBoolean(String key) async { + final value = await get(key); + return value == 'true'; + } + + Future get(String key) async { + final cachedValue = CacheUtil.get(key); + if (cachedValue != null) { + return cachedValue; + } + + try { + final db = await database; + final result = await db.query( + DatabaseConfig.tableKeychain, + columns: [DatabaseConfig.columnValue], + where: '${DatabaseConfig.columnKey} = ?', + whereArgs: [key], + ); + + if (result.isNotEmpty) { + final value = result.first[DatabaseConfig.columnValue]; + CacheUtil.set(key, value); + return value; + } + return null; + } catch (error) { + log('Error getting value for key $key: $error'); + return null; + } + } + + Future set(String key, dynamic value) async { + CacheUtil.set(key, value); + final db = await database; + final data = { + DatabaseConfig.columnKey: key, + DatabaseConfig.columnValue: value.toString(), + DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), + DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), + }; + + return await db.insert( + DatabaseConfig.tableKeychain, + data, + conflictAlgorithm: ConflictAlgorithm.replace, + ); + } + + Future delete(String key) async { + final db = await database; + return await db.transaction((txn) async { + return await txn.delete( + DatabaseConfig.tableKeychain, + where: '${DatabaseConfig.columnKey} = ?', + whereArgs: [key], + ); + }); + } + + Future purge() async { + await deleteDatabaseDB(); + await database; + log('Database purged'); + } + Future deleteDatabaseDB() async { final path = await _getDatabasePath(); await deleteDatabase(path); log('Database deleted'); _database = null; } - - Future getByField({String? key, String? field}) async { - try { - final db = await database; - List> queryResult; - - if (field != null && key != null) { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } else if (field != null) { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - ); - } else if (key != null) { - field = DatabaseConfig.columnValue; - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } else { - queryResult = await db.query(DatabaseConfig.tableKeychain); - } - - log('Query result for key: $key, field: $field -> $queryResult'); - - if (queryResult.isNotEmpty) { - return queryResult.first[field]; - } else { - return null; - } - } catch (error) { - log('Error getting: $error'); - return null; - } - } - - Future get(String? key) async { - try { - final db = await database; - List> queryResult; - const String field = DatabaseConfig.columnValue; - - if (key != null) { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } else { - queryResult = await db.query( - DatabaseConfig.tableKeychain, - columns: [field], - ); - } - - log('Query result for key: $key, field: $field -> $queryResult'); - - if (queryResult.isNotEmpty) { - return queryResult.first[field]; - } else { - return null; - } - } catch (error) { - log('Error getting: $error'); - return null; - } - } - - Future insert(String key, dynamic value, String? type) async { - final db = await database; - - final Map data = { - DatabaseConfig.columnKey: key, - DatabaseConfig.columnValue: value.toString(), - DatabaseConfig.columnType: type, - DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), - DatabaseConfig.columnResolvedAt: null, - DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), - }; - - log('Inserting: $data'); - return await db.insert(DatabaseConfig.tableKeychain, data); - } - - Future set(String key, dynamic value) async { - final db = await database; - - final Map data = { - DatabaseConfig.columnKey: key, - if (value != null) DatabaseConfig.columnValue: value.toString(), - // if (type != null) DatabaseConfig.columnType: type, - DatabaseConfig.columnUpdateAt: DateTime.now().toIso8601String(), - DatabaseConfig.columnResolvedAt: null, - DatabaseConfig.columnCreatedAt: DateTime.now().toIso8601String(), - }; - - log('Updating: $data'); - return await db.update( - DatabaseConfig.tableKeychain, - data, - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } - - Future clear(String key) async { - final db = await database; - - log('Setting value of key: $key to empty string'); - return await db.update( - DatabaseConfig.tableKeychain, - {DatabaseConfig.columnValue: ''}, - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } - - Future delete(String key) async { - final db = await database; - - log('Deleting key: $key'); - return await db.delete( - DatabaseConfig.tableKeychain, - where: '${DatabaseConfig.columnKey} = ?', - whereArgs: [key], - ); - } - - Future purge() async { - await deleteDatabaseDB(); - await database; - log('Purge'); - } } diff --git a/lib/shared/utils/cache_util.dart b/lib/shared/utils/cache_util.dart index 01855fd2..548c56c1 100644 --- a/lib/shared/utils/cache_util.dart +++ b/lib/shared/utils/cache_util.dart @@ -1,5 +1,3 @@ -class CacheManager {} - class CacheUtil { static final Map _cache = {}; diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index 5d095261..61729bfc 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -3,9 +3,8 @@ import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final SQLiteStorageHelper db = SQLiteStorageHelper(); - final cliName = await db.get('cliName').then((value) => value.toString()); - final cliUUID = await db.get('cliUUID').then((value) => value.toString()); + final cliName = SQLiteStorageHelper().cliName; + final cliUUID = SQLiteStorageHelper().cliUUID; for (var i = 0; i < payload['convites'].length; i++) { await Share.share('''