From 28294038148b07bc1f5f3d2d8a2e670bfe34c72e Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 12 Nov 2024 14:36:41 -0300 Subject: [PATCH 01/75] WIP --- lib/backend/api_requests/api_calls.dart | 63 ++++++++++++++++ .../services/license/license_service.dart | 74 +++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 lib/shared/services/license/license_service.dart diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index e1dac19a..9d4484f8 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -56,8 +56,71 @@ class PhpGroup { static GetPets getPets = GetPets(); static GetPetPhoto getPetPhoto = GetPetPhoto(); static UnregisterDevice unregisterDevice = UnregisterDevice(); + static GetLicense getLicense = GetLicense(); + static TestCall testCall = TestCall(); } +class TestCall { + Future call() async { + const String accessKey = 'af7483f'; + const String usuEmail = 'email_app@exemplo.com'; + const String idDestino = '1'; + + return ApiManager.instance.makeApiCall( + callName: 'getLicense', + apiUrl: 'https://residenceapi.fre.com.br/getLicenca.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'AccessKey': accessKey, + 'UsuEmail': usuEmail, + 'idDestino': idDestino, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + isStreamingApi: false, + alwaysAllowBody: false, + ); + } +} + +class GetLicense { + Future call() async { + final String baseUrl = PhpGroup.getBaseUrl(); + final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + + return ApiManager.instance.makeApiCall( + callName: 'getLicense', + apiUrl: '$baseUrl/processRequest.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'atividade': 'getLicenca', + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + isStreamingApi: false, + alwaysAllowBody: false, + ); + } +} + + class UnregisterDevice { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart new file mode 100644 index 00000000..51f234c4 --- /dev/null +++ b/lib/shared/services/license/license_service.dart @@ -0,0 +1,74 @@ +// ignore_for_file: curly_braces_in_flow_control_structures, prefer_is_empty + +import 'dart:developer'; + +import 'package:hub/backend/api_requests/api_calls.dart'; +import 'dart:convert'; + +class LicenseService { + static final LicenseService _instance = LicenseService._internal(); + + factory LicenseService() => _instance; + LicenseService._internal(); + + List _modules = []; + + List get modules => List.unmodifiable(_modules); + + Future initLicenseService() async { + await _fetchLicenses(); + } + + Future _fetchLicenses() async { + try { + log('Obtendo licenças...'); + final ApiCallResponse response = await PhpGroup.testCall(); + final String responseBody = response.jsonBody.toString(); + + if (responseBody.isEmpty) { + throw Exception('Licensa ausente ou vazia.'); + } + + // if (responseBody == "[]") { + // log('Nenhuma licença encontrada.'); + // _modules = []; + // log('() MOD => $_modules'); + // return; + // } + + final dynamic jsonBody = jsonDecode(responseBody); + + if (jsonBody is Map && jsonBody['error'] == true) { + final String error = jsonBody['error_msg'] ?? 'Erro desconhecido'; + throw Exception('Erro ao consultar licenças: $error'); + } + + final bool isList = jsonBody is List; + final bool isMap = jsonBody is Map; + final dynamic license = isList + ? (jsonBody).map((data) => Module.fromJson(data as Map)).toList() + : isMap + ? [Module.fromJson(jsonBody)] + : []; + log('Modulos obtidos: $license'); + if (license is List && license.isNotEmpty && license != _modules) { + _modules = license; + log('Licença obtida com sucesso'); + log('$_modules'); + } else if (license is List && license.isEmpty) { + throw Exception('Nenhum módulo encontrado.'); + } + } catch (e, s) { + log('Erro ao obter licença', error: e, stackTrace: s); + } + } + + Future checkLicense() async { + log('Verificando licença...'); + await _fetchLicenses(); + } + + Future catchLicense() async { + await PhpGroup.getLicense(); + } +} From 32c0b960748d92f10593d3cea7b11082ecbea7eb Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 13 Nov 2024 13:37:34 -0300 Subject: [PATCH 02/75] WIP --- lib/shared/helpers/base_storage.dart | 51 +++++++ lib/shared/helpers/sqlite_storage.dart | 128 ++++++++++++++---- .../services/license/license_service.dart | 118 ++++++++++------ .../localization/localization_service.dart | 35 ++--- 4 files changed, 247 insertions(+), 85 deletions(-) diff --git a/lib/shared/helpers/base_storage.dart b/lib/shared/helpers/base_storage.dart index 11bc2509..9cc96289 100644 --- a/lib/shared/helpers/base_storage.dart +++ b/lib/shared/helpers/base_storage.dart @@ -141,3 +141,54 @@ extension SQLIteStorageKeyExtension on SQLiteStorageKey { } } } + +enum LicenseStorageKey { + messages, + liberations, + reservations, + access, + openedVisits, + vehicles, + residents, + pets, + orders, + completeSchedule, + providerSchedule, + deliverySchedule, + fastPass, +} + +extension LicenseKeyExtension on LicenseStorageKey { + String get value { + switch (this) { + case LicenseStorageKey.messages: + return 'FRE-HUB-MESSAGES'; + case LicenseStorageKey.liberations: + return 'FRE-HUB-LIBERATIONS'; + case LicenseStorageKey.reservations: + return 'FRE-HUB-RESERVATIONS'; + case LicenseStorageKey.access: + return 'FRE-HUB-ACCESS'; + case LicenseStorageKey.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case LicenseStorageKey.vehicles: + return 'FRE-HUB-VEHICLES'; + case LicenseStorageKey.residents: + return 'FRE-HUB-RESIDENTS'; + case LicenseStorageKey.pets: + return 'FRE-HUB-PETS'; + case LicenseStorageKey.orders: + return 'FRE-HUB-ORDERS'; + case LicenseStorageKey.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case LicenseStorageKey.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case LicenseStorageKey.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case LicenseStorageKey.fastPass: + return 'FRE-HUB-FASTPASS'; + default: + return ''; + } + } +} diff --git a/lib/shared/helpers/sqlite_storage.dart b/lib/shared/helpers/sqlite_storage.dart index 774a9afe..9c4fd052 100644 --- a/lib/shared/helpers/sqlite_storage.dart +++ b/lib/shared/helpers/sqlite_storage.dart @@ -1,3 +1,6 @@ +import 'dart:convert'; +import 'dart:developer'; + import 'package:hub/shared/helpers/base_storage.dart'; import 'package:sqflite/sqflite.dart'; import 'package:sqflite/sqlite_api.dart'; @@ -7,13 +10,15 @@ class SQLiteStorage implements BaseStorage { SQLiteStorage._(); static final String _dbName = 'database.db'; - static final int _dbVersion = 1; + static final int _dbVersion = 2; static const String tableKeychain = 'keychain'; + static const String tableLicense = 'license'; static final SQLiteStorage instance = SQLiteStorage._(); - late final _database; + static late final Database _database; + static Database get database => _database; @override Future init() async { @@ -21,20 +26,29 @@ class SQLiteStorage implements BaseStorage { join(await getDatabasesPath(), _dbName), version: _dbVersion, onCreate: _onCreate, - onUpgrade: _onUpdate, + onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - // await _onInitLocalVariables(_database); } _onCreate(Database database, int version) async { - await database.execute(_tableKeychain); + log('Creating database...'); + await database.execute(_keychain); + await database.execute(_license); + await initLicense(database); + } + + _onUpgrade(Database database, int oldVersion, int newVersion) async { + log('Upgrading database from version $oldVersion to $newVersion...'); + if (oldVersion < 2) { + await database.execute(_license); + await initLicense(database); + } } - _onUpdate(Database database, int oldVersion, int newVersion) async {} _onDowngrade(Database database, int oldVersion, int newVersion) async {} - String get _tableKeychain => ''' + String get _keychain => ''' CREATE TABLE keychain ( key TEXT UNIQUE, value TEXT, @@ -45,39 +59,76 @@ class SQLiteStorage implements BaseStorage { ); '''; - List> get _localVariables => [ - {'key': SQLiteStorageKey.devUUID.value, 'value': '', 'type': 'user'}, - {'key': SQLiteStorageKey.userUUID.value, 'value': '', 'type': 'user'}, - {'key': SQLiteStorageKey.userDevUUID.value, 'value': '', 'type': 'user'}, - {'key': SQLiteStorageKey.status.value, 'value': '', 'type': 'user'}, - {'key': SQLiteStorageKey.userName.value, 'value': '', 'type': 'user'}, - {'key': SQLiteStorageKey.clientUUID.value, 'value': '', 'type': 'local'}, - {'key': SQLiteStorageKey.ownerUUID.value, 'value': '', 'type': 'local'}, - {'key': SQLiteStorageKey.clientName.value, 'value': '', 'type': 'local'}, - {'key': SQLiteStorageKey.whatsapp.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.provisional.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.pets.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.local.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.notify.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.fingerprint.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.access.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.panic.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.person.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.requestOSNotification.value, 'value': 'false', 'type': 'util'}, - {'key': SQLiteStorageKey.petAmount.value, 'value': '', 'type': 'local'}, - ]; + String get _license => ''' + CREATE TABLE license ( + key TEXT UNIQUE, + display TEXT, + expirationDate TEXT, + startDate TEXT, + quantity TEXT + ); + '''; + + static Future initLicense(Database database) async { + log('initLicense()'); + for (var element in LicenseStorageKey.values.map((e) => e.value)) { + await database.insert( + tableLicense, + { + 'key': element, + 'display': 'VISIVEL', + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }, + conflictAlgorithm: ConflictAlgorithm.ignore, + ); + } + } @override Future get(String key) async { - var response = await _database.query('keychain', where: 'key = ?', whereArgs: [key]); + if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { + return await _getLicense(key); + } else { + return await _getKeychain(key); + } + } + + Future _getKeychain(String key) async { + var response = await _database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; } - return response.first['value']; + return response.first['value'].toString(); + } + + Future _getLicense(String key) async { + var response = await _database.query(tableLicense, where: 'key = ?', whereArgs: [key]); + if (response.isEmpty) { + return null; + } + return response.first['value'].toString(); + } + + Future getAll(String table) async { + var response = await _database.query(table); + if (response.isEmpty) { + return null; + } + return jsonEncode(response); } @override Future set(String key, String value) async { + if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { + return await _setLicense(key, value); + } else { + return await _setKeychain(key, value); + } + } + + Future _setKeychain(String key, String value) async { var date = DateTime.now().toIso8601String(); await _database.insert( tableKeychain, @@ -92,6 +143,23 @@ class SQLiteStorage implements BaseStorage { conflictAlgorithm: ConflictAlgorithm.replace); } + Future _setLicense(String key, String value) async { + log('setLicense($key, $value)'); + Map valueMap = jsonDecode(value); + log('String to Map: $value to $valueMap'); + + await _database.insert( + tableLicense, + { + 'key': key, + 'display': valueMap['display'], + 'expirationDate': valueMap['expirationDate'], + 'startDate': valueMap['startDate'], + 'quantity': valueMap['quantity'], + }, + conflictAlgorithm: ConflictAlgorithm.replace); + } + @override Future delete(String key) async { await _database.delete('keychain', where: 'key = ?', whereArgs: [key]); diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 51f234c4..4b562a09 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -3,72 +3,112 @@ import 'dart:developer'; import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/sqlite_storage.dart'; import 'dart:convert'; +import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:sqflite/sqflite.dart'; + class LicenseService { static final LicenseService _instance = LicenseService._internal(); factory LicenseService() => _instance; LicenseService._internal(); - List _modules = []; - - List get modules => List.unmodifiable(_modules); - - Future initLicenseService() async { - await _fetchLicenses(); + static Future initLicenseService() async { + // for (var element in LicenseStorageKey.values.map((e) => e.value)) { + // await SQLiteStorage.database.insert( + // SQLiteStorage.tableLicense, + // { + // 'key': element, + // 'display': 'VISIVEL', + // 'expirationDate': '', + // 'startDate': '', + // 'quantity': '', + // }, + // conflictAlgorithm: ConflictAlgorithm.ignore, + // ); + // } } - Future _fetchLicenses() async { + static Future processLicense() async {} + + static Future fetchLicenses() async { try { log('Obtendo licenças...'); final ApiCallResponse response = await PhpGroup.testCall(); - final String responseBody = response.jsonBody.toString(); + final List responseBody = response.jsonBody; - if (responseBody.isEmpty) { - throw Exception('Licensa ausente ou vazia.'); + if (responseBody == []) { + // throw Exception('Licensa ausente ou vazia.'); } - // if (responseBody == "[]") { - // log('Nenhuma licença encontrada.'); - // _modules = []; - // log('() MOD => $_modules'); - // return; - // } - - final dynamic jsonBody = jsonDecode(responseBody); - - if (jsonBody is Map && jsonBody['error'] == true) { - final String error = jsonBody['error_msg'] ?? 'Erro desconhecido'; + if (response.jsonBody is! List && response.jsonBody['error'] != null) { + final String error = response.jsonBody['error_msg'] ?? 'Erro desconhecido'; throw Exception('Erro ao consultar licenças: $error'); } - final bool isList = jsonBody is List; - final bool isMap = jsonBody is Map; - final dynamic license = isList - ? (jsonBody).map((data) => Module.fromJson(data as Map)).toList() - : isMap - ? [Module.fromJson(jsonBody)] - : []; - log('Modulos obtidos: $license'); - if (license is List && license.isNotEmpty && license != _modules) { - _modules = license; - log('Licença obtida com sucesso'); - log('$_modules'); - } else if (license is List && license.isEmpty) { - throw Exception('Nenhum módulo encontrado.'); + for (var element in responseBody) { + switch (element['key']) { + case 'FRE-HUB-MESSAGES': + _saveModule(element); + break; + case 'FRE-HUB-LIBERATIONS': + _saveModule(element); + break; + case 'FRE-HUB-RESERVATIONS': + _saveModule(element); + break; + case 'FRE-HUB-ACCESS': + _saveModule(element); + break; + case 'FRE-HUB-OPENED-VISITS': + _saveModule(element); + break; + case 'FRE-HUB-VEHICLES': + _saveModule(element); + break; + case 'FRE-HUB-RESIDENTS': + _saveModule(element); + break; + case 'FRE-HUB-PETS': + _saveModule(element); + break; + case 'FRE-HUB-FASTPASS': + _saveModule(element); + break; + case 'FRE-HUB-ORDERS': + _saveModule(element); + break; + case 'FRE-HUB-COMPLETE-SCHEDULE': + _saveModule(element); + break; + case 'FRE-HUB-AGE-PROV-DELIVERY': + _saveModule(element); + break; + case 'FRE-HUB-AGE-PROV-PRESTADOR': + _saveModule(element); + break; + case 'FRE-WHATSAPP': + _saveModule(element); + break; + } } } catch (e, s) { log('Erro ao obter licença', error: e, stackTrace: s); } } - Future checkLicense() async { - log('Verificando licença...'); - await _fetchLicenses(); + static Future _saveModule(final dynamic body) async { + if (body is Map) log('Salvando módulo: ${body.toString()}'); + // if (body is Map) await StorageHelper().set(body['key'], '', Storage.SQLiteStorage); + if (body is Map) await StorageHelper().set(body['key'], jsonEncode(body), Storage.SQLiteStorage); } - Future catchLicense() async { + static Future updateLicense(final dynamic body) async {} + + static Future catchLicense() async { await PhpGroup.getLicense(); } } diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index e1319084..673c318f 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -8,6 +8,7 @@ import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/base_storage.dart'; import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/services/license/license_service.dart'; import 'package:hub/shared/utils/device_util.dart'; import 'package:hub/shared/utils/dialog_util.dart'; @@ -162,6 +163,8 @@ class LocalizationService { ); await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); return false; + } finally { + await LicenseService.fetchLicenses(); } } @@ -293,6 +296,22 @@ class LocalizationService { } } + static Future _updateStorageUtil(Map jsonBody) async { + await StorageHelper().set(SQLiteStorageKey.whatsapp.value, + jsonBody['whatsapp'] != null && jsonBody['whatsapp'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper().set(SQLiteStorageKey.provisional.value, + jsonBody['provisional'] != null && jsonBody['provisional'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper().set(SQLiteStorageKey.pets.value, + jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper().set( + SQLiteStorageKey.petAmount.value, + jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty + ? '0' + : jsonBody['petAmountRegister'].toString(), + Storage.SQLiteStorage); + await StorageHelper().set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage); + } + static bool _isActive(List locals) { return locals.where((local) => local['CLU_STATUS'] == 'A').isNotEmpty; } @@ -324,20 +343,4 @@ class LocalizationService { String cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty; } - - static Future _updateStorageUtil(Map jsonBody) async { - await StorageHelper().set(SQLiteStorageKey.whatsapp.value, - jsonBody['whatsapp'] != null && jsonBody['whatsapp'] ? 'true' : 'false', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.provisional.value, - jsonBody['provisional'] != null && jsonBody['provisional'] ? 'true' : 'false', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.pets.value, - jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false', Storage.SQLiteStorage); - await StorageHelper().set( - SQLiteStorageKey.petAmount.value, - jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty - ? '0' - : jsonBody['petAmountRegister'].toString(), - Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage); - } } From 6c72e17515f5e813e516d299fe24dc767f170569 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 13 Nov 2024 14:18:40 -0300 Subject: [PATCH 03/75] WIP --- lib/shared/helpers/sqlite_storage.dart | 20 ++++++++++++----- .../services/license/license_service.dart | 22 ++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/shared/helpers/sqlite_storage.dart b/lib/shared/helpers/sqlite_storage.dart index 9c4fd052..7f3261fa 100644 --- a/lib/shared/helpers/sqlite_storage.dart +++ b/lib/shared/helpers/sqlite_storage.dart @@ -33,16 +33,24 @@ class SQLiteStorage implements BaseStorage { _onCreate(Database database, int version) async { log('Creating database...'); - await database.execute(_keychain); - await database.execute(_license); - await initLicense(database); + try { + await database.execute(_keychain); + await database.execute(_license); + await setupLicense(); + } catch (e) { + log('Tables keychain and license already exists'); + } } _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2) { - await database.execute(_license); - await initLicense(database); + try { + await database.execute(_license); + await setupLicense(); + } catch (e) { + log('Table license already exists'); + } } } @@ -69,7 +77,7 @@ class SQLiteStorage implements BaseStorage { ); '''; - static Future initLicense(Database database) async { + static Future setupLicense() async { log('initLicense()'); for (var element in LicenseStorageKey.values.map((e) => e.value)) { await database.insert( diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 4b562a09..01bb6f9f 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -8,7 +8,6 @@ import 'package:hub/shared/helpers/sqlite_storage.dart'; import 'dart:convert'; import 'package:hub/shared/helpers/storage_helper.dart'; -import 'package:sqflite/sqflite.dart'; class LicenseService { static final LicenseService _instance = LicenseService._internal(); @@ -37,16 +36,22 @@ class LicenseService { static Future fetchLicenses() async { try { log('Obtendo licenças...'); - final ApiCallResponse response = await PhpGroup.testCall(); - final List responseBody = response.jsonBody; + final ApiCallResponse response = await PhpGroup.getLicense(); + final dynamic responseBody = response.jsonBody; + log('Licenças obtidas: $responseBody'); - if (responseBody == []) { - // throw Exception('Licensa ausente ou vazia.'); + if (response.jsonBody is! List) { + late final String error; + if (response.jsonBody is Map) + error = response.jsonBody['error_msg']; + else + error = 'Erro desconhecido'; + + throw Exception('Erro ao consultar licenças: $error'); } - if (response.jsonBody is! List && response.jsonBody['error'] != null) { - final String error = response.jsonBody['error_msg'] ?? 'Erro desconhecido'; - throw Exception('Erro ao consultar licenças: $error'); + if (responseBody == []) { + await SQLiteStorage.setupLicense(); } for (var element in responseBody) { @@ -97,6 +102,7 @@ class LicenseService { } } catch (e, s) { log('Erro ao obter licença', error: e, stackTrace: s); + await SQLiteStorage.setupLicense(); } } From 7a2ea2b2b42e439e0f34a9d594688c5c508afe58 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 14 Nov 2024 09:00:27 -0300 Subject: [PATCH 04/75] WIP --- integration_test/app_test.dart | 12 +- lib/backend/api_requests/api_calls.dart | 203 +++++++++--------- .../firebase_messaging_service.dart | 2 +- .../notifications/notification_service.dart | 8 +- ..._arrow_linked_locals_component_widget.dart | 16 +- .../local_profile_component_model.dart | 4 +- .../local_profile_component_widget.dart | 2 +- .../menu_component/menu_component_model.dart | 14 +- .../schedule_visit_detail_model.dart | 6 +- ...p_arrow_linked_locals_component_model.dart | 8 +- ...cation_modal_template_component_model.dart | 6 +- .../change_pass_widget.dart | 2 +- ...item_details_template_component_model.dart | 6 +- .../provisional_schedule_template_model.dart | 10 +- ...siter_vistor_template_component_model.dart | 6 +- .../sign_up_template_component_widget.dart | 2 +- .../view_visit_detail_model.dart | 6 +- ...search_modal_template_component_model.dart | 6 +- lib/flutter_flow/nav/nav.dart | 14 +- lib/main.dart | 10 +- .../acess_history_page_model.dart | 6 +- .../fast_pass_page/fast_pass_page_widget.dart | 10 +- lib/pages/home_page/home_page_model.dart | 10 +- .../liberation_history_model.dart | 6 +- .../message_history_page_model.dart | 6 +- .../package_order_page.dart | 2 +- lib/pages/pets_page/pets_history_screen.dart | 8 +- lib/pages/pets_page/pets_page_model.dart | 8 +- .../preferences_settings_model.dart | 42 ++-- .../qr_code_page/qr_code_page_model.dart | 4 +- .../qr_code_page/qr_code_page_widget.dart | 2 +- .../reception_page/reception_page_model.dart | 3 +- .../reception_page/reception_page_widget.dart | 2 +- .../reservation_page_widget.dart | 11 +- .../schedule_complete_visit_page_model.dart | 6 +- .../visit_history_page_widget.dart | 14 +- .../welcome_page/welcome_page_widget.dart | 6 +- lib/shared/helpers/base_storage.dart | 8 +- lib/shared/helpers/database_storage.dart | 44 ++++ lib/shared/helpers/sqlite_storage.dart | 180 ---------------- lib/shared/helpers/storage_helper.dart | 135 +++++++++--- .../authentication_service.dart | 28 +-- .../services/license/license_service.dart | 146 ++++++++----- .../localization/localization_service.dart | 74 +++---- .../services/sqlite/sqlite_service.dart | 64 ++++++ lib/shared/utils/share_util.dart | 4 +- 46 files changed, 589 insertions(+), 583 deletions(-) create mode 100644 lib/shared/helpers/database_storage.dart delete mode 100644 lib/shared/helpers/sqlite_storage.dart create mode 100644 lib/shared/services/sqlite/sqlite_service.dart diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index f8ab2568..8706e9a0 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -14,8 +14,8 @@ void main() { group('Initialization', () { group('Navigation', () { - setUpAll(() async => await initializeApp().then( - (_) async => await StorageHelper().set(SecureStorageKey.isLogged.value, 'false', Storage.SecureStorage))); + setUpAll(() async => + await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); testWidgets('Test Welcome', (WidgetTester tester) async { widget = tester; await _testWelcome(); @@ -26,16 +26,16 @@ void main() { }); group('Authentication', () { group('Sign in', () { - setUpAll(() async => await initializeApp().then( - (_) async => await StorageHelper().set(SecureStorageKey.isLogged.value, 'false', Storage.SecureStorage))); + setUpAll(() async => + await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); testWidgets('Test Sign In', (WidgetTester tester) async { widget = tester; await _testSignIn(); }); }); group('Sign up', () { - setUpAll(() async => await initializeApp().then( - (_) async => await StorageHelper().set(SecureStorageKey.isLogged.value, 'false', Storage.SecureStorage))); + setUpAll(() async => + await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); testWidgets('Test Sign Up', (WidgetTester tester) async { widget = tester; await _testSignUp(); diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 9d4484f8..bc0c68d4 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -92,9 +92,9 @@ class TestCall { class GetLicense { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getLicense', @@ -120,12 +120,11 @@ class GetLicense { } } - class UnregisterDevice { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -152,9 +151,9 @@ class UnregisterDevice { class DeletePet { Future call({final int? petID = 0}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'excluirPet'; return ApiManager.instance.makeApiCall( @@ -197,9 +196,9 @@ class UpdatePet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'atualizarPet'; return ApiManager.instance.makeApiCall( @@ -243,9 +242,9 @@ class GetPets { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaPets'; return ApiManager.instance.makeApiCall( @@ -277,9 +276,9 @@ class GetPetPhoto { Future call({final int? petId}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaFotoPet'; return ApiManager.instance.makeApiCall( @@ -320,9 +319,9 @@ class RegisterPet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cadastrarPet'; return ApiManager.instance.makeApiCall( @@ -365,9 +364,9 @@ class BuscaEnconcomendas { final String? adresseeType, final String? status, }) async { - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getEncomendas'; final String baseUrl = PhpGroup.getBaseUrl(); @@ -409,9 +408,9 @@ class CancelaVisita { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -443,8 +442,8 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; final String baseUrl = PhpGroup.getBaseUrl(); return ApiManager.instance.makeApiCall( @@ -475,9 +474,9 @@ class ChangePanic { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -511,9 +510,9 @@ class ChangePass { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -547,9 +546,9 @@ class RespondeVinculo { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -581,9 +580,9 @@ class ChangeNotifica { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -615,10 +614,10 @@ class UpdateIDE { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - final String newIde = (await StorageHelper().get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String newIde = (await StorageHelper().g(SQLiteStorageKey.userDevUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -650,9 +649,9 @@ class UpdToken { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String token = (await StorageHelper().get(SecureStorageKey.token.value, Storage.SecureStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String token = (await StorageHelper().g(SecureStorageKey.token.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'updToken', @@ -679,12 +678,11 @@ class UpdToken { class LoginCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String email = (await StorageHelper().get(SecureStorageKey.email.value, Storage.SecureStorage)) ?? ''; - final String password = (await StorageHelper().get(SecureStorageKey.password.value, Storage.SecureStorage)) ?? ''; - final String type = (await StorageHelper().get(SecureStorageKey.deviceType.value, Storage.SecureStorage)) ?? ''; - final String description = - (await StorageHelper().get(SecureStorageKey.deviceDescription.value, Storage.SecureStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String email = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; + final String password = (await StorageHelper().g(SecureStorageKey.password.value)) ?? ''; + final String type = (await StorageHelper().g(SecureStorageKey.deviceType.value)) ?? ''; + final String description = (await StorageHelper().g(SecureStorageKey.deviceDescription.value)) ?? ''; late final String token; try { token = await FirebaseMessagingService.getToken(); @@ -767,9 +765,9 @@ class ChangePasswordCall { required final String psswd, }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'changePassword', @@ -828,8 +826,8 @@ class GetLocalsCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage) ?? ''; - final String userUUID = await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage) ?? ''; + final String devUUID = await StorageHelper().g(SQLiteStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().g(SQLiteStorageKey.userUUID.value) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -868,9 +866,9 @@ class PostScheduleVisitorCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisitante'; return ApiManager.instance.makeApiCall( @@ -923,9 +921,9 @@ class PostScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisita'; return ApiManager.instance.makeApiCall( @@ -977,9 +975,9 @@ class GetScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1251,9 +1249,9 @@ class GetDadosCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getDados'; return ApiManager.instance.makeApiCall( @@ -1484,9 +1482,9 @@ class GetVisitorByDocCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitante'; return ApiManager.instance.makeApiCall( @@ -1538,9 +1536,9 @@ class GetFotoVisitanteCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getFotoVisitante'; return ApiManager.instance.makeApiCall( @@ -1577,9 +1575,9 @@ class PostProvVisitSchedulingCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putAgendamentoProv'; return ApiManager.instance.makeApiCall( @@ -1626,9 +1624,9 @@ class GetVisitsCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1889,9 +1887,9 @@ class DeleteVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -1932,10 +1930,10 @@ class GetPessoasLocalCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String ownerUUID = (await StorageHelper().get(SQLiteStorageKey.ownerUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String ownerUUID = (await StorageHelper().g(SQLiteStorageKey.ownerUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -1998,9 +1996,9 @@ class RespondeSolicitacaoCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'respondeSolicitacao'; return ApiManager.instance.makeApiCall( @@ -2048,9 +2046,9 @@ class GetAccessCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getAcessos'; return ApiManager.instance.makeApiCall( @@ -2297,10 +2295,9 @@ class GetLiberationsCall { final StreamController controller = StreamController(); Future.microtask(() async { - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = - (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getSolicitacoes'; try { @@ -2490,9 +2487,9 @@ class GetMessagesCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getMensagens'; return ApiManager.instance.makeApiCall( diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index 1fa9864e..7dc5fd4f 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -43,7 +43,7 @@ class FirebaseMessagingService { final String? deviceToken = await _firebaseMessaging.getToken(); if (deviceToken != null) { - await StorageHelper().set(SecureStorageKey.token.value, deviceToken, Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.token.value, 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 b15eb326..f97f7a63 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -15,7 +15,7 @@ import 'package:hub/shared/utils/dialog_util.dart'; Future onMessageReceived(Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; answersRequest( {required BuildContext context, @@ -239,7 +239,7 @@ Future onMessageReceived(Map payload, String? extra, Stri break; case 'enroll_cond': - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); StorageHelper().context!.go('/homePage'); break; default: @@ -271,11 +271,11 @@ class NotificationService { await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async { final bool requestOSnotification = - (await StorageHelper().get(SQLiteStorageKey.requestOSNotification.value, Storage.SQLiteStorage)) == 'true'; + (await StorageHelper().g(SQLiteStorageKey.requestOSNotification.value)) == 'true'; if (requestOSnotification == false) { if (isAllowed == false) { - await StorageHelper().set(SQLiteStorageKey.requestOSNotification.value, 'true', Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.requestOSNotification.value, 'true'); await AwesomeNotifications().requestPermissionToSendNotifications(); } } 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 e5ebe5e3..b9a930ed 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 @@ -105,9 +105,9 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State _fetchResponseLink(String status, String cliID) async { try { - await StorageHelper().set(SQLiteStorageKey.clientUUID.value, cliID, Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.clientUUID.value, cliID); var response = await PhpGroup.resopndeVinculo.call(tarefa: status); if (response.jsonBody['error'] == false) { @@ -147,7 +147,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State getData() async { - cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; 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 2ea21dd2..2b47bcc0 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 @@ -97,7 +97,7 @@ class _LocalProfileComponentWidgetState extends State onUpdate()); }, child: ClipRRect( 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 106dbf6c..7b1579f8 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -60,8 +60,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openDeliverySchedule(BuildContext context) async { - final bool isProvisional = - await StorageHelper().get(SQLiteStorageKey.provisional.value, Storage.SQLiteStorage) == 'true'; + final bool isProvisional = await StorageHelper().g(SQLiteStorageKey.provisional.value) == 'true'; if (isProvisional == true) { context.push( '/deliverySchedule', @@ -79,8 +78,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openProvisionalSchedule(BuildContext context) async { - final isProvisional = - await StorageHelper().get(SQLiteStorageKey.provisional.value, Storage.SQLiteStorage) == 'true'; + final isProvisional = await StorageHelper().g(SQLiteStorageKey.provisional.value) == 'true'; if (isProvisional == true) { context.push( '/provisionalSchedule', @@ -98,7 +96,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openFastPassSchedule(BuildContext context) async { - final isWpp = await StorageHelper().get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true'; + final isWpp = await StorageHelper().g(SQLiteStorageKey.whatsapp.value) == 'true'; if (isWpp) { context.push( '/fastPassPage', @@ -207,7 +205,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openMyOrders(BuildContext context) async { - final isWpp = await StorageHelper().get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true'; + final isWpp = await StorageHelper().g(SQLiteStorageKey.whatsapp.value) == 'true'; ; if (isWpp) { context.push( @@ -226,7 +224,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openReservations(BuildContext context) async { - final isWpp = await StorageHelper().get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true'; + final isWpp = await StorageHelper().g(SQLiteStorageKey.whatsapp.value) == 'true'; ; if (isWpp) { context.push( @@ -343,7 +341,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openPetsRegister(BuildContext context) async { - bool isPet = await StorageHelper().get(SQLiteStorageKey.pets.value, Storage.SQLiteStorage) == 'true'; + bool isPet = await StorageHelper().g(SQLiteStorageKey.pets.value) == 'true'; ; if (isPet) { context.push( 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 f65158fa..81050e87 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 @@ -56,9 +56,9 @@ class ScheduleVisitDetailModel extends FlutterFlowModel initDB() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart index b1733956..c808f15d 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 @@ -16,10 +16,10 @@ class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel initDB() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; } @override diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart index 1de0af97..b076651b 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 @@ -32,9 +32,9 @@ class AccessNotificationModalTemplateComponentModel } Future initDB() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart index 90395b06..bb0d3126 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 @@ -49,7 +49,7 @@ class _PassKeyTemplateWidgetState extends State { } Future _initialize() async { - _accessPass = await StorageHelper().get(SecureStorageKey.accessPass.value, Storage.SecureStorage) ?? ''; + _accessPass = await StorageHelper().g(SecureStorageKey.accessPass.value) ?? ''; } @override 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 26e45baa..9bf42aee 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 @@ -27,9 +27,9 @@ class LiberationHistoryItemDetailsTemplateComponentModel void initState(BuildContext context) {} Future initDatabase() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; ; } 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 7c86e00d..41a8c60e 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 @@ -138,12 +138,12 @@ class ScheduleProvisionalVisitPageModel extends FlutterFlowModel init() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; ; - cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; - ownerUUID = (await StorageHelper().get(SQLiteStorageKey.ownerUUID.value, Storage.SQLiteStorage)) ?? ''; + cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + ownerUUID = (await StorageHelper().g(SQLiteStorageKey.ownerUUID.value)) ?? ''; setState?.call(); } } 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 44b53bb8..0aaecec6 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 @@ -129,9 +129,9 @@ class RegisiterVistorTemplateComponentModel extends FlutterFlowModel initializeDatabase() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; ; } 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 61787f05..332234e6 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 @@ -91,7 +91,7 @@ class _SignUpTemplateComponentWidgetState extends State _initialize() async { - _deviceType = (await StorageHelper().get(SecureStorageKey.deviceType.value, Storage.SecureStorage)) ?? ''; + _deviceType = (await StorageHelper().g(SecureStorageKey.deviceType.value)) ?? ''; } @override 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 5113e702..ae428c74 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 @@ -37,9 +37,9 @@ class ViewVisitDetailModel extends FlutterFlowModel { } Future initializeDatabase() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; ; } 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 eb9d3806..4c9ef4c0 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 @@ -35,9 +35,9 @@ class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel initDatabase() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; ; } diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index f891b962..fe46ac17 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -80,16 +80,10 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { builder: (context, _) { return FutureBuilder( future: () async { - final bool isLogged = - await StorageHelper().get(SecureStorageKey.isLogged.value, Storage.SecureStorage) == 'true'; - final bool haveLocal = - await StorageHelper().get(SecureStorageKey.haveLocal.value, Storage.SecureStorage) == 'true'; - final bool haveUserUUID = - (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? - false; - final bool haveDevUUID = - (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? - false; + final bool isLogged = await StorageHelper().g(SecureStorageKey.isLogged.value) == 'true'; + final bool haveLocal = await StorageHelper().g(SecureStorageKey.haveLocal.value) == 'true'; + final bool haveUserUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value))?.isNotEmpty ?? false; + final bool haveDevUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value))?.isNotEmpty ?? false; if (isLogged && haveDevUUID && haveUserUUID) { return haveLocal ? const HomePageWidget() : const ReceptionPageWidget(); diff --git a/lib/main.dart b/lib/main.dart index 7fcd9d7b..b864eb60 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -83,7 +83,7 @@ Future _initializeFlutterFlow() async { Future _foregroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); StorageHelper().context?.go('/homePage'); } @@ -97,7 +97,7 @@ Future _foregroundHandlerMessage(RemoteMessage message) async { Future _backgroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); StorageHelper().context?.go('/homePage'); } } @@ -226,7 +226,7 @@ class _AppState extends State with WidgetsBindingObserver { FirebaseMessaging.onMessage.listen(_foregroundHandlerMessage); FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); log('onMessageOpenedApp'); } else { onMessageReceived(message.data, message.notification!.body, message.data['click_action']); @@ -235,7 +235,7 @@ class _AppState extends State with WidgetsBindingObserver { FirebaseMessaging.instance.getInitialMessage().then((message) async { if (message != null) { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); log('getInitialMessage'); } } @@ -281,7 +281,7 @@ class _AppState extends State with WidgetsBindingObserver { if (state == AppLifecycleState.detached) { await LocalizationService.processLocals(context); FirebaseMessagingService().updateDeviceToken(); - } + } } @override diff --git a/lib/pages/acess_history_page/acess_history_page_model.dart b/lib/pages/acess_history_page/acess_history_page_model.dart index e42c0cf5..eb2fc0c1 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -33,9 +33,9 @@ class AcessHistoryPageModel extends FlutterFlowModel { } Future initDatabase() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/fast_pass_page/fast_pass_page_widget.dart b/lib/pages/fast_pass_page/fast_pass_page_widget.dart index c713c0a8..fc06c01c 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -23,11 +23,11 @@ class _FastPassPageWidgetState extends State { late InAppWebViewController _controllerIOS; Future> initVariables() async { - final email = (await StorageHelper().get(hub.SecureStorageKey.email.value, hub.Storage.SecureStorage)) ?? ''; - final name = (await StorageHelper().get(hub.SQLiteStorageKey.userName.value, hub.Storage.SQLiteStorage)) ?? ''; - final devUUID = (await StorageHelper().get(hub.SQLiteStorageKey.devUUID.value, hub.Storage.SQLiteStorage)) ?? ''; - final userUUID = (await StorageHelper().get(hub.SQLiteStorageKey.userUUID.value, hub.Storage.SQLiteStorage)) ?? ''; - final cliUUID = (await StorageHelper().get(hub.SQLiteStorageKey.clientUUID.value, hub.Storage.SQLiteStorage)) ?? ''; + final email = (await StorageHelper().g(hub.SecureStorageKey.email.value)) ?? ''; + final name = (await StorageHelper().g(hub.SQLiteStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().g(hub.SQLiteStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(hub.SQLiteStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(hub.SQLiteStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; final freUserData = diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index dad2a7fe..bfa6dafa 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -24,11 +24,11 @@ class HomePageModel extends FlutterFlowModel { late MessageWellComponentModel messageWellComponentModel; Future _initVariable() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - userName = (await StorageHelper().get(SQLiteStorageKey.userName.value, Storage.SQLiteStorage)) ?? ''; - userEmail = (await StorageHelper().get(SecureStorageKey.email.value, Storage.SecureStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + userName = (await StorageHelper().g(SQLiteStorageKey.userName.value)) ?? ''; + userEmail = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; } @override diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index d0ff3638..a6296804 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -36,9 +36,9 @@ class LiberationHistoryModel extends FlutterFlowModel { } Future init() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } Future answersRequest( diff --git a/lib/pages/message_history_page/message_history_page_model.dart b/lib/pages/message_history_page/message_history_page_model.dart index e8fdacbc..bb6852d0 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -39,9 +39,9 @@ class MessageHistoryPageModel extends FlutterFlowModel } Future init() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index d480b952..b7412d3f 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -64,7 +64,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index 917a041d..74249fb2 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -229,10 +229,10 @@ class _PetsHistoryScreenState extends State with TickerProvid } ], onTapCardItemAction: () async { - final devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - final cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + final devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; 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 d0e5b3f5..94bf39b9 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -144,10 +144,10 @@ class PetsPageModel extends FlutterFlowModel { textControllerObservation = TextEditingController(); WidgetsBinding.instance.addPostFrameCallback((_) async { - devUUID = await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage) ?? ''; - userUUID = await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage) ?? ''; - cliUUID = await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage) ?? ''; - petAmountRegister = await StorageHelper().get(SQLiteStorageKey.petAmount.value, Storage.SQLiteStorage) ?? ''; + devUUID = await StorageHelper().g(SQLiteStorageKey.devUUID.value) ?? ''; + userUUID = await StorageHelper().g(SQLiteStorageKey.userUUID.value) ?? ''; + cliUUID = await StorageHelper().g(SQLiteStorageKey.clientUUID.value) ?? ''; + petAmountRegister = await StorageHelper().g(SQLiteStorageKey.petAmount.value) ?? ''; }); } diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 2b57ed67..af8623bf 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -23,11 +23,11 @@ class PreferencesPageModel with ChangeNotifier { late bool isPanic = false; Future _initialize() async { - isFingerprint = await StorageHelper().get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; - isPerson = await StorageHelper().get(SQLiteStorageKey.person.value, Storage.SQLiteStorage) == 'true'; - isNotify = await StorageHelper().get(SQLiteStorageKey.notify.value, Storage.SQLiteStorage) == 'true'; - isAccess = await StorageHelper().get(SQLiteStorageKey.access.value, Storage.SQLiteStorage) == 'true'; - isPanic = await StorageHelper().get(SQLiteStorageKey.panic.value, Storage.SQLiteStorage) == 'true'; + isFingerprint = await StorageHelper().g(SQLiteStorageKey.fingerprint.value) == 'true'; + isPerson = await StorageHelper().g(SQLiteStorageKey.person.value) == 'true'; + isNotify = await StorageHelper().g(SQLiteStorageKey.notify.value) == 'true'; + isAccess = await StorageHelper().g(SQLiteStorageKey.access.value) == 'true'; + isPanic = await StorageHelper().g(SQLiteStorageKey.panic.value) == 'true'; notifyListeners(); } @@ -36,8 +36,7 @@ class PreferencesPageModel with ChangeNotifier { } Future enablePerson(BuildContext context) async { - final String userDevUUID = - (await StorageHelper().get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userDevUUID = (await StorageHelper().g(SQLiteStorageKey.userDevUUID.value)) ?? ''; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( @@ -64,8 +63,7 @@ class PreferencesPageModel with ChangeNotifier { .call(notifica: value) .then((value) async { if (value.jsonBody['error'] == false) { - await StorageHelper() - .set(SQLiteStorageKey.notify.value, isNotify ? 'false' : 'true', Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.notify.value, isNotify ? 'false' : 'true'); content = FFLocalizations.of(context).getVariableText( enText: 'Notification changed successfully', ptText: 'Notificação alterada com sucesso', @@ -88,8 +86,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => - isNotify = await StorageHelper().get(SQLiteStorageKey.notify.value, Storage.SQLiteStorage) == 'true') + .then((_) async => isNotify = await StorageHelper().g(SQLiteStorageKey.notify.value) == 'true') .whenComplete(() => notifyListeners()); context.pop(); } @@ -138,14 +135,13 @@ class PreferencesPageModel with ChangeNotifier { Future toggleAccess(BuildContext context) async { onChange(String key) async { - await StorageHelper().set(SecureStorageKey.accessPass.value, key, Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.accessPass.value, key); await PhpGroup.changePass .call(newSenha: key) .then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - await StorageHelper() - .set(SQLiteStorageKey.access.value, isAccess ? 'false' : 'true', Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.access.value, isAccess ? 'false' : 'true'); notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Access pass changed successfully', @@ -167,8 +163,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => - isAccess = await StorageHelper().get(SQLiteStorageKey.access.value, Storage.SQLiteStorage) == 'true') + .then((_) async => isAccess = await StorageHelper().g(SQLiteStorageKey.access.value) == 'true') .whenComplete(() => notifyListeners()); } @@ -177,14 +172,13 @@ class PreferencesPageModel with ChangeNotifier { Future togglePanic(BuildContext context) async { onChange(String key) async { - await StorageHelper().set(SecureStorageKey.panicPass.value, key, Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.panicPass.value, key); await PhpGroup.changePanic .call(newSenhaPanico: key) .then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - await StorageHelper() - .set(SQLiteStorageKey.panic.value, isPanic ? 'false' : 'true', Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.panic.value, isPanic ? 'false' : 'true'); notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Panic password changed successfully', @@ -206,8 +200,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => - isPanic = await StorageHelper().get(SQLiteStorageKey.panic.value, Storage.SQLiteStorage) == 'true') + .then((_) async => isPanic = await StorageHelper().g(SQLiteStorageKey.panic.value) == 'true') .whenComplete(() => notifyListeners()); } @@ -222,12 +215,11 @@ class PreferencesPageModel with ChangeNotifier { onChange(String? key) async { isFingerprint = !isFingerprint; - await StorageHelper().set(SecureStorageKey.fingerprintPass.value, key ?? '', Storage.SecureStorage); - await StorageHelper() - .set(SQLiteStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false', Storage.SQLiteStorage); + await StorageHelper().s(SecureStorageKey.fingerprintPass.value, key ?? ''); + await StorageHelper().s(SQLiteStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false'); notifyListeners(); SnackBarUtil.showSnackBar(context, content); - isFingerprint = await StorageHelper().get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; + isFingerprint = await StorageHelper().g(SQLiteStorageKey.fingerprint.value) == 'true'; } isFingerprint ? onChange(null) : _showPassKey(context, onChange); 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 514f99b2..c2786b7b 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -29,8 +29,8 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = await StorageHelper().get(SQLiteStorageKey.fingerprint.value, Storage.SQLiteStorage) == 'true'; - userDevUUID = await StorageHelper().get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage) ?? ''; + isFingerprint = await StorageHelper().g(SQLiteStorageKey.fingerprint.value) == 'true'; + userDevUUID = await StorageHelper().g(SQLiteStorageKey.userDevUUID.value) ?? ''; safeSetState?.call(); } diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index 43d904df..23c8e894 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -353,7 +353,7 @@ class _QrCodePageWidgetState extends State with TickerProvider await BiometricHelper.checkBiometrics() .then((value) async => await BiometricHelper.authenticateBiometric().then((value) async { if (value == false) throw Exception('Biometric authentication failed'); - final key = await StorageHelper().get(SecureStorageKey.fingerprintPass.value, Storage.SecureStorage); + final key = await StorageHelper().g(SecureStorageKey.fingerprintPass.value); if (key == null || key.isEmpty) throw Exception('No key found'); safeSetState(() { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index ad6c4b2e..e406e8c1 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -6,8 +6,7 @@ import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final String userDevUUID = - (await StorageHelper().get(SQLiteStorageKey.userDevUUID.value, Storage.SQLiteStorage)) ?? ''; + final String userDevUUID = (await StorageHelper().g(SQLiteStorageKey.userDevUUID.value)) ?? ''; notifyListeners(); Share.share( diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 9cf5a0a8..e6e76e17 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -163,7 +163,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB onPressed: () async { PhpGroup.unregisterDevice(); - StorageHelper().clearAll(Storage.SecureStorage); + StorageHelper().c(Storage.secureStorage); setState(() {}); diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index c8e210c3..5200e03a 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -22,12 +22,11 @@ class _ReservationPageWidgetState extends State { late WebViewController _controllerAll; Future> initVariables() async { - final email = (await StorageHelper().get(hub.SecureStorageKey.email.value, hub.Storage.SecureStorage)) ?? ''; - final name = (await StorageHelper().get(hub.SQLiteStorageKey.userName.value, hub.Storage.SQLiteStorage)) ?? ''; - final devUUID = (await StorageHelper().get(hub.SQLiteStorageKey.devUUID.value, hub.Storage.SQLiteStorage)) ?? ''; - final userUUID = (await StorageHelper().get(hub.SQLiteStorageKey.userUUID.value, hub.Storage.SQLiteStorage)) ?? ''; - final clientId = - (await StorageHelper().get(hub.SQLiteStorageKey.clientUUID.value, hub.Storage.SQLiteStorage)) ?? ''; + final email = (await StorageHelper().g(hub.SecureStorageKey.email.value)) ?? ''; + final name = (await StorageHelper().g(hub.SQLiteStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().g(hub.SQLiteStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(hub.SQLiteStorageKey.userUUID.value)) ?? ''; + final clientId = (await StorageHelper().g(hub.SQLiteStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart index 2acd9126..05440393 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 @@ -215,9 +215,9 @@ class ScheduleCompleteVisitPageModel extends FlutterFlowModel } Future _initVariables() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } @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 56022372..b95812ec 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 @@ -35,9 +35,9 @@ class _VisitHistoryWidgetState extends State with TickerProv List _visitWrap = []; Future _initVariables() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; } @override @@ -245,10 +245,10 @@ class _VisitHistoryWidgetState extends State with TickerProv }, ], onTapCardItemAction: () async { - final devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - final cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + final devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; await showDialog( useSafeArea: true, diff --git a/lib/pages/welcome_page/welcome_page_widget.dart b/lib/pages/welcome_page/welcome_page_widget.dart index cb24d5e1..96cc2ec9 100644 --- a/lib/pages/welcome_page/welcome_page_widget.dart +++ b/lib/pages/welcome_page/welcome_page_widget.dart @@ -31,13 +31,13 @@ class _WelcomePageWidgetState extends State { // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { if (isAndroid == true) { - await StorageHelper().set(SecureStorageKey.deviceType.value, 'Android', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.deviceType.value, 'Android'); setState(() {}); } else if (isiOS == true) { - await StorageHelper().set(SecureStorageKey.deviceType.value, 'iOS', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.deviceType.value, 'iOS'); setState(() {}); } else { - await StorageHelper().set(SecureStorageKey.deviceType.value, 'Web', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.deviceType.value, 'Web'); setState(() {}); } }); diff --git a/lib/shared/helpers/base_storage.dart b/lib/shared/helpers/base_storage.dart index 9cc96289..18712f8d 100644 --- a/lib/shared/helpers/base_storage.dart +++ b/lib/shared/helpers/base_storage.dart @@ -11,9 +11,11 @@ abstract class BaseStorage { } enum Storage { - SecureStorage, - SharedPreferences, - SQLiteStorage, + secureStorage, + sharedPreferences, + databaseStorage, + sqliteStorage, + licenseStorage, } enum SharedPreferencesKey { diff --git a/lib/shared/helpers/database_storage.dart b/lib/shared/helpers/database_storage.dart new file mode 100644 index 00000000..ce0cec67 --- /dev/null +++ b/lib/shared/helpers/database_storage.dart @@ -0,0 +1,44 @@ +import 'package:hub/shared/services/license/license_service.dart'; +import 'package:hub/shared/services/sqlite/sqlite_service.dart'; +import 'package:sqflite/sqflite.dart'; +import 'package:path/path.dart'; +import 'dart:developer'; + +class DatabaseStorage { + static final String _dbName = 'database.db'; + static final int _dbVersion = 2; + + static final DatabaseStorage instance = DatabaseStorage._internal(); + factory DatabaseStorage() => instance; + DatabaseStorage._internal(); + + static late final Database _database; + static Database get database => _database; + + Future init() async { + _database = await openDatabase( + join(await getDatabasesPath(), _dbName), + version: _dbVersion, + onCreate: _onCreate, + onUpgrade: _onUpgrade, + onDowngrade: _onDowngrade, + ); + } + + Future _onCreate(Database database, int version) async { + log('Creating database...'); + await database.execute(SQLiteStorage.createTableQuery); + await database.execute(LicenseService.createTableQuery); + await LicenseService.setupLicense(); + } + + Future _onUpgrade(Database database, int oldVersion, int newVersion) async { + log('Upgrading database from version $oldVersion to $newVersion...'); + if (oldVersion < 2) { + await database.execute(LicenseService.createTableQuery); + await LicenseService.setupLicense(); + } + } + + Future _onDowngrade(Database database, int oldVersion, int newVersion) async {} +} diff --git a/lib/shared/helpers/sqlite_storage.dart b/lib/shared/helpers/sqlite_storage.dart deleted file mode 100644 index 7f3261fa..00000000 --- a/lib/shared/helpers/sqlite_storage.dart +++ /dev/null @@ -1,180 +0,0 @@ -import 'dart:convert'; -import 'dart:developer'; - -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:sqflite/sqflite.dart'; -import 'package:sqflite/sqlite_api.dart'; -import 'package:path/path.dart'; - -class SQLiteStorage implements BaseStorage { - SQLiteStorage._(); - - static final String _dbName = 'database.db'; - static final int _dbVersion = 2; - - static const String tableKeychain = 'keychain'; - static const String tableLicense = 'license'; - - static final SQLiteStorage instance = SQLiteStorage._(); - - static late final Database _database; - static Database get database => _database; - - @override - Future init() async { - _database = await openDatabase( - join(await getDatabasesPath(), _dbName), - version: _dbVersion, - onCreate: _onCreate, - onUpgrade: _onUpgrade, - onDowngrade: _onDowngrade, - ); - } - - _onCreate(Database database, int version) async { - log('Creating database...'); - try { - await database.execute(_keychain); - await database.execute(_license); - await setupLicense(); - } catch (e) { - log('Tables keychain and license already exists'); - } - } - - _onUpgrade(Database database, int oldVersion, int newVersion) async { - log('Upgrading database from version $oldVersion to $newVersion...'); - if (oldVersion < 2) { - try { - await database.execute(_license); - await setupLicense(); - } catch (e) { - log('Table license already exists'); - } - } - } - - _onDowngrade(Database database, int oldVersion, int newVersion) async {} - - String get _keychain => ''' - CREATE TABLE keychain ( - key TEXT UNIQUE, - value TEXT, - type TEXT, - updateAt TEXT, - resolvedAt TEXT, - createdAt TEXT - ); - '''; - - String get _license => ''' - CREATE TABLE license ( - key TEXT UNIQUE, - display TEXT, - expirationDate TEXT, - startDate TEXT, - quantity TEXT - ); - '''; - - static Future setupLicense() async { - log('initLicense()'); - for (var element in LicenseStorageKey.values.map((e) => e.value)) { - await database.insert( - tableLicense, - { - 'key': element, - 'display': 'VISIVEL', - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }, - conflictAlgorithm: ConflictAlgorithm.ignore, - ); - } - } - - @override - Future get(String key) async { - if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { - return await _getLicense(key); - } else { - return await _getKeychain(key); - } - } - - Future _getKeychain(String key) async { - var response = await _database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); - if (response.isEmpty) { - return null; - } - return response.first['value'].toString(); - } - - Future _getLicense(String key) async { - var response = await _database.query(tableLicense, where: 'key = ?', whereArgs: [key]); - if (response.isEmpty) { - return null; - } - return response.first['value'].toString(); - } - - Future getAll(String table) async { - var response = await _database.query(table); - if (response.isEmpty) { - return null; - } - return jsonEncode(response); - } - - @override - Future set(String key, String value) async { - if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { - return await _setLicense(key, value); - } else { - return await _setKeychain(key, value); - } - } - - Future _setKeychain(String key, String value) async { - var date = DateTime.now().toIso8601String(); - await _database.insert( - tableKeychain, - { - 'key': key, - 'value': value, - 'type': 'local', - 'updateAt': date, - 'resolvedAt': date, - 'createdAt': date, - }, - conflictAlgorithm: ConflictAlgorithm.replace); - } - - Future _setLicense(String key, String value) async { - log('setLicense($key, $value)'); - Map valueMap = jsonDecode(value); - log('String to Map: $value to $valueMap'); - - await _database.insert( - tableLicense, - { - 'key': key, - 'display': valueMap['display'], - 'expirationDate': valueMap['expirationDate'], - 'startDate': valueMap['startDate'], - 'quantity': valueMap['quantity'], - }, - conflictAlgorithm: ConflictAlgorithm.replace); - } - - @override - Future delete(String key) async { - await _database.delete('keychain', where: 'key = ?', whereArgs: [key]); - } - - @override - Future clearAll() async { - await _database.delete('keychain'); - } -} diff --git a/lib/shared/helpers/storage_helper.dart b/lib/shared/helpers/storage_helper.dart index 582a3b4b..7c233537 100644 --- a/lib/shared/helpers/storage_helper.dart +++ b/lib/shared/helpers/storage_helper.dart @@ -1,8 +1,10 @@ import 'package:flutter/cupertino.dart'; import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/database_storage.dart'; import 'package:hub/shared/helpers/secure_storage.dart'; import 'package:hub/shared/helpers/shared_preferences_storage.dart'; -import 'package:hub/shared/helpers/sqlite_storage.dart'; +import 'package:hub/shared/services/license/license_service.dart'; +import 'package:hub/shared/services/sqlite/sqlite_service.dart'; class StorageHelper { static final StorageHelper _instance = StorageHelper._internal(); @@ -20,7 +22,7 @@ class StorageHelper { Future init() async { await SecureStorage.instance.init(); await SharedPreferencesStorage.instance.init(); - await SQLiteStorage.instance.init(); + await DatabaseStorage.instance.init(); String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value); @@ -30,47 +32,110 @@ class StorageHelper { } } - Future get(String key, Storage storage) { + static BaseStorage getInstance(Storage storage) { switch (storage) { - case Storage.SecureStorage: - return SecureStorage.instance.get(key); - case Storage.SharedPreferences: - return SharedPreferencesStorage.instance.get(key); - case Storage.SQLiteStorage: - return SQLiteStorage.instance.get(key); + case Storage.secureStorage: + return SecureStorage.instance; + case Storage.sharedPreferences: + return SharedPreferencesStorage.instance; + case Storage.sqliteStorage: + return SQLiteStorage.instance; + case Storage.licenseStorage: + return LicenseService(); + default: + throw Exception('Storage not found'); } } - Future set(String key, String value, Storage storage) { - switch (storage) { - case Storage.SecureStorage: - return SecureStorage.instance.set(key, value); - case Storage.SharedPreferences: - return SharedPreferencesStorage.instance.set(key, value); - case Storage.SQLiteStorage: - return SQLiteStorage.instance.set(key, value); + static BaseStorage getInstanceByKey(String key) { + if (SecureStorageKey.values.map((e) => e.value).toList().contains(key)) { + return SecureStorage.instance; } + if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) { + return SharedPreferencesStorage.instance; + } + if (SQLiteStorageKey.values.map((e) => e.value).toList().contains(key)) { + return SQLiteStorage.instance; + } + if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { + return LicenseService(); + } + throw Exception('Key not found'); } - Future delete(String key, Storage storage) { - switch (storage) { - case Storage.SecureStorage: - return SecureStorage.instance.delete(key); - case Storage.SharedPreferences: - return SharedPreferencesStorage.instance.delete(key); - case Storage.SQLiteStorage: - return SQLiteStorage.instance.delete(key); - } + Future g(String key) { + return getInstanceByKey(key).get(key); } - Future clearAll(Storage storage) { - switch (storage) { - case Storage.SecureStorage: - return SecureStorage.instance.clearAll(); - case Storage.SharedPreferences: - return SharedPreferencesStorage.instance.clearAll(); - case Storage.SQLiteStorage: - return SQLiteStorage.instance.clearAll(); - } + Future s(String key, String value) { + return getInstanceByKey(key).set(key, value); } + + Future d(String key) { + return getInstanceByKey(key).delete(key); + } + + Future c(Storage storage) { + return getInstance(storage).clearAll(); + } + + // Future get(String key, Storage storage) { + // switch (storage) { + // case Storage.SecureStorage: + // return SecureStorage.instance.get(key); + // case Storage.SharedPreferences: + // return SharedPreferencesStorage.instance.get(key); + // case Storage.SQLiteStorage: + // return SQLiteStorage.instance.get(key); + // case Storage.LicenseStorage: + // return LicenseStorage.instance.get(key); + // default: + // throw Exception('Storage not found'); + // } + // } + + // Future set(String key, String value, Storage storage) { + // switch (storage) { + // case Storage.SecureStorage: + // return SecureStorage.instance.set(key, value); + // case Storage.SharedPreferences: + // return SharedPreferencesStorage.instance.set(key, value); + // case Storage.SQLiteStorage: + // return SQLiteStorage.instance.set(key, value); + // case Storage.LicenseStorage: + // return LicenseStorage.instance.set(key, value); + // default: + // throw Exception('Storage not found'); + // } + // } + + // Future delete(String key, Storage storage) { + // switch (storage) { + // case Storage.SecureStorage: + // return SecureStorage.instance.delete(key); + // case Storage.SharedPreferences: + // return SharedPreferencesStorage.instance.delete(key); + // case Storage.SQLiteStorage: + // return SQLiteStorage.instance.delete(key); + // case Storage.LicenseStorage: + // return LicenseStorage.instance.delete(key); + // default: + // throw Exception('Storage not found'); + // } + // } + + // Future clearAll(Storage storage) { + // switch (storage) { + // case Storage.SecureStorage: + // return SecureStorage.instance.clearAll(); + // case Storage.SharedPreferences: + // return SharedPreferencesStorage.instance.clearAll(); + // case Storage.SQLiteStorage: + // return SQLiteStorage.instance.clearAll(); + // case Storage.LicenseStorage: + // return LicenseStorage.instance.clearAll(); + // default: + // throw Exception('Storage not found'); + // } + // } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 81afd3a1..ebf94824 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -24,14 +24,14 @@ class AuthenticationService { List locals = response.jsonBody['locais'] ?? []; if (locals.isEmpty) { - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'false', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'false'); context.go('/receptionPage'); } else { - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); context.go('/homePage'); } - await StorageHelper().set(SecureStorageKey.isLogged.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.isLogged.value, 'true'); } static Future signIn( @@ -44,7 +44,7 @@ class AuthenticationService { final ApiCallResponse? response; final LoginCall callback = PhpGroup.loginCall; String deviceDescription = randomString(10, 10, true, false, false); - await StorageHelper().set(SecureStorageKey.deviceDescription.value, deviceDescription, Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.deviceDescription.value, deviceDescription); final String? devUUID; final String userUUID; @@ -59,9 +59,9 @@ class AuthenticationService { devUUID = await DeviceUtil.getDevUUID(); if ((email != '') && (passwd != '')) { - await StorageHelper().set(SecureStorageKey.email.value, email, Storage.SecureStorage); - await StorageHelper().set(SecureStorageKey.password.value, passwd, Storage.SecureStorage); - await StorageHelper().set(SQLiteStorageKey.devUUID.value, devUUID!, Storage.SQLiteStorage); + await StorageHelper().s(SecureStorageKey.email.value, email); + await StorageHelper().s(SecureStorageKey.password.value, passwd); + await StorageHelper().s(SQLiteStorageKey.devUUID.value, devUUID!); response = await callback.call(); if (response.jsonBody['error'] == false) { @@ -70,10 +70,10 @@ class AuthenticationService { userDevUUID = response.jsonBody['user']['dev_id']; userName = response.jsonBody['user']['name']; - await StorageHelper().set(SQLiteStorageKey.userUUID.value, userUUID, Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.userDevUUID.value, userDevUUID, Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.status.value, status, Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.userName.value, userName, Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.userUUID.value, userUUID); + await StorageHelper().s(SQLiteStorageKey.userDevUUID.value, userDevUUID); + await StorageHelper().s(SQLiteStorageKey.status.value, status); + await StorageHelper().s(SQLiteStorageKey.userName.value, userName); await login(context); } else { @@ -137,8 +137,8 @@ class AuthenticationService { alignment: Alignment.bottomCenter, ), }; - await StorageHelper().clearAll(Storage.SecureStorage); - await StorageHelper().clearAll(Storage.SQLiteStorage); + await StorageHelper().c(Storage.secureStorage); + await StorageHelper().c(Storage.sqliteStorage); context.go('/welcomePage', extra: extra); } @@ -199,7 +199,7 @@ class AuthenticationService { enText: 'Account deleted successfully', ptText: 'Conta deletada com sucesso', ); - await StorageHelper().clearAll(Storage.SecureStorage); + await StorageHelper().c(Storage.secureStorage); context.pop(); context.go('/welcomePage', extra: extra); } diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 01bb6f9f..72bb5356 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -4,17 +4,88 @@ import 'dart:developer'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/sqlite_storage.dart'; +import 'package:hub/shared/helpers/database_storage.dart'; import 'dart:convert'; import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:sqflite/sqflite.dart'; -class LicenseService { +class LicenseService implements BaseStorage { static final LicenseService _instance = LicenseService._internal(); - factory LicenseService() => _instance; LicenseService._internal(); + static const String tableLicense = 'license'; + + static String get createTableQuery => ''' + CREATE TABLE $tableLicense ( + key TEXT UNIQUE, + display TEXT, + expirationDate TEXT, + startDate TEXT, + quantity TEXT + ); + '''; + + static Future setupLicense() async { + log('initLicense()'); + for (var element in LicenseStorageKey.values.map((e) => e.value)) { + await DatabaseStorage.database.insert( + tableLicense, + { + 'key': element, + 'display': 'VISIVEL', + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }, + conflictAlgorithm: ConflictAlgorithm.ignore, + ); + } + } + + @override + Future init() async { + await DatabaseStorage.instance.init(); + } + + @override + Future get(String key) async { + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); + if (response.isEmpty) { + return null; + } + return response.first['value'].toString(); + } + + @override + Future set(String key, String value) async { + log('setLicense($key, $value)'); + Map valueMap = jsonDecode(value); + log('String to Map: $value to $valueMap'); + + await DatabaseStorage.database.insert( + tableLicense, + { + 'key': key, + 'display': valueMap['display'], + 'expirationDate': valueMap['expirationDate'], + 'startDate': valueMap['startDate'], + 'quantity': valueMap['quantity'], + }, + conflictAlgorithm: ConflictAlgorithm.replace); + } + + @override + Future delete(String key) async { + await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); + } + + @override + Future clearAll() async { + await DatabaseStorage.database.delete(tableLicense); + } + static Future initLicenseService() async { // for (var element in LicenseStorageKey.values.map((e) => e.value)) { // await SQLiteStorage.database.insert( @@ -33,10 +104,10 @@ class LicenseService { static Future processLicense() async {} - static Future fetchLicenses() async { + static Future fetchLicenses() async { try { log('Obtendo licenças...'); - final ApiCallResponse response = await PhpGroup.getLicense(); + final response = await PhpGroup.getLicense(); final dynamic responseBody = response.jsonBody; log('Licenças obtidas: $responseBody'); @@ -51,70 +122,35 @@ class LicenseService { } if (responseBody == []) { - await SQLiteStorage.setupLicense(); + await setupLicense(); + return true; } for (var element in responseBody) { - switch (element['key']) { - case 'FRE-HUB-MESSAGES': - _saveModule(element); - break; - case 'FRE-HUB-LIBERATIONS': - _saveModule(element); - break; - case 'FRE-HUB-RESERVATIONS': - _saveModule(element); - break; - case 'FRE-HUB-ACCESS': - _saveModule(element); - break; - case 'FRE-HUB-OPENED-VISITS': - _saveModule(element); - break; - case 'FRE-HUB-VEHICLES': - _saveModule(element); - break; - case 'FRE-HUB-RESIDENTS': - _saveModule(element); - break; - case 'FRE-HUB-PETS': - _saveModule(element); - break; - case 'FRE-HUB-FASTPASS': - _saveModule(element); - break; - case 'FRE-HUB-ORDERS': - _saveModule(element); - break; - case 'FRE-HUB-COMPLETE-SCHEDULE': - _saveModule(element); - break; - case 'FRE-HUB-AGE-PROV-DELIVERY': - _saveModule(element); - break; - case 'FRE-HUB-AGE-PROV-PRESTADOR': - _saveModule(element); - break; - case 'FRE-WHATSAPP': - _saveModule(element); - break; + if (licenseContainsKey(element['key'])) { + _saveModule(element); } } + return true; } catch (e, s) { log('Erro ao obter licença', error: e, stackTrace: s); - await SQLiteStorage.setupLicense(); + await setupLicense(); + return true; } } + static bool licenseContainsKey(final String key) { + return LicenseStorageKey.values.map((e) => e.value).toList().contains(key); + } + static Future _saveModule(final dynamic body) async { if (body is Map) log('Salvando módulo: ${body.toString()}'); - // if (body is Map) await StorageHelper().set(body['key'], '', Storage.SQLiteStorage); - if (body is Map) await StorageHelper().set(body['key'], jsonEncode(body), Storage.SQLiteStorage); + // if (body is Map) await StorageHelper().s(body['key'], ''); + if (body is Map) await StorageHelper().s(body['key'], jsonEncode(body)); + // StorageHelper.getInstance(Storage.SQLiteStorage).set(key, value); } static Future updateLicense(final dynamic body) async {} - static Future catchLicense() async { - await PhpGroup.getLicense(); - } + static Future catchLicense() async {} } diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 673c318f..124a460c 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -45,11 +45,11 @@ class LocalizationService { final bool isEnable = !isEmpty && isActive; if (isEnable) { - await StorageHelper().set(SecureStorageKey.haveLocal.value, 'true', Storage.SecureStorage); - await StorageHelper().set(SecureStorageKey.isLogged.value, 'true', Storage.SecureStorage); + await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); + await StorageHelper().s(SecureStorageKey.isLogged.value, 'true'); await WidgetsBinding.instance.endOfFrame; - await StorageHelper().set(SQLiteStorageKey.clientUUID.value, '', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, '', Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.clientUUID.value, ''); + await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, ''); StorageHelper().context?.go('/homePage'); } } catch (e, s) { @@ -152,7 +152,7 @@ class LocalizationService { return false; } else { await _updateStorageUtil(response.jsonBody); - return true; + return await LicenseService.fetchLicenses(); } } catch (e, s) { log('() => stack processData: $s'); @@ -163,8 +163,6 @@ class LocalizationService { ); await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); return false; - } finally { - await LicenseService.fetchLicenses(); } } @@ -197,8 +195,8 @@ class LocalizationService { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async { if (value.jsonBody['error'] == false) { - await StorageHelper().set(SQLiteStorageKey.clientName.value, '', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.clientUUID.value, '', Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.clientName.value, ''); + await StorageHelper().s(SQLiteStorageKey.clientUUID.value, ''); context.pop(); context.go( '/homePage', @@ -232,8 +230,8 @@ class LocalizationService { } static void _handleError(BuildContext context, String errorMsg) async { - final String devUUID = await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage) ?? ''; - final String userUUID = await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage) ?? ''; + final String devUUID = await StorageHelper().g(SQLiteStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().g(SQLiteStorageKey.userUUID.value) ?? ''; final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; final bool isDevLinked = !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); log('() => isLinked: $errorMsg'); @@ -261,14 +259,14 @@ class LocalizationService { static Future _handleUnavailable(BuildContext context, List locals) async { log('() => isUnavailable'); try { - await StorageHelper().set(SQLiteStorageKey.clientUUID.value, locals[0]['CLI_ID'], Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID'], Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.clientName.value, locals[0]['CLI_NOME'], Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.clientUUID.value, locals[0]['CLI_ID']); + await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); + await StorageHelper().s(SQLiteStorageKey.clientName.value, locals[0]['CLI_NOME']); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { - await StorageHelper().set(SQLiteStorageKey.clientUUID.value, '', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, '', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.clientName.value, '', Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.clientUUID.value, ''); + await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, ''); + await StorageHelper().s(SQLiteStorageKey.clientName.value, ''); return false; } if (response.jsonBody['error'] == false) return await processData(context).then((value) => value); @@ -282,10 +280,10 @@ class LocalizationService { static Future _handleEnabled(BuildContext context, dynamic local) async { log('() => isEnabled'); - await StorageHelper().set(SQLiteStorageKey.clientUUID.value, local['CLI_ID'], Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, local['CLU_OWNER_ID'], Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.clientName.value, local['CLI_NOME'], Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.userName.value, local['USU_NOME'], Storage.SQLiteStorage); + await StorageHelper().s(SQLiteStorageKey.clientUUID.value, local['CLI_ID']); + await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); + await StorageHelper().s(SQLiteStorageKey.clientName.value, local['CLI_NOME']); + await StorageHelper().s(SQLiteStorageKey.userName.value, local['USU_NOME']); return await processData(context); } @@ -297,19 +295,17 @@ class LocalizationService { } static Future _updateStorageUtil(Map jsonBody) async { - await StorageHelper().set(SQLiteStorageKey.whatsapp.value, - jsonBody['whatsapp'] != null && jsonBody['whatsapp'] ? 'true' : 'false', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.provisional.value, - jsonBody['provisional'] != null && jsonBody['provisional'] ? 'true' : 'false', Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.pets.value, - jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false', Storage.SQLiteStorage); - await StorageHelper().set( + await StorageHelper() + .s(SQLiteStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp'] ? 'true' : 'false'); + await StorageHelper().s(SQLiteStorageKey.provisional.value, + jsonBody['provisional'] != null && jsonBody['provisional'] ? 'true' : 'false'); + await StorageHelper().s(SQLiteStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false'); + await StorageHelper().s( SQLiteStorageKey.petAmount.value, jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty ? '0' - : jsonBody['petAmountRegister'].toString(), - Storage.SQLiteStorage); - await StorageHelper().set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage); + : jsonBody['petAmountRegister'].toString()); + await StorageHelper().s(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); } static bool _isActive(List locals) { @@ -317,7 +313,7 @@ class LocalizationService { } static Future _isInactived(List locals) async { - String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; } @@ -326,21 +322,21 @@ class LocalizationService { } static Future _isUnselected() async { - String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - String cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; - String ownerUUID = (await StorageHelper().get(SQLiteStorageKey.ownerUUID.value, Storage.SQLiteStorage)) ?? ''; + String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + String ownerUUID = (await StorageHelper().g(SQLiteStorageKey.ownerUUID.value)) ?? ''; return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; } static Future _isSelected(bool isInactived) async { - String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - String cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; } static Future _isAvailable() async { - String cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; - String cliName = (await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage)) ?? ''; + String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty; } } diff --git a/lib/shared/services/sqlite/sqlite_service.dart b/lib/shared/services/sqlite/sqlite_service.dart new file mode 100644 index 00000000..4f17b4f7 --- /dev/null +++ b/lib/shared/services/sqlite/sqlite_service.dart @@ -0,0 +1,64 @@ +import 'dart:convert'; +import 'dart:developer'; +import 'package:hub/shared/helpers/database_storage.dart'; +import 'package:sqflite/sqflite.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; + +class SQLiteStorage implements BaseStorage { + SQLiteStorage._(); + + static final SQLiteStorage instance = SQLiteStorage._(); + + static const String tableKeychain = 'keychain'; + + static String get createTableQuery => ''' + CREATE TABLE $tableKeychain ( + key TEXT UNIQUE, + value TEXT, + type TEXT, + updateAt TEXT, + resolvedAt TEXT, + createdAt TEXT + ); + '''; + + @override + Future init() async { + await DatabaseStorage.instance.init(); + } + + @override + Future get(String key) async { + var response = await DatabaseStorage.database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); + if (response.isEmpty) { + return null; + } + return response.first['value'].toString(); + } + + @override + Future set(String key, String value) async { + var date = DateTime.now().toIso8601String(); + await DatabaseStorage.database.insert( + tableKeychain, + { + 'key': key, + 'value': value, + 'type': 'local', + 'updateAt': date, + 'resolvedAt': date, + 'createdAt': date, + }, + conflictAlgorithm: ConflictAlgorithm.replace); + } + + @override + Future delete(String key) async { + await DatabaseStorage.database.delete(tableKeychain, where: 'key = ?', whereArgs: [key]); + } + + @override + Future clearAll() async { + await DatabaseStorage.database.delete(tableKeychain); + } +} diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index 0922c268..b2313323 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -4,8 +4,8 @@ import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final cliName = await StorageHelper().get(SQLiteStorageKey.clientName.value, Storage.SQLiteStorage); - final cliUUID = await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage); + final cliName = await StorageHelper().g(SQLiteStorageKey.clientName.value); + final cliUUID = await StorageHelper().g(SQLiteStorageKey.clientUUID.value); for (var i = 0; i < payload['convites'].length; i++) { await Share.share(''' From 4391efaeaff90d7ad4f00bbc756a8c49f833e145 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 14 Nov 2024 09:39:29 -0300 Subject: [PATCH 05/75] =?UTF-8?q?debit:=20refatora=C3=A7=C3=A3o=20do=20dat?= =?UTF-8?q?abase=20storage~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/backend/api_requests/api_calls.dart | 190 +++++++++--------- .../notifications/notification_service.dart | 6 +- ..._arrow_linked_locals_component_widget.dart | 16 +- .../local_profile_component_model.dart | 4 +- .../local_profile_component_widget.dart | 2 +- .../menu_component/menu_component_model.dart | 12 +- .../schedule_visit_detail_model.dart | 6 +- ...p_arrow_linked_locals_component_model.dart | 8 +- ...cation_modal_template_component_model.dart | 6 +- ...item_details_template_component_model.dart | 6 +- .../provisional_schedule_template_model.dart | 10 +- ...siter_vistor_template_component_model.dart | 6 +- .../view_visit_detail_model.dart | 6 +- ...search_modal_template_component_model.dart | 6 +- lib/flutter_flow/nav/nav.dart | 5 +- lib/main.dart | 1 - .../acess_history_page_model.dart | 6 +- .../fast_pass_page/fast_pass_page_widget.dart | 8 +- lib/pages/home_page/home_page_model.dart | 8 +- .../liberation_history_model.dart | 6 +- .../message_history_page_model.dart | 6 +- .../package_order_page.dart | 2 +- lib/pages/pets_page/pets_history_screen.dart | 8 +- lib/pages/pets_page/pets_page_model.dart | 8 +- .../preferences_settings_model.dart | 28 +-- .../qr_code_page/qr_code_page_model.dart | 4 +- .../reception_page/reception_page_model.dart | 2 +- .../reservation_page_widget.dart | 8 +- .../schedule_complete_visit_page_model.dart | 6 +- .../visit_history_page_widget.dart | 14 +- lib/shared/helpers/base_storage.dart | 44 ++-- lib/shared/helpers/database_storage.dart | 45 ++++- lib/shared/helpers/storage_helper.dart | 96 ++------- .../authentication_service.dart | 12 +- .../keychain_database_delegate.dart} | 10 +- .../services/keychain/keychain_service.dart | 11 + .../license/license_database_delegate.dart | 66 ++++++ .../services/license/license_service.dart | 56 +----- .../localization/localization_service.dart | 59 +++--- lib/shared/utils/share_util.dart | 4 +- 40 files changed, 398 insertions(+), 409 deletions(-) rename lib/shared/services/{sqlite/sqlite_service.dart => keychain/keychain_database_delegate.dart} (89%) create mode 100644 lib/shared/services/keychain/keychain_service.dart create mode 100644 lib/shared/services/license/license_database_delegate.dart diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index bc0c68d4..1de34639 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -92,9 +92,9 @@ class TestCall { class GetLicense { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getLicense', @@ -123,8 +123,8 @@ class GetLicense { class UnregisterDevice { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -151,9 +151,9 @@ class UnregisterDevice { class DeletePet { Future call({final int? petID = 0}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'excluirPet'; return ApiManager.instance.makeApiCall( @@ -196,9 +196,9 @@ class UpdatePet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'atualizarPet'; return ApiManager.instance.makeApiCall( @@ -242,9 +242,9 @@ class GetPets { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaPets'; return ApiManager.instance.makeApiCall( @@ -276,9 +276,9 @@ class GetPetPhoto { Future call({final int? petId}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaFotoPet'; return ApiManager.instance.makeApiCall( @@ -319,9 +319,9 @@ class RegisterPet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cadastrarPet'; return ApiManager.instance.makeApiCall( @@ -364,9 +364,9 @@ class BuscaEnconcomendas { final String? adresseeType, final String? status, }) async { - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getEncomendas'; final String baseUrl = PhpGroup.getBaseUrl(); @@ -408,9 +408,9 @@ class CancelaVisita { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -442,8 +442,8 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String baseUrl = PhpGroup.getBaseUrl(); return ApiManager.instance.makeApiCall( @@ -474,9 +474,9 @@ class ChangePanic { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -510,9 +510,9 @@ class ChangePass { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -546,9 +546,9 @@ class RespondeVinculo { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -580,9 +580,9 @@ class ChangeNotifica { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -614,10 +614,10 @@ class UpdateIDE { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - final String newIde = (await StorageHelper().g(SQLiteStorageKey.userDevUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String newIde = (await StorageHelper().g(KeychainStorageKey.userDevUUID.value)) ?? ''; const String atividade = 'updVisitado'; return ApiManager.instance.makeApiCall( @@ -649,8 +649,8 @@ class UpdToken { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String token = (await StorageHelper().g(SecureStorageKey.token.value)) ?? ''; return ApiManager.instance.makeApiCall( @@ -678,7 +678,7 @@ class UpdToken { class LoginCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; final String email = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; final String password = (await StorageHelper().g(SecureStorageKey.password.value)) ?? ''; final String type = (await StorageHelper().g(SecureStorageKey.deviceType.value)) ?? ''; @@ -765,9 +765,9 @@ class ChangePasswordCall { required final String psswd, }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'changePassword', @@ -826,8 +826,8 @@ class GetLocalsCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = await StorageHelper().g(SQLiteStorageKey.devUUID.value) ?? ''; - final String userUUID = await StorageHelper().g(SQLiteStorageKey.userUUID.value) ?? ''; + final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -866,9 +866,9 @@ class PostScheduleVisitorCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisitante'; return ApiManager.instance.makeApiCall( @@ -921,9 +921,9 @@ class PostScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisita'; return ApiManager.instance.makeApiCall( @@ -975,9 +975,9 @@ class GetScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1249,9 +1249,9 @@ class GetDadosCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getDados'; return ApiManager.instance.makeApiCall( @@ -1482,9 +1482,9 @@ class GetVisitorByDocCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitante'; return ApiManager.instance.makeApiCall( @@ -1536,9 +1536,9 @@ class GetFotoVisitanteCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getFotoVisitante'; return ApiManager.instance.makeApiCall( @@ -1575,9 +1575,9 @@ class PostProvVisitSchedulingCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putAgendamentoProv'; return ApiManager.instance.makeApiCall( @@ -1624,9 +1624,9 @@ class GetVisitsCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; return ApiManager.instance.makeApiCall( @@ -1887,9 +1887,9 @@ class DeleteVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; return ApiManager.instance.makeApiCall( @@ -1930,10 +1930,10 @@ class GetPessoasLocalCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String ownerUUID = (await StorageHelper().g(SQLiteStorageKey.ownerUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; return ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -1996,9 +1996,9 @@ class RespondeSolicitacaoCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'respondeSolicitacao'; return ApiManager.instance.makeApiCall( @@ -2046,9 +2046,9 @@ class GetAccessCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getAcessos'; return ApiManager.instance.makeApiCall( @@ -2295,9 +2295,9 @@ class GetLiberationsCall { final StreamController controller = StreamController(); Future.microtask(() async { - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getSolicitacoes'; try { @@ -2487,9 +2487,9 @@ class GetMessagesCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getMensagens'; return ApiManager.instance.makeApiCall( diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index f97f7a63..b40ad38a 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -15,7 +15,7 @@ import 'package:hub/shared/utils/dialog_util.dart'; Future onMessageReceived(Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; answersRequest( {required BuildContext context, @@ -271,11 +271,11 @@ class NotificationService { await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async { final bool requestOSnotification = - (await StorageHelper().g(SQLiteStorageKey.requestOSNotification.value)) == 'true'; + (await StorageHelper().g(KeychainStorageKey.requestOSNotification.value)) == 'true'; if (requestOSnotification == false) { if (isAllowed == false) { - await StorageHelper().s(SQLiteStorageKey.requestOSNotification.value, 'true'); + await StorageHelper().s(KeychainStorageKey.requestOSNotification.value, 'true'); await AwesomeNotifications().requestPermissionToSendNotifications(); } } 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 b9a930ed..8b7c9df2 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 @@ -105,9 +105,9 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State _fetchResponseLink(String status, String cliID) async { try { - await StorageHelper().s(SQLiteStorageKey.clientUUID.value, cliID); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, cliID); var response = await PhpGroup.resopndeVinculo.call(tarefa: status); if (response.jsonBody['error'] == false) { @@ -147,7 +147,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State getData() async { - cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; 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 2b47bcc0..13b497f0 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 @@ -97,7 +97,7 @@ class _LocalProfileComponentWidgetState extends State onUpdate()); }, child: ClipRRect( 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 7b1579f8..4c58370d 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -60,7 +60,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openDeliverySchedule(BuildContext context) async { - final bool isProvisional = await StorageHelper().g(SQLiteStorageKey.provisional.value) == 'true'; + final bool isProvisional = await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; if (isProvisional == true) { context.push( '/deliverySchedule', @@ -78,7 +78,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openProvisionalSchedule(BuildContext context) async { - final isProvisional = await StorageHelper().g(SQLiteStorageKey.provisional.value) == 'true'; + final isProvisional = await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; if (isProvisional == true) { context.push( '/provisionalSchedule', @@ -96,7 +96,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openFastPassSchedule(BuildContext context) async { - final isWpp = await StorageHelper().g(SQLiteStorageKey.whatsapp.value) == 'true'; + final isWpp = await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; if (isWpp) { context.push( '/fastPassPage', @@ -205,7 +205,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openMyOrders(BuildContext context) async { - final isWpp = await StorageHelper().g(SQLiteStorageKey.whatsapp.value) == 'true'; + final isWpp = await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; ; if (isWpp) { context.push( @@ -224,7 +224,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openReservations(BuildContext context) async { - final isWpp = await StorageHelper().g(SQLiteStorageKey.whatsapp.value) == 'true'; + final isWpp = await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; ; if (isWpp) { context.push( @@ -341,7 +341,7 @@ class MenuComponentModel extends FlutterFlowModel { } Future openPetsRegister(BuildContext context) async { - bool isPet = await StorageHelper().g(SQLiteStorageKey.pets.value) == 'true'; + bool isPet = await StorageHelper().g(KeychainStorageKey.pets.value) == 'true'; ; if (isPet) { context.push( 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 81050e87..a8ae03e4 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 @@ -56,9 +56,9 @@ class ScheduleVisitDetailModel extends FlutterFlowModel initDB() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart index c808f15d..211ab6ce 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 @@ -16,10 +16,10 @@ class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel initDB() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; } @override diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart index b076651b..5e38346f 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 @@ -32,9 +32,9 @@ class AccessNotificationModalTemplateComponentModel } Future initDB() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } @override 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 9bf42aee..b9865a35 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 @@ -27,9 +27,9 @@ class LiberationHistoryItemDetailsTemplateComponentModel void initState(BuildContext context) {} Future initDatabase() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; ; } 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 41a8c60e..f7366c79 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 @@ -138,12 +138,12 @@ class ScheduleProvisionalVisitPageModel extends FlutterFlowModel init() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; ; - cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; - ownerUUID = (await StorageHelper().g(SQLiteStorageKey.ownerUUID.value)) ?? ''; + cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; setState?.call(); } } 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 0aaecec6..494337f1 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 @@ -129,9 +129,9 @@ class RegisiterVistorTemplateComponentModel extends FlutterFlowModel initializeDatabase() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; ; } 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 ae428c74..c9153f31 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 @@ -37,9 +37,9 @@ class ViewVisitDetailModel extends FlutterFlowModel { } Future initializeDatabase() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; ; } 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 4c9ef4c0..aee5f3da 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 @@ -35,9 +35,9 @@ class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel initDatabase() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; ; } diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index fe46ac17..01982757 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -82,8 +82,9 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { future: () async { final bool isLogged = await StorageHelper().g(SecureStorageKey.isLogged.value) == 'true'; final bool haveLocal = await StorageHelper().g(SecureStorageKey.haveLocal.value) == 'true'; - final bool haveUserUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value))?.isNotEmpty ?? false; - final bool haveDevUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value))?.isNotEmpty ?? false; + final bool haveUserUUID = + (await StorageHelper().g(KeychainStorageKey.userUUID.value))?.isNotEmpty ?? false; + final bool haveDevUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value))?.isNotEmpty ?? false; if (isLogged && haveDevUUID && haveUserUUID) { return haveLocal ? const HomePageWidget() : const ReceptionPageWidget(); diff --git a/lib/main.dart b/lib/main.dart index b864eb60..e7d08f3c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -21,7 +21,6 @@ import 'package:hub/pages/forgot_password_page/forgot_password_screen.dart'; import 'package:hub/shared/helpers/base_storage.dart'; import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; -import 'package:hub/shared/utils/device_util.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'backend/notifications/firebase_messaging_service.dart'; 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 eb2fc0c1..046011df 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -33,9 +33,9 @@ class AcessHistoryPageModel extends FlutterFlowModel { } Future initDatabase() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/fast_pass_page/fast_pass_page_widget.dart b/lib/pages/fast_pass_page/fast_pass_page_widget.dart index fc06c01c..f5123a00 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -24,10 +24,10 @@ class _FastPassPageWidgetState extends State { Future> initVariables() async { final email = (await StorageHelper().g(hub.SecureStorageKey.email.value)) ?? ''; - final name = (await StorageHelper().g(hub.SQLiteStorageKey.userName.value)) ?? ''; - final devUUID = (await StorageHelper().g(hub.SQLiteStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(hub.SQLiteStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(hub.SQLiteStorageKey.clientUUID.value)) ?? ''; + final name = (await StorageHelper().g(hub.KeychainStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().g(hub.KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(hub.KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(hub.KeychainStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; final freUserData = diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index bfa6dafa..b3032db6 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -24,10 +24,10 @@ class HomePageModel extends FlutterFlowModel { late MessageWellComponentModel messageWellComponentModel; Future _initVariable() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - userName = (await StorageHelper().g(SQLiteStorageKey.userName.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + userName = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; userEmail = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; } diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index a6296804..c7b7ea6e 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -36,9 +36,9 @@ class LiberationHistoryModel extends FlutterFlowModel { } Future init() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } Future answersRequest( diff --git a/lib/pages/message_history_page/message_history_page_model.dart b/lib/pages/message_history_page/message_history_page_model.dart index bb6852d0..b51112df 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -39,9 +39,9 @@ class MessageHistoryPageModel extends FlutterFlowModel } Future init() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index b7412d3f..93394c26 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -64,7 +64,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/pets_page/pets_history_screen.dart b/lib/pages/pets_page/pets_history_screen.dart index 74249fb2..ea951820 100644 --- a/lib/pages/pets_page/pets_history_screen.dart +++ b/lib/pages/pets_page/pets_history_screen.dart @@ -229,10 +229,10 @@ class _PetsHistoryScreenState extends State with TickerProvid } ], onTapCardItemAction: () async { - final devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - final cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; 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 94bf39b9..a7d1dca7 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -144,10 +144,10 @@ class PetsPageModel extends FlutterFlowModel { textControllerObservation = TextEditingController(); WidgetsBinding.instance.addPostFrameCallback((_) async { - devUUID = await StorageHelper().g(SQLiteStorageKey.devUUID.value) ?? ''; - userUUID = await StorageHelper().g(SQLiteStorageKey.userUUID.value) ?? ''; - cliUUID = await StorageHelper().g(SQLiteStorageKey.clientUUID.value) ?? ''; - petAmountRegister = await StorageHelper().g(SQLiteStorageKey.petAmount.value) ?? ''; + devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; + userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; + cliUUID = await StorageHelper().g(KeychainStorageKey.clientUUID.value) ?? ''; + petAmountRegister = await StorageHelper().g(KeychainStorageKey.petAmount.value) ?? ''; }); } diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index af8623bf..f4fadd91 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -23,11 +23,11 @@ class PreferencesPageModel with ChangeNotifier { late bool isPanic = false; Future _initialize() async { - isFingerprint = await StorageHelper().g(SQLiteStorageKey.fingerprint.value) == 'true'; - isPerson = await StorageHelper().g(SQLiteStorageKey.person.value) == 'true'; - isNotify = await StorageHelper().g(SQLiteStorageKey.notify.value) == 'true'; - isAccess = await StorageHelper().g(SQLiteStorageKey.access.value) == 'true'; - isPanic = await StorageHelper().g(SQLiteStorageKey.panic.value) == 'true'; + isFingerprint = await StorageHelper().g(KeychainStorageKey.fingerprint.value) == 'true'; + isPerson = await StorageHelper().g(KeychainStorageKey.person.value) == 'true'; + isNotify = await StorageHelper().g(KeychainStorageKey.notify.value) == 'true'; + isAccess = await StorageHelper().g(KeychainStorageKey.access.value) == 'true'; + isPanic = await StorageHelper().g(KeychainStorageKey.panic.value) == 'true'; notifyListeners(); } @@ -36,7 +36,7 @@ class PreferencesPageModel with ChangeNotifier { } Future enablePerson(BuildContext context) async { - final String userDevUUID = (await StorageHelper().g(SQLiteStorageKey.userDevUUID.value)) ?? ''; + final String userDevUUID = (await StorageHelper().g(KeychainStorageKey.userDevUUID.value)) ?? ''; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( @@ -63,7 +63,7 @@ class PreferencesPageModel with ChangeNotifier { .call(notifica: value) .then((value) async { if (value.jsonBody['error'] == false) { - await StorageHelper().s(SQLiteStorageKey.notify.value, isNotify ? 'false' : 'true'); + await StorageHelper().s(KeychainStorageKey.notify.value, isNotify ? 'false' : 'true'); content = FFLocalizations.of(context).getVariableText( enText: 'Notification changed successfully', ptText: 'Notificação alterada com sucesso', @@ -86,7 +86,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => isNotify = await StorageHelper().g(SQLiteStorageKey.notify.value) == 'true') + .then((_) async => isNotify = await StorageHelper().g(KeychainStorageKey.notify.value) == 'true') .whenComplete(() => notifyListeners()); context.pop(); } @@ -141,7 +141,7 @@ class PreferencesPageModel with ChangeNotifier { .then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - await StorageHelper().s(SQLiteStorageKey.access.value, isAccess ? 'false' : 'true'); + await StorageHelper().s(KeychainStorageKey.access.value, isAccess ? 'false' : 'true'); notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Access pass changed successfully', @@ -163,7 +163,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => isAccess = await StorageHelper().g(SQLiteStorageKey.access.value) == 'true') + .then((_) async => isAccess = await StorageHelper().g(KeychainStorageKey.access.value) == 'true') .whenComplete(() => notifyListeners()); } @@ -178,7 +178,7 @@ class PreferencesPageModel with ChangeNotifier { .then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - await StorageHelper().s(SQLiteStorageKey.panic.value, isPanic ? 'false' : 'true'); + await StorageHelper().s(KeychainStorageKey.panic.value, isPanic ? 'false' : 'true'); notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Panic password changed successfully', @@ -200,7 +200,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => isPanic = await StorageHelper().g(SQLiteStorageKey.panic.value) == 'true') + .then((_) async => isPanic = await StorageHelper().g(KeychainStorageKey.panic.value) == 'true') .whenComplete(() => notifyListeners()); } @@ -216,10 +216,10 @@ class PreferencesPageModel with ChangeNotifier { onChange(String? key) async { isFingerprint = !isFingerprint; await StorageHelper().s(SecureStorageKey.fingerprintPass.value, key ?? ''); - await StorageHelper().s(SQLiteStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false'); + await StorageHelper().s(KeychainStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false'); notifyListeners(); SnackBarUtil.showSnackBar(context, content); - isFingerprint = await StorageHelper().g(SQLiteStorageKey.fingerprint.value) == 'true'; + isFingerprint = await StorageHelper().g(KeychainStorageKey.fingerprint.value) == 'true'; } isFingerprint ? onChange(null) : _showPassKey(context, onChange); 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 c2786b7b..6bd4c12b 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -29,8 +29,8 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = await StorageHelper().g(SQLiteStorageKey.fingerprint.value) == 'true'; - userDevUUID = await StorageHelper().g(SQLiteStorageKey.userDevUUID.value) ?? ''; + isFingerprint = await StorageHelper().g(KeychainStorageKey.fingerprint.value) == 'true'; + userDevUUID = await StorageHelper().g(KeychainStorageKey.userDevUUID.value) ?? ''; safeSetState?.call(); } diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index e406e8c1..bb4c4727 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -6,7 +6,7 @@ import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final String userDevUUID = (await StorageHelper().g(SQLiteStorageKey.userDevUUID.value)) ?? ''; + final String userDevUUID = (await StorageHelper().g(KeychainStorageKey.userDevUUID.value)) ?? ''; notifyListeners(); Share.share( diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index 5200e03a..757293c9 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -23,10 +23,10 @@ class _ReservationPageWidgetState extends State { Future> initVariables() async { final email = (await StorageHelper().g(hub.SecureStorageKey.email.value)) ?? ''; - final name = (await StorageHelper().g(hub.SQLiteStorageKey.userName.value)) ?? ''; - final devUUID = (await StorageHelper().g(hub.SQLiteStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(hub.SQLiteStorageKey.userUUID.value)) ?? ''; - final clientId = (await StorageHelper().g(hub.SQLiteStorageKey.clientUUID.value)) ?? ''; + final name = (await StorageHelper().g(hub.KeychainStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().g(hub.KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(hub.KeychainStorageKey.userUUID.value)) ?? ''; + final clientId = (await StorageHelper().g(hub.KeychainStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart index 05440393..6f61ea9f 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 @@ -215,9 +215,9 @@ class ScheduleCompleteVisitPageModel extends FlutterFlowModel } Future _initVariables() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } @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 b95812ec..0f655b49 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 @@ -35,9 +35,9 @@ class _VisitHistoryWidgetState extends State with TickerProv List _visitWrap = []; Future _initVariables() async { - devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; } @override @@ -245,10 +245,10 @@ class _VisitHistoryWidgetState extends State with TickerProv }, ], onTapCardItemAction: () async { - final devUUID = (await StorageHelper().g(SQLiteStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(SQLiteStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - final cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; await showDialog( useSafeArea: true, diff --git a/lib/shared/helpers/base_storage.dart b/lib/shared/helpers/base_storage.dart index 18712f8d..fd66d0de 100644 --- a/lib/shared/helpers/base_storage.dart +++ b/lib/shared/helpers/base_storage.dart @@ -14,8 +14,6 @@ enum Storage { secureStorage, sharedPreferences, databaseStorage, - sqliteStorage, - licenseStorage, } enum SharedPreferencesKey { @@ -75,7 +73,7 @@ extension SecureStorageKeyExtension on SecureStorageKey { } } -enum SQLiteStorageKey { +enum KeychainStorageKey { devUUID, userUUID, userDevUUID, @@ -97,46 +95,46 @@ enum SQLiteStorageKey { requestOSNotification, } -extension SQLIteStorageKeyExtension on SQLiteStorageKey { +extension KeychainStorageKeyExtension on KeychainStorageKey { String get value { switch (this) { - case SQLiteStorageKey.devUUID: + case KeychainStorageKey.devUUID: return 'fre_devUUID'; - case SQLiteStorageKey.userUUID: + case KeychainStorageKey.userUUID: return 'fre_userUUID'; - case SQLiteStorageKey.userDevUUID: + case KeychainStorageKey.userDevUUID: return 'fre_userDevUUID'; - case SQLiteStorageKey.status: + case KeychainStorageKey.status: return 'fre_status'; - case SQLiteStorageKey.userName: + case KeychainStorageKey.userName: return 'fre_userName'; - case SQLiteStorageKey.clientUUID: + case KeychainStorageKey.clientUUID: return 'fre_cliUUID'; - case SQLiteStorageKey.ownerUUID: + case KeychainStorageKey.ownerUUID: return 'fre_ownerUUID'; - case SQLiteStorageKey.clientName: + case KeychainStorageKey.clientName: return 'fre_cliName'; - case SQLiteStorageKey.petAmount: + case KeychainStorageKey.petAmount: return 'fre_petAmountRegister'; - case SQLiteStorageKey.whatsapp: + case KeychainStorageKey.whatsapp: return 'fre_whatsapp'; - case SQLiteStorageKey.provisional: + case KeychainStorageKey.provisional: return 'fre_provisional'; - case SQLiteStorageKey.pets: + case KeychainStorageKey.pets: return 'fre_pets'; - case SQLiteStorageKey.local: + case KeychainStorageKey.local: return 'fre_local'; - case SQLiteStorageKey.notify: + case KeychainStorageKey.notify: return 'fre_notify'; - case SQLiteStorageKey.fingerprint: + case KeychainStorageKey.fingerprint: return 'fre_fingerprint'; - case SQLiteStorageKey.access: + case KeychainStorageKey.access: return 'fre_access'; - case SQLiteStorageKey.panic: + case KeychainStorageKey.panic: return 'fre_panic'; - case SQLiteStorageKey.person: + case KeychainStorageKey.person: return 'fre_person'; - case SQLiteStorageKey.requestOSNotification: + case KeychainStorageKey.requestOSNotification: return 'fre_requestOSnotification'; default: return ''; diff --git a/lib/shared/helpers/database_storage.dart b/lib/shared/helpers/database_storage.dart index ce0cec67..2a40d14e 100644 --- a/lib/shared/helpers/database_storage.dart +++ b/lib/shared/helpers/database_storage.dart @@ -1,10 +1,13 @@ +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/services/keychain/keychain_database_delegate.dart'; +import 'package:hub/shared/services/keychain/keychain_service.dart'; +import 'package:hub/shared/services/license/license_database_delegate.dart'; import 'package:hub/shared/services/license/license_service.dart'; -import 'package:hub/shared/services/sqlite/sqlite_service.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart'; import 'dart:developer'; -class DatabaseStorage { +class DatabaseStorage implements BaseStorage { static final String _dbName = 'database.db'; static final int _dbVersion = 2; @@ -15,6 +18,16 @@ class DatabaseStorage { static late final Database _database; static Database get database => _database; + static BaseStorage getInstanceByKey(String key) { + if (KeychainStorageKey.values.map((e) => e.value).toList().contains(key)) { + return KeychainDelegate.instance; + } + if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { + return LicenseDelegate.instance; + } + throw Exception('Storage not found'); + } + Future init() async { _database = await openDatabase( join(await getDatabasesPath(), _dbName), @@ -27,18 +40,40 @@ class DatabaseStorage { Future _onCreate(Database database, int version) async { log('Creating database...'); - await database.execute(SQLiteStorage.createTableQuery); - await database.execute(LicenseService.createTableQuery); + await database.execute(KeychainDelegate.createTableQuery); + await database.execute(LicenseDelegate.createTableQuery); await LicenseService.setupLicense(); } Future _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2) { - await database.execute(LicenseService.createTableQuery); + await database.execute(LicenseDelegate.createTableQuery); await LicenseService.setupLicense(); } } Future _onDowngrade(Database database, int oldVersion, int newVersion) async {} + + @override + Future clearAll() async { + await _database.delete(KeychainDelegate.tableKeychain); + await _database.delete(LicenseDelegate.tableLicense); + return; + } + + @override + Future delete(String key) async { + return await getInstanceByKey(key).delete(key); + } + + @override + Future get(String key) async { + return await getInstanceByKey(key).get(key); + } + + @override + Future set(String key, String value) async { + return await getInstanceByKey(key).set(key, value); + } } diff --git a/lib/shared/helpers/storage_helper.dart b/lib/shared/helpers/storage_helper.dart index 7c233537..879c54a6 100644 --- a/lib/shared/helpers/storage_helper.dart +++ b/lib/shared/helpers/storage_helper.dart @@ -3,8 +3,8 @@ import 'package:hub/shared/helpers/base_storage.dart'; import 'package:hub/shared/helpers/database_storage.dart'; import 'package:hub/shared/helpers/secure_storage.dart'; import 'package:hub/shared/helpers/shared_preferences_storage.dart'; +import 'package:hub/shared/services/keychain/keychain_service.dart'; import 'package:hub/shared/services/license/license_service.dart'; -import 'package:hub/shared/services/sqlite/sqlite_service.dart'; class StorageHelper { static final StorageHelper _instance = StorageHelper._internal(); @@ -38,104 +38,34 @@ class StorageHelper { return SecureStorage.instance; case Storage.sharedPreferences: return SharedPreferencesStorage.instance; - case Storage.sqliteStorage: - return SQLiteStorage.instance; - case Storage.licenseStorage: - return LicenseService(); default: - throw Exception('Storage not found'); + return DatabaseStorage.instance; } } static BaseStorage getInstanceByKey(String key) { if (SecureStorageKey.values.map((e) => e.value).toList().contains(key)) { return SecureStorage.instance; - } - if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) { + } else if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) { return SharedPreferencesStorage.instance; + } else { + return DatabaseStorage.instance; } - if (SQLiteStorageKey.values.map((e) => e.value).toList().contains(key)) { - return SQLiteStorage.instance; - } - if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { - return LicenseService(); - } - throw Exception('Key not found'); } - Future g(String key) { - return getInstanceByKey(key).get(key); + Future g(String key) async { + return await getInstanceByKey(key).get(key); } - Future s(String key, String value) { - return getInstanceByKey(key).set(key, value); + Future s(String key, String value) async { + return await getInstanceByKey(key).set(key, value); } - Future d(String key) { - return getInstanceByKey(key).delete(key); + Future d(String key) async { + return await getInstanceByKey(key).delete(key); } - Future c(Storage storage) { - return getInstance(storage).clearAll(); + Future c(Storage storage) async { + return await getInstance(storage).clearAll(); } - - // Future get(String key, Storage storage) { - // switch (storage) { - // case Storage.SecureStorage: - // return SecureStorage.instance.get(key); - // case Storage.SharedPreferences: - // return SharedPreferencesStorage.instance.get(key); - // case Storage.SQLiteStorage: - // return SQLiteStorage.instance.get(key); - // case Storage.LicenseStorage: - // return LicenseStorage.instance.get(key); - // default: - // throw Exception('Storage not found'); - // } - // } - - // Future set(String key, String value, Storage storage) { - // switch (storage) { - // case Storage.SecureStorage: - // return SecureStorage.instance.set(key, value); - // case Storage.SharedPreferences: - // return SharedPreferencesStorage.instance.set(key, value); - // case Storage.SQLiteStorage: - // return SQLiteStorage.instance.set(key, value); - // case Storage.LicenseStorage: - // return LicenseStorage.instance.set(key, value); - // default: - // throw Exception('Storage not found'); - // } - // } - - // Future delete(String key, Storage storage) { - // switch (storage) { - // case Storage.SecureStorage: - // return SecureStorage.instance.delete(key); - // case Storage.SharedPreferences: - // return SharedPreferencesStorage.instance.delete(key); - // case Storage.SQLiteStorage: - // return SQLiteStorage.instance.delete(key); - // case Storage.LicenseStorage: - // return LicenseStorage.instance.delete(key); - // default: - // throw Exception('Storage not found'); - // } - // } - - // Future clearAll(Storage storage) { - // switch (storage) { - // case Storage.SecureStorage: - // return SecureStorage.instance.clearAll(); - // case Storage.SharedPreferences: - // return SharedPreferencesStorage.instance.clearAll(); - // case Storage.SQLiteStorage: - // return SQLiteStorage.instance.clearAll(); - // case Storage.LicenseStorage: - // return LicenseStorage.instance.clearAll(); - // default: - // throw Exception('Storage not found'); - // } - // } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index ebf94824..67da6484 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -61,7 +61,7 @@ class AuthenticationService { if ((email != '') && (passwd != '')) { await StorageHelper().s(SecureStorageKey.email.value, email); await StorageHelper().s(SecureStorageKey.password.value, passwd); - await StorageHelper().s(SQLiteStorageKey.devUUID.value, devUUID!); + await StorageHelper().s(KeychainStorageKey.devUUID.value, devUUID!); response = await callback.call(); if (response.jsonBody['error'] == false) { @@ -70,10 +70,10 @@ class AuthenticationService { userDevUUID = response.jsonBody['user']['dev_id']; userName = response.jsonBody['user']['name']; - await StorageHelper().s(SQLiteStorageKey.userUUID.value, userUUID); - await StorageHelper().s(SQLiteStorageKey.userDevUUID.value, userDevUUID); - await StorageHelper().s(SQLiteStorageKey.status.value, status); - await StorageHelper().s(SQLiteStorageKey.userName.value, userName); + await StorageHelper().s(KeychainStorageKey.userUUID.value, userUUID); + await StorageHelper().s(KeychainStorageKey.userDevUUID.value, userDevUUID); + await StorageHelper().s(KeychainStorageKey.status.value, status); + await StorageHelper().s(KeychainStorageKey.userName.value, userName); await login(context); } else { @@ -138,7 +138,7 @@ class AuthenticationService { ), }; await StorageHelper().c(Storage.secureStorage); - await StorageHelper().c(Storage.sqliteStorage); + await StorageHelper().c(Storage.databaseStorage); context.go('/welcomePage', extra: extra); } diff --git a/lib/shared/services/sqlite/sqlite_service.dart b/lib/shared/services/keychain/keychain_database_delegate.dart similarity index 89% rename from lib/shared/services/sqlite/sqlite_service.dart rename to lib/shared/services/keychain/keychain_database_delegate.dart index 4f17b4f7..42bb7fc3 100644 --- a/lib/shared/services/sqlite/sqlite_service.dart +++ b/lib/shared/services/keychain/keychain_database_delegate.dart @@ -1,13 +1,11 @@ -import 'dart:convert'; -import 'dart:developer'; +import 'package:hub/shared/helpers/base_storage.dart'; import 'package:hub/shared/helpers/database_storage.dart'; import 'package:sqflite/sqflite.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -class SQLiteStorage implements BaseStorage { - SQLiteStorage._(); +class KeychainDelegate implements BaseStorage { + KeychainDelegate._(); - static final SQLiteStorage instance = SQLiteStorage._(); + static final KeychainDelegate instance = KeychainDelegate._(); static const String tableKeychain = 'keychain'; diff --git a/lib/shared/services/keychain/keychain_service.dart b/lib/shared/services/keychain/keychain_service.dart new file mode 100644 index 00000000..4d14aa4d --- /dev/null +++ b/lib/shared/services/keychain/keychain_service.dart @@ -0,0 +1,11 @@ +import 'dart:convert'; +import 'dart:developer'; +import 'package:hub/shared/helpers/database_storage.dart'; +import 'package:sqflite/sqflite.dart'; +import 'package:hub/shared/helpers/base_storage.dart'; + +class KeychainService { + static final KeychainService _instance = KeychainService._internal(); + factory KeychainService() => _instance; + KeychainService._internal(); +} diff --git a/lib/shared/services/license/license_database_delegate.dart b/lib/shared/services/license/license_database_delegate.dart new file mode 100644 index 00000000..e37e145b --- /dev/null +++ b/lib/shared/services/license/license_database_delegate.dart @@ -0,0 +1,66 @@ +import 'dart:convert'; +import 'dart:developer'; + +import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/database_storage.dart'; +import 'package:sqflite/sqflite.dart'; + +class LicenseDelegate implements BaseStorage { + LicenseDelegate._(); + + static final LicenseDelegate instance = LicenseDelegate._(); + + static const String tableLicense = 'license'; + + static String get createTableQuery => ''' + CREATE TABLE $tableLicense ( + key TEXT UNIQUE, + display TEXT, + expirationDate TEXT, + startDate TEXT, + quantity TEXT + ); + '''; + + @override + Future init() async { + await DatabaseStorage.instance.init(); + } + + @override + Future get(String key) async { + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); + if (response.isEmpty) { + return null; + } + return response.first['value'].toString(); + } + + @override + Future set(String key, String value) async { + log('setLicense($key, $value)'); + Map valueMap = jsonDecode(value); + log('String to Map: $value to $valueMap'); + + await DatabaseStorage.database.insert( + tableLicense, + { + 'key': key, + 'display': valueMap['display'], + 'expirationDate': valueMap['expirationDate'], + 'startDate': valueMap['startDate'], + 'quantity': valueMap['quantity'], + }, + conflictAlgorithm: ConflictAlgorithm.replace); + } + + @override + Future delete(String key) async { + await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); + } + + @override + Future clearAll() async { + await DatabaseStorage.database.delete(tableLicense); + } +} diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 72bb5356..1dee9c9e 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -8,30 +8,21 @@ import 'package:hub/shared/helpers/database_storage.dart'; import 'dart:convert'; import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/services/license/license_database_delegate.dart'; import 'package:sqflite/sqflite.dart'; -class LicenseService implements BaseStorage { +class LicenseService { static final LicenseService _instance = LicenseService._internal(); factory LicenseService() => _instance; LicenseService._internal(); - static const String tableLicense = 'license'; - static String get createTableQuery => ''' - CREATE TABLE $tableLicense ( - key TEXT UNIQUE, - display TEXT, - expirationDate TEXT, - startDate TEXT, - quantity TEXT - ); - '''; static Future setupLicense() async { log('initLicense()'); for (var element in LicenseStorageKey.values.map((e) => e.value)) { await DatabaseStorage.database.insert( - tableLicense, + LicenseDelegate.tableLicense, { 'key': element, 'display': 'VISIVEL', @@ -44,47 +35,6 @@ class LicenseService implements BaseStorage { } } - @override - Future init() async { - await DatabaseStorage.instance.init(); - } - - @override - Future get(String key) async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); - if (response.isEmpty) { - return null; - } - return response.first['value'].toString(); - } - - @override - Future set(String key, String value) async { - log('setLicense($key, $value)'); - Map valueMap = jsonDecode(value); - log('String to Map: $value to $valueMap'); - - await DatabaseStorage.database.insert( - tableLicense, - { - 'key': key, - 'display': valueMap['display'], - 'expirationDate': valueMap['expirationDate'], - 'startDate': valueMap['startDate'], - 'quantity': valueMap['quantity'], - }, - conflictAlgorithm: ConflictAlgorithm.replace); - } - - @override - Future delete(String key) async { - await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); - } - - @override - Future clearAll() async { - await DatabaseStorage.database.delete(tableLicense); - } static Future initLicenseService() async { // for (var element in LicenseStorageKey.values.map((e) => e.value)) { diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 124a460c..59e54cac 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -48,8 +48,8 @@ class LocalizationService { await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); await StorageHelper().s(SecureStorageKey.isLogged.value, 'true'); await WidgetsBinding.instance.endOfFrame; - await StorageHelper().s(SQLiteStorageKey.clientUUID.value, ''); - await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, ''); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await StorageHelper().s(KeychainStorageKey.ownerUUID.value, ''); StorageHelper().context?.go('/homePage'); } } catch (e, s) { @@ -195,8 +195,8 @@ class LocalizationService { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async { if (value.jsonBody['error'] == false) { - await StorageHelper().s(SQLiteStorageKey.clientName.value, ''); - await StorageHelper().s(SQLiteStorageKey.clientUUID.value, ''); + await StorageHelper().s(KeychainStorageKey.clientName.value, ''); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); context.pop(); context.go( '/homePage', @@ -230,8 +230,8 @@ class LocalizationService { } static void _handleError(BuildContext context, String errorMsg) async { - final String devUUID = await StorageHelper().g(SQLiteStorageKey.devUUID.value) ?? ''; - final String userUUID = await StorageHelper().g(SQLiteStorageKey.userUUID.value) ?? ''; + final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; final bool isDevLinked = !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); log('() => isLinked: $errorMsg'); @@ -259,14 +259,14 @@ class LocalizationService { static Future _handleUnavailable(BuildContext context, List locals) async { log('() => isUnavailable'); try { - await StorageHelper().s(SQLiteStorageKey.clientUUID.value, locals[0]['CLI_ID']); - await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); - await StorageHelper().s(SQLiteStorageKey.clientName.value, locals[0]['CLI_NOME']); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); + await StorageHelper().s(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); + await StorageHelper().s(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { - await StorageHelper().s(SQLiteStorageKey.clientUUID.value, ''); - await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, ''); - await StorageHelper().s(SQLiteStorageKey.clientName.value, ''); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await StorageHelper().s(KeychainStorageKey.ownerUUID.value, ''); + await StorageHelper().s(KeychainStorageKey.clientName.value, ''); return false; } if (response.jsonBody['error'] == false) return await processData(context).then((value) => value); @@ -280,10 +280,10 @@ class LocalizationService { static Future _handleEnabled(BuildContext context, dynamic local) async { log('() => isEnabled'); - await StorageHelper().s(SQLiteStorageKey.clientUUID.value, local['CLI_ID']); - await StorageHelper().s(SQLiteStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); - await StorageHelper().s(SQLiteStorageKey.clientName.value, local['CLI_NOME']); - await StorageHelper().s(SQLiteStorageKey.userName.value, local['USU_NOME']); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, local['CLI_ID']); + await StorageHelper().s(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); + await StorageHelper().s(KeychainStorageKey.clientName.value, local['CLI_NOME']); + await StorageHelper().s(KeychainStorageKey.userName.value, local['USU_NOME']); return await processData(context); } @@ -296,16 +296,17 @@ class LocalizationService { static Future _updateStorageUtil(Map jsonBody) async { await StorageHelper() - .s(SQLiteStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp'] ? 'true' : 'false'); - await StorageHelper().s(SQLiteStorageKey.provisional.value, + .s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp'] ? 'true' : 'false'); + await StorageHelper().s(KeychainStorageKey.provisional.value, jsonBody['provisional'] != null && jsonBody['provisional'] ? 'true' : 'false'); - await StorageHelper().s(SQLiteStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false'); + await StorageHelper() + .s(KeychainStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false'); await StorageHelper().s( - SQLiteStorageKey.petAmount.value, + KeychainStorageKey.petAmount.value, jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString()); - await StorageHelper().s(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); + await StorageHelper().s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); } static bool _isActive(List locals) { @@ -313,7 +314,7 @@ class LocalizationService { } static Future _isInactived(List locals) async { - String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; } @@ -322,21 +323,21 @@ class LocalizationService { } static Future _isUnselected() async { - String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; - String ownerUUID = (await StorageHelper().g(SQLiteStorageKey.ownerUUID.value)) ?? ''; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + String ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; } static Future _isSelected(bool isInactived) async { - String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; } static Future _isAvailable() async { - String cliUUID = (await StorageHelper().g(SQLiteStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(SQLiteStorageKey.clientName.value)) ?? ''; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty; } } diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index b2313323..67a4e183 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -4,8 +4,8 @@ import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final cliName = await StorageHelper().g(SQLiteStorageKey.clientName.value); - final cliUUID = await StorageHelper().g(SQLiteStorageKey.clientUUID.value); + final cliName = await StorageHelper().g(KeychainStorageKey.clientName.value); + final cliUUID = await StorageHelper().g(KeychainStorageKey.clientUUID.value); for (var i = 0; i < payload['convites'].length; i++) { await Share.share(''' From 4eca85a85d56cd7a7870bf625e380e0bcfd11de8 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 14 Nov 2024 10:46:10 -0300 Subject: [PATCH 06/75] WIP --- lib/backend/notifications/notification_service.dart | 4 ++-- lib/main.dart | 8 ++++---- lib/pages/fast_pass_page/fast_pass_page_widget.dart | 4 ++-- .../reservation_page/reservation_page_widget.dart | 4 ++-- lib/shared/helpers/base_storage.dart | 3 ++- lib/shared/helpers/database_storage.dart | 2 +- lib/shared/helpers/secure_storage.dart | 4 ++-- lib/shared/helpers/shared_preferences_storage.dart | 4 ++-- lib/shared/helpers/storage_helper.dart | 8 +++----- .../authentication/authentication_service.dart | 6 +++--- .../keychain/keychain_database_delegate.dart | 4 ++-- lib/shared/services/keychain/keychain_service.dart | 6 +----- .../services/license/license_database_delegate.dart | 13 ++++++------- lib/shared/services/license/license_service.dart | 10 +++------- .../services/localization/localization_service.dart | 5 ++--- 15 files changed, 37 insertions(+), 48 deletions(-) diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index b40ad38a..e6512034 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -239,7 +239,7 @@ Future onMessageReceived(Map payload, String? extra, Stri break; case 'enroll_cond': - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, true); StorageHelper().context!.go('/homePage'); break; default: @@ -275,7 +275,7 @@ class NotificationService { if (requestOSnotification == false) { if (isAllowed == false) { - await StorageHelper().s(KeychainStorageKey.requestOSNotification.value, 'true'); + await StorageHelper().s(KeychainStorageKey.requestOSNotification.value, true); await AwesomeNotifications().requestPermissionToSendNotifications(); } } diff --git a/lib/main.dart b/lib/main.dart index e7d08f3c..55765c25 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -82,7 +82,7 @@ Future _initializeFlutterFlow() async { Future _foregroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, true); StorageHelper().context?.go('/homePage'); } @@ -96,7 +96,7 @@ Future _foregroundHandlerMessage(RemoteMessage message) async { Future _backgroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, true); StorageHelper().context?.go('/homePage'); } } @@ -225,7 +225,7 @@ class _AppState extends State with WidgetsBindingObserver { FirebaseMessaging.onMessage.listen(_foregroundHandlerMessage); FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, true); log('onMessageOpenedApp'); } else { onMessageReceived(message.data, message.notification!.body, message.data['click_action']); @@ -234,7 +234,7 @@ class _AppState extends State with WidgetsBindingObserver { FirebaseMessaging.instance.getInitialMessage().then((message) async { if (message != null) { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, true); log('getInitialMessage'); } } 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 f5123a00..c998e6cc 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -78,7 +78,7 @@ class _FastPassPageWidgetState extends State { await controller.evaluateJavascript( source: "window.localStorage.setItem('fre-user-data', '$freUserData')"); await controller.evaluateJavascript( - source: "window.localStorage.setItem('enableBackButton', 'true')"); + source: "window.localStorage.setItem('enableBackButton', true)"); }, onUpdateVisitedHistory: (controller, uri, isVisited) { if (uri.toString().contains('/hub/home')) context.pop(); @@ -96,7 +96,7 @@ class _FastPassPageWidgetState extends State { onPageStarted: (String url) { final String token = "localStorage.setItem('fre-token', '\"$userUUID\"');"; final String data = "localStorage.setItem('fre-user-data', '$freUserData');"; - const String backNavigation = "localStorage.setItem('enableBackButton', 'true');"; + const String backNavigation = "localStorage.setItem('enableBackButton', true);"; _controllerAndroid.runJavaScript(token); _controllerAndroid.runJavaScript(data); diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index 757293c9..1f5e4f47 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -79,7 +79,7 @@ class _ReservationPageWidgetState extends State { await controller.evaluateJavascript( source: "window.localStorage.setItem('fre-user-data', '$freUserData')"); await controller.evaluateJavascript( - source: "window.localStorage.setItem('enableBackButton', 'true')"); + source: "window.localStorage.setItem('enableBackButton', true)"); }, onUpdateVisitedHistory: (controller, uri, isVisited) { if (uri.toString().contains('/hub/home')) { @@ -99,7 +99,7 @@ class _ReservationPageWidgetState extends State { onPageStarted: (String url) { final String token = "localStorage.setItem('fre-token', '\"$userUUID\"');"; final String data = "localStorage.setItem('fre-user-data', '$freUserData');"; - const String backNavigation = "localStorage.setItem('enableBackButton', 'true');"; + const String backNavigation = "localStorage.setItem('enableBackButton', true);"; _controllerAll.runJavaScript(token); _controllerAll.runJavaScript(data); diff --git a/lib/shared/helpers/base_storage.dart b/lib/shared/helpers/base_storage.dart index fd66d0de..3fae76dd 100644 --- a/lib/shared/helpers/base_storage.dart +++ b/lib/shared/helpers/base_storage.dart @@ -1,7 +1,8 @@ abstract class BaseStorage { Future init(); - Future set(String key, String value); + Future set(String key, T value); + Future get(String key); diff --git a/lib/shared/helpers/database_storage.dart b/lib/shared/helpers/database_storage.dart index 2a40d14e..5d981a64 100644 --- a/lib/shared/helpers/database_storage.dart +++ b/lib/shared/helpers/database_storage.dart @@ -73,7 +73,7 @@ class DatabaseStorage implements BaseStorage { } @override - Future set(String key, String value) async { + Future set(String key, T value) async { return await getInstanceByKey(key).set(key, value); } } diff --git a/lib/shared/helpers/secure_storage.dart b/lib/shared/helpers/secure_storage.dart index 0313b583..949e1ca9 100644 --- a/lib/shared/helpers/secure_storage.dart +++ b/lib/shared/helpers/secure_storage.dart @@ -20,8 +20,8 @@ class SecureStorage implements BaseStorage { } @override - Future set(String key, String value) async { - await _secureStorage.write(key: key, value: value); + Future set(String key, T value) async { + await _secureStorage.write(key: key, value: value.toString()); } @override diff --git a/lib/shared/helpers/shared_preferences_storage.dart b/lib/shared/helpers/shared_preferences_storage.dart index c7d10cd5..358f5920 100644 --- a/lib/shared/helpers/shared_preferences_storage.dart +++ b/lib/shared/helpers/shared_preferences_storage.dart @@ -20,8 +20,8 @@ class SharedPreferencesStorage implements BaseStorage { } @override - Future set(String key, String value) async { - await _prefs.setString(key, value); + Future set(String key, T value) async { + await _prefs.setString(key, value.toString()); } @override diff --git a/lib/shared/helpers/storage_helper.dart b/lib/shared/helpers/storage_helper.dart index 879c54a6..286115ab 100644 --- a/lib/shared/helpers/storage_helper.dart +++ b/lib/shared/helpers/storage_helper.dart @@ -3,8 +3,6 @@ import 'package:hub/shared/helpers/base_storage.dart'; import 'package:hub/shared/helpers/database_storage.dart'; import 'package:hub/shared/helpers/secure_storage.dart'; import 'package:hub/shared/helpers/shared_preferences_storage.dart'; -import 'package:hub/shared/services/keychain/keychain_service.dart'; -import 'package:hub/shared/services/license/license_service.dart'; class StorageHelper { static final StorageHelper _instance = StorageHelper._internal(); @@ -27,8 +25,8 @@ class StorageHelper { String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value); if (isFirstRun == 'true') { - await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, 'false'); - await SecureStorage.instance.set(SecureStorageKey.isLogged.value, 'false'); + await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, false); + await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); } } @@ -57,7 +55,7 @@ class StorageHelper { return await getInstanceByKey(key).get(key); } - Future s(String key, String value) async { + Future s(String key, T value) async { return await getInstanceByKey(key).set(key, value); } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 67da6484..040087d2 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -24,14 +24,14 @@ class AuthenticationService { List locals = response.jsonBody['locais'] ?? []; if (locals.isEmpty) { - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'false'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, false); context.go('/receptionPage'); } else { - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, true); context.go('/homePage'); } - await StorageHelper().s(SecureStorageKey.isLogged.value, 'true'); + await StorageHelper().s(SecureStorageKey.isLogged.value, true); } static Future signIn( diff --git a/lib/shared/services/keychain/keychain_database_delegate.dart b/lib/shared/services/keychain/keychain_database_delegate.dart index 42bb7fc3..35ccf130 100644 --- a/lib/shared/services/keychain/keychain_database_delegate.dart +++ b/lib/shared/services/keychain/keychain_database_delegate.dart @@ -35,13 +35,13 @@ class KeychainDelegate implements BaseStorage { } @override - Future set(String key, String value) async { + Future set(String key, T value) async { var date = DateTime.now().toIso8601String(); await DatabaseStorage.database.insert( tableKeychain, { 'key': key, - 'value': value, + 'value': value.toString(), 'type': 'local', 'updateAt': date, 'resolvedAt': date, diff --git a/lib/shared/services/keychain/keychain_service.dart b/lib/shared/services/keychain/keychain_service.dart index 4d14aa4d..13fa5ceb 100644 --- a/lib/shared/services/keychain/keychain_service.dart +++ b/lib/shared/services/keychain/keychain_service.dart @@ -1,8 +1,4 @@ -import 'dart:convert'; -import 'dart:developer'; -import 'package:hub/shared/helpers/database_storage.dart'; -import 'package:sqflite/sqflite.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; + class KeychainService { static final KeychainService _instance = KeychainService._internal(); diff --git a/lib/shared/services/license/license_database_delegate.dart b/lib/shared/services/license/license_database_delegate.dart index e37e145b..873b0bde 100644 --- a/lib/shared/services/license/license_database_delegate.dart +++ b/lib/shared/services/license/license_database_delegate.dart @@ -37,19 +37,18 @@ class LicenseDelegate implements BaseStorage { } @override - Future set(String key, String value) async { + Future set(String key, T value) async { log('setLicense($key, $value)'); - Map valueMap = jsonDecode(value); - log('String to Map: $value to $valueMap'); + value as Map; await DatabaseStorage.database.insert( tableLicense, { 'key': key, - 'display': valueMap['display'], - 'expirationDate': valueMap['expirationDate'], - 'startDate': valueMap['startDate'], - 'quantity': valueMap['quantity'], + 'display': value['display'], + 'expirationDate': value['expirationDate'], + 'startDate': value['startDate'], + 'quantity': value['quantity'], }, conflictAlgorithm: ConflictAlgorithm.replace); } diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 1dee9c9e..079751a8 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -16,10 +16,8 @@ class LicenseService { factory LicenseService() => _instance; LicenseService._internal(); - - static Future setupLicense() async { - log('initLicense()'); + log('All modules are visible'); for (var element in LicenseStorageKey.values.map((e) => e.value)) { await DatabaseStorage.database.insert( LicenseDelegate.tableLicense, @@ -35,7 +33,6 @@ class LicenseService { } } - static Future initLicenseService() async { // for (var element in LicenseStorageKey.values.map((e) => e.value)) { // await SQLiteStorage.database.insert( @@ -82,8 +79,7 @@ class LicenseService { } } return true; - } catch (e, s) { - log('Erro ao obter licença', error: e, stackTrace: s); + } catch (e) { await setupLicense(); return true; } @@ -96,7 +92,7 @@ class LicenseService { static Future _saveModule(final dynamic body) async { if (body is Map) log('Salvando módulo: ${body.toString()}'); // if (body is Map) await StorageHelper().s(body['key'], ''); - if (body is Map) await StorageHelper().s(body['key'], jsonEncode(body)); + if (body is Map) await StorageHelper().s(body['key'], body); // StorageHelper.getInstance(Storage.SQLiteStorage).set(key, value); } diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 59e54cac..59a3a409 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -9,7 +9,6 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/base_storage.dart'; import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/services/license/license_service.dart'; -import 'package:hub/shared/utils/device_util.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import '../../../backend/api_requests/api_calls.dart'; @@ -45,8 +44,8 @@ class LocalizationService { final bool isEnable = !isEmpty && isActive; if (isEnable) { - await StorageHelper().s(SecureStorageKey.haveLocal.value, 'true'); - await StorageHelper().s(SecureStorageKey.isLogged.value, 'true'); + await StorageHelper().s(SecureStorageKey.haveLocal.value, true); + await StorageHelper().s(SecureStorageKey.isLogged.value, true); await WidgetsBinding.instance.endOfFrame; await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); await StorageHelper().s(KeychainStorageKey.ownerUUID.value, ''); From 1f70e5db226aa20c4d746e9160448499334a7b41 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 14 Nov 2024 16:50:09 -0300 Subject: [PATCH 07/75] WIP --- lib/shared/helpers/database_storage.dart | 20 ++++++++++++------- .../services/license/license_service.dart | 8 ++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/shared/helpers/database_storage.dart b/lib/shared/helpers/database_storage.dart index 5d981a64..e46b21bb 100644 --- a/lib/shared/helpers/database_storage.dart +++ b/lib/shared/helpers/database_storage.dart @@ -15,8 +15,13 @@ class DatabaseStorage implements BaseStorage { factory DatabaseStorage() => instance; DatabaseStorage._internal(); - static late final Database _database; - static Database get database => _database; + static Database? _database; + static Database get database { + if (_database == null) { + throw Exception('Database has not been initialized. Call init() first.'); + } + return _database!; + } static BaseStorage getInstanceByKey(String key) { if (KeychainStorageKey.values.map((e) => e.value).toList().contains(key)) { @@ -29,6 +34,7 @@ class DatabaseStorage implements BaseStorage { } Future init() async { + if (_database != null && _database!.isOpen) return; _database = await openDatabase( join(await getDatabasesPath(), _dbName), version: _dbVersion, @@ -42,14 +48,14 @@ class DatabaseStorage implements BaseStorage { log('Creating database...'); await database.execute(KeychainDelegate.createTableQuery); await database.execute(LicenseDelegate.createTableQuery); - await LicenseService.setupLicense(); + await LicenseService.setupLicense(database); } Future _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2) { await database.execute(LicenseDelegate.createTableQuery); - await LicenseService.setupLicense(); + await LicenseService.setupLicense(database); } } @@ -57,8 +63,8 @@ class DatabaseStorage implements BaseStorage { @override Future clearAll() async { - await _database.delete(KeychainDelegate.tableKeychain); - await _database.delete(LicenseDelegate.tableLicense); + await _database?.delete(KeychainDelegate.tableKeychain); + await _database?.delete(LicenseDelegate.tableLicense); return; } @@ -76,4 +82,4 @@ class DatabaseStorage implements BaseStorage { Future set(String key, T value) async { return await getInstanceByKey(key).set(key, value); } -} +} \ No newline at end of file diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 079751a8..49851806 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -16,10 +16,10 @@ class LicenseService { factory LicenseService() => _instance; LicenseService._internal(); - static Future setupLicense() async { + static Future setupLicense(Database database) async { log('All modules are visible'); for (var element in LicenseStorageKey.values.map((e) => e.value)) { - await DatabaseStorage.database.insert( + await database.insert( LicenseDelegate.tableLicense, { 'key': element, @@ -69,7 +69,7 @@ class LicenseService { } if (responseBody == []) { - await setupLicense(); + await setupLicense(DatabaseStorage.database); return true; } @@ -80,7 +80,7 @@ class LicenseService { } return true; } catch (e) { - await setupLicense(); + await setupLicense(DatabaseStorage.database); return true; } } From c5112075e670132fc39dc2e8b4a5256f59e5b86e Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 14 Nov 2024 18:04:33 -0300 Subject: [PATCH 08/75] WIP --- lib/shared/helpers/base_storage.dart | 64 ++++++++++++++++++- ...base_storage.dart => database_helper.dart} | 41 ++---------- .../keychain_storage.dart} | 2 +- .../license_helper.dart} | 19 +++++- lib/shared/helpers/secure_storage.dart | 1 - .../helpers/shared_preferences_storage.dart | 1 - lib/shared/helpers/storage_helper.dart | 7 +- .../services/license/license_service.dart | 21 ++---- .../localization/localization_service.dart | 20 ++++-- 9 files changed, 106 insertions(+), 70 deletions(-) rename lib/shared/helpers/{database_storage.dart => database_helper.dart} (56%) rename lib/shared/{services/keychain/keychain_database_delegate.dart => helpers/keychain_storage.dart} (96%) rename lib/shared/{services/license/license_database_delegate.dart => helpers/license_helper.dart} (76%) diff --git a/lib/shared/helpers/base_storage.dart b/lib/shared/helpers/base_storage.dart index 3fae76dd..76efbc99 100644 --- a/lib/shared/helpers/base_storage.dart +++ b/lib/shared/helpers/base_storage.dart @@ -2,7 +2,6 @@ abstract class BaseStorage { Future init(); Future set(String key, T value); - Future get(String key); @@ -94,6 +93,7 @@ enum KeychainStorageKey { panic, person, requestOSNotification, + isNewVersion, } extension KeychainStorageKeyExtension on KeychainStorageKey { @@ -137,6 +137,68 @@ extension KeychainStorageKeyExtension on KeychainStorageKey { return 'fre_person'; case KeychainStorageKey.requestOSNotification: return 'fre_requestOSnotification'; + case KeychainStorageKey.isNewVersion: + return 'fre_isNewVersion'; + default: + return ''; + } + } +} + +enum InactiveLicenseKey { + residents, + vehicles, + openedVisits, +} + +enum ActiveLicenseKey { + messages, + liberations, + reservations, + access, + orders, + completeSchedule, + providerSchedule, + deliverySchedule, + fastPass, +} + +extension InactiveLicenseKeyExtension on InactiveLicenseKey { + String get value { + switch (this) { + case InactiveLicenseKey.residents: + return 'FRE-HUB-RESIDENTS'; + case InactiveLicenseKey.vehicles: + return 'FRE-HUB-VEHICLES'; + case InactiveLicenseKey.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + default: + return ''; + } + } +} + +extension ActiveLicenseKeyExtension on ActiveLicenseKey { + String get value { + switch (this) { + case ActiveLicenseKey.messages: + return 'FRE-HUB-MESSAGES'; + case ActiveLicenseKey.liberations: + return 'FRE-HUB-LIBERATIONS'; + case ActiveLicenseKey.reservations: + return 'FRE-HUB-RESERVATIONS'; + case ActiveLicenseKey.access: + return 'FRE-HUB-ACCESS'; + case ActiveLicenseKey.orders: + return 'FRE-HUB-ORDERS'; + case ActiveLicenseKey.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case ActiveLicenseKey.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case ActiveLicenseKey.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case ActiveLicenseKey.fastPass: + return 'FRE-HUB-FASTPASS'; default: return ''; } diff --git a/lib/shared/helpers/database_storage.dart b/lib/shared/helpers/database_helper.dart similarity index 56% rename from lib/shared/helpers/database_storage.dart rename to lib/shared/helpers/database_helper.dart index e46b21bb..84b33c35 100644 --- a/lib/shared/helpers/database_storage.dart +++ b/lib/shared/helpers/database_helper.dart @@ -1,13 +1,11 @@ -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/services/keychain/keychain_database_delegate.dart'; -import 'package:hub/shared/services/keychain/keychain_service.dart'; -import 'package:hub/shared/services/license/license_database_delegate.dart'; +import 'package:hub/shared/helpers/keychain_storage.dart'; +import 'package:hub/shared/helpers/license_helper.dart'; import 'package:hub/shared/services/license/license_service.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart'; import 'dart:developer'; -class DatabaseStorage implements BaseStorage { +class DatabaseStorage { static final String _dbName = 'database.db'; static final int _dbVersion = 2; @@ -23,16 +21,6 @@ class DatabaseStorage implements BaseStorage { return _database!; } - static BaseStorage getInstanceByKey(String key) { - if (KeychainStorageKey.values.map((e) => e.value).toList().contains(key)) { - return KeychainDelegate.instance; - } - if (LicenseStorageKey.values.map((e) => e.value).toList().contains(key)) { - return LicenseDelegate.instance; - } - throw Exception('Storage not found'); - } - Future init() async { if (_database != null && _database!.isOpen) return; _database = await openDatabase( @@ -61,25 +49,4 @@ class DatabaseStorage implements BaseStorage { Future _onDowngrade(Database database, int oldVersion, int newVersion) async {} - @override - Future clearAll() async { - await _database?.delete(KeychainDelegate.tableKeychain); - await _database?.delete(LicenseDelegate.tableLicense); - return; - } - - @override - Future delete(String key) async { - return await getInstanceByKey(key).delete(key); - } - - @override - Future get(String key) async { - return await getInstanceByKey(key).get(key); - } - - @override - Future set(String key, T value) async { - return await getInstanceByKey(key).set(key, value); - } -} \ No newline at end of file +} diff --git a/lib/shared/services/keychain/keychain_database_delegate.dart b/lib/shared/helpers/keychain_storage.dart similarity index 96% rename from lib/shared/services/keychain/keychain_database_delegate.dart rename to lib/shared/helpers/keychain_storage.dart index 35ccf130..8be43ccc 100644 --- a/lib/shared/services/keychain/keychain_database_delegate.dart +++ b/lib/shared/helpers/keychain_storage.dart @@ -1,5 +1,5 @@ import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_storage.dart'; +import 'package:hub/shared/helpers/database_helper.dart'; import 'package:sqflite/sqflite.dart'; class KeychainDelegate implements BaseStorage { diff --git a/lib/shared/services/license/license_database_delegate.dart b/lib/shared/helpers/license_helper.dart similarity index 76% rename from lib/shared/services/license/license_database_delegate.dart rename to lib/shared/helpers/license_helper.dart index 873b0bde..17896651 100644 --- a/lib/shared/services/license/license_database_delegate.dart +++ b/lib/shared/helpers/license_helper.dart @@ -1,8 +1,7 @@ -import 'dart:convert'; import 'dart:developer'; import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_storage.dart'; +import 'package:hub/shared/helpers/database_helper.dart'; import 'package:sqflite/sqflite.dart'; class LicenseDelegate implements BaseStorage { @@ -53,6 +52,22 @@ class LicenseDelegate implements BaseStorage { conflictAlgorithm: ConflictAlgorithm.replace); } + static Future insertLicenseFoo(final List key, final String display) async { + for (var element in key) { + DatabaseStorage.database.insert( + LicenseDelegate.tableLicense, + { + 'key': element, + 'display': display, + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }, + conflictAlgorithm: ConflictAlgorithm.ignore, + ); + } + } + @override Future delete(String key) async { await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); diff --git a/lib/shared/helpers/secure_storage.dart b/lib/shared/helpers/secure_storage.dart index 949e1ca9..b579c543 100644 --- a/lib/shared/helpers/secure_storage.dart +++ b/lib/shared/helpers/secure_storage.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:hub/shared/helpers/base_storage.dart'; diff --git a/lib/shared/helpers/shared_preferences_storage.dart b/lib/shared/helpers/shared_preferences_storage.dart index 358f5920..9a9b4fd1 100644 --- a/lib/shared/helpers/shared_preferences_storage.dart +++ b/lib/shared/helpers/shared_preferences_storage.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:hub/shared/helpers/base_storage.dart'; import 'package:shared_preferences/shared_preferences.dart'; diff --git a/lib/shared/helpers/storage_helper.dart b/lib/shared/helpers/storage_helper.dart index 286115ab..4c5418d3 100644 --- a/lib/shared/helpers/storage_helper.dart +++ b/lib/shared/helpers/storage_helper.dart @@ -1,6 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_storage.dart'; +import 'package:hub/shared/helpers/database_helper.dart'; +import 'package:hub/shared/helpers/keychain_storage.dart'; import 'package:hub/shared/helpers/secure_storage.dart'; import 'package:hub/shared/helpers/shared_preferences_storage.dart'; @@ -37,7 +38,7 @@ class StorageHelper { case Storage.sharedPreferences: return SharedPreferencesStorage.instance; default: - return DatabaseStorage.instance; + return KeychainDelegate.instance; } } @@ -47,7 +48,7 @@ class StorageHelper { } else if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) { return SharedPreferencesStorage.instance; } else { - return DatabaseStorage.instance; + return KeychainDelegate.instance; } } diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 49851806..215aa663 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -4,11 +4,10 @@ import 'dart:developer'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_storage.dart'; -import 'dart:convert'; +import 'package:hub/shared/helpers/database_helper.dart'; +import 'package:hub/shared/helpers/license_helper.dart'; import 'package:hub/shared/helpers/storage_helper.dart'; -import 'package:hub/shared/services/license/license_database_delegate.dart'; import 'package:sqflite/sqflite.dart'; class LicenseService { @@ -17,20 +16,8 @@ class LicenseService { LicenseService._internal(); static Future setupLicense(Database database) async { - log('All modules are visible'); - for (var element in LicenseStorageKey.values.map((e) => e.value)) { - await database.insert( - LicenseDelegate.tableLicense, - { - 'key': element, - 'display': 'VISIVEL', - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }, - conflictAlgorithm: ConflictAlgorithm.ignore, - ); - } + await LicenseDelegate.insertLicenseFoo(InactiveLicenseKey.values.map((e) => e.value).toList(), 'INVISIVEL'); + await LicenseDelegate.insertLicenseFoo(ActiveLicenseKey.values.map((e) => e.value).toList(), 'VISIVEL'); } static Future initLicenseService() async { diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 59a3a409..08501be0 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -7,6 +7,7 @@ import 'package:http/src/response.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/database_helper.dart'; import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/services/license/license_service.dart'; import 'package:hub/shared/utils/dialog_util.dart'; @@ -150,7 +151,11 @@ class LocalizationService { await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } else { - await _updateStorageUtil(response.jsonBody); + final bool isNewVersion = await _updateStorageUtil(response.jsonBody); + if (!isNewVersion) { + await LicenseService.setupLicense(DatabaseStorage.database); + return false; + } return await LicenseService.fetchLicenses(); } } catch (e, s) { @@ -293,19 +298,20 @@ class LocalizationService { } } - static Future _updateStorageUtil(Map jsonBody) async { + static Future _updateStorageUtil(Map jsonBody) async { + await StorageHelper().s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp']); await StorageHelper() - .s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp'] ? 'true' : 'false'); - await StorageHelper().s(KeychainStorageKey.provisional.value, - jsonBody['provisional'] != null && jsonBody['provisional'] ? 'true' : 'false'); - await StorageHelper() - .s(KeychainStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet'] ? 'true' : 'false'); + .s(KeychainStorageKey.provisional.value, jsonBody['provisional'] != null && jsonBody['provisional']); + await StorageHelper().s(KeychainStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet']); await StorageHelper().s( KeychainStorageKey.petAmount.value, jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString()); await StorageHelper().s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); + await StorageHelper() + .s(KeychainStorageKey.isNewVersion.value, jsonBody['newVersion'] != null && jsonBody['newVersion']); + return jsonBody['newVersion'] != null && jsonBody['newVersion']; } static bool _isActive(List locals) { From 0a22f736da8d7719b531b85b5e7cc7361f1533ca Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 18 Nov 2024 10:58:12 -0300 Subject: [PATCH 09/75] WIP --- lib/backend/api_requests/api_calls.dart | 21 +++++++++++-------- .../menu_component/menu_component_model.dart | 16 +++++++------- .../people_on_the_property_page_model.dart | 4 ++-- lib/pages/visits_on_the_property/model.dart | 4 ++-- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index d7303aa6..fcef9a98 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -58,14 +58,16 @@ class PhpGroup { static GetVehiclesByProperty getVehiclesByProperty = GetVehiclesByProperty(); static GetResidentsByProperty getResidentsByProperty = GetResidentsByProperty(); static GetOpenedVisits getOpenedVisits = GetOpenedVisits(); + static TestCall testCall = TestCall(); + static GetLicense getLicense = GetLicense(); } class GetOpenedVisits { Future call(final String page) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getOpenedVisits'; const String pageSize = '10'; return ApiManager.instance.makeApiCall( @@ -95,9 +97,9 @@ class GetOpenedVisits { class GetResidentsByProperty { Future call(final String page) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; + final String cliID = await StorageHelper().g(KeychainStorageKey.clientUUID.value) ?? ''; const String atividade = 'getResidentsByProperty'; const String pageSize = '10'; return ApiManager.instance.makeApiCall( @@ -126,9 +128,9 @@ class GetResidentsByProperty { class GetVehiclesByProperty { Future call(final String page) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - final String userUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) ?? ''; - final String cliID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVehiclesByProperty'; const String pageSize = '10'; return ApiManager.instance.makeApiCall( @@ -152,6 +154,7 @@ class GetVehiclesByProperty { alwaysAllowBody: false, ); } + static GetLicense getLicense = GetLicense(); static TestCall testCall = TestCall(); } 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 d0854a97..4364203d 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -74,7 +74,7 @@ class MenuComponentModel extends FlutterFlowModel { if (options.contains(MenuOption.WorkersOnTheProperty)) addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', 'Agendar Prestadores', () async { - if (await StorageHelper().get(SQLiteStorageKey.provisional.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true') await open(context, '/provisionalSchedule'); else DialogUnavailable.unavailableFeature(context); @@ -82,7 +82,7 @@ class MenuComponentModel extends FlutterFlowModel { }); if (options.contains(MenuOption.DeliverySchedule)) addMenuEntry(Icons.sports_motorsports_outlined, 'Schedule Deliveries', 'Agendar Entregas', () async { - if (await StorageHelper().get(SQLiteStorageKey.provisional.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true') await open(context, '/deliverySchedule'); else DialogUnavailable.unavailableFeature(context); @@ -90,7 +90,7 @@ class MenuComponentModel extends FlutterFlowModel { }); if (options.contains(MenuOption.FastPassSchedule)) addMenuEntry(Icons.attach_email_outlined, 'Invite Visitor', 'Convidar Visitante', () async { - if (await StorageHelper().get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') await open(context, '/fastPassPage'); else DialogUnavailable.unavailableFeature(context); @@ -103,7 +103,7 @@ class MenuComponentModel extends FlutterFlowModel { }); if (options.contains(MenuOption.PackagesOnTheProperty)) addMenuEntry(Icons.inventory_2_outlined, 'Orders', 'Encomendas', () async { - if (await StorageHelper().get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') await open(context, '/packageOrder'); else DialogUnavailable.unavailableFeature(context); @@ -111,7 +111,7 @@ class MenuComponentModel extends FlutterFlowModel { }); if (options.contains(MenuOption.ReservationsOnTheLocal)) addMenuEntry(Icons.event_available, 'Reservations', 'Reservas', () async { - if (await StorageHelper().get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') await open(context, '/reservation'); else DialogUnavailable.unavailableFeature(context); @@ -129,7 +129,7 @@ class MenuComponentModel extends FlutterFlowModel { }); if (options.contains(MenuOption.PetsOnTheProperty)) addMenuEntry(Icons.pets, 'Pets', 'Pets', () async { - if (await StorageHelper().get(SQLiteStorageKey.pets.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.pets.value) == 'true') await open(context, '/petsOnThePropertyPage'); else DialogUnavailable.unavailableFeature(context); @@ -137,7 +137,7 @@ class MenuComponentModel extends FlutterFlowModel { }); if (options.contains(MenuOption.PetsRegister)) addMenuEntry(Icons.pets, 'Pets Register', 'Cadastrar Pet', () async { - if (await StorageHelper().get(SQLiteStorageKey.pets.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.pets.value) == 'true') await open(context, '/petsPage'); else DialogUnavailable.unavailableFeature(context); @@ -176,7 +176,7 @@ class MenuComponentModel extends FlutterFlowModel { if (options.contains(MenuOption.AboutProperty)) addMenuEntry(Icons.home, 'About Property', 'Sobre a Propriedade', () async { - if (await StorageHelper().get(SQLiteStorageKey.whatsapp.value, Storage.SQLiteStorage) == 'true') + if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') await open(context, '/aboutProperty'); else DialogUnavailable.unavailableFeature(context); diff --git a/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart b/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart index 6e7114f8..d99be82b 100644 --- a/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart +++ b/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart @@ -18,8 +18,8 @@ class PeopleOnThePropertyPageModel extends FlutterFlowModel { void dispose() {} Future initAsync() async { - devUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) ?? ''; - cliUUID = (await StorageHelper().get(SQLiteStorageKey.clientUUID.value, Storage.SQLiteStorage)) ?? ''; + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; onRefresh?.call(); } From e59aa9f9c4ec5c68773a85018f88b4b468c51de3 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 18 Nov 2024 14:46:20 -0300 Subject: [PATCH 10/75] WIP --- integration_test/app_test.dart | 4 +- lib/backend/api_requests/api_calls.dart | 4 +- .../firebase_messaging_service.dart | 4 +- .../notifications/notification_service.dart | 4 +- .../order_filter_modal_widget.dart | 2 +- ..._arrow_linked_locals_component_widget.dart | 4 +- .../local_profile_component_model.dart | 4 +- .../local_profile_component_widget.dart | 4 +- .../menu_component/menu_component_model.dart | 4 +- .../schedule_visit_detail_model.dart | 5 +- ...p_arrow_linked_locals_component_model.dart | 5 +- ...cation_modal_template_component_model.dart | 5 +- .../change_pass_widget.dart | 5 +- ...item_details_template_component_model.dart | 4 +- .../provisional_schedule_template_model.dart | 5 +- ...siter_vistor_template_component_model.dart | 4 +- .../sign_up_template_component_widget.dart | 4 +- .../view_visit_detail_model.dart | 5 +- ...search_modal_template_component_model.dart | 5 +- lib/flutter_flow/nav/nav.dart | 4 +- lib/main.dart | 4 +- .../acess_history_page_model.dart | 5 +- .../fast_pass_page/fast_pass_page_widget.dart | 14 +- .../forgot_password_screen.dart | 2 +- lib/pages/home_page/home_page_model.dart | 5 +- lib/pages/home_page/home_page_widget.dart | 2 +- .../liberation_history_model.dart | 5 +- .../message_history_page_model.dart | 4 +- .../package_order_page.dart | 4 +- .../people_on_the_property_page_model.dart | 5 +- .../pets_history_screen.dart | 4 +- lib/pages/pets_page/pets_page_model.dart | 4 +- .../preferences_settings_model.dart | 4 +- .../qr_code_page/qr_code_page_model.dart | 4 +- .../qr_code_page/qr_code_page_widget.dart | 4 +- .../reception_page/reception_page_model.dart | 4 +- .../reception_page/reception_page_widget.dart | 2 +- .../reservation_page_widget.dart | 14 +- .../schedule_complete_visit_page_model.dart | 5 +- .../visit_history_page_widget.dart | 4 +- .../sign_in_page/sign_in_page_widget.dart | 2 +- .../sign_up_page/sign_up_page_widget.dart | 2 +- lib/pages/visits_on_the_property/model.dart | 4 +- .../welcome_page/welcome_page_widget.dart | 4 +- .../{ => database}/database_helper.dart | 15 +- .../helpers/license/license_helper.dart | 185 ++++++++++++++++++ lib/shared/helpers/license_helper.dart | 80 -------- .../helpers/{ => storage}/base_storage.dart | 110 ----------- .../{ => storage}/keychain_storage.dart | 10 +- .../helpers/{ => storage}/secure_storage.dart | 2 +- .../shared_preferences_storage.dart | 2 +- .../helpers/{ => storage}/storage_helper.dart | 15 +- .../authentication_service.dart | 5 +- .../services/license/license_service.dart | 13 +- .../localization/localization_service.dart | 7 +- lib/shared/utils/share_util.dart | 4 +- 56 files changed, 325 insertions(+), 319 deletions(-) rename lib/shared/helpers/{ => database}/database_helper.dart (78%) create mode 100644 lib/shared/helpers/license/license_helper.dart delete mode 100644 lib/shared/helpers/license_helper.dart rename lib/shared/helpers/{ => storage}/base_storage.dart (54%) rename lib/shared/helpers/{ => storage}/keychain_storage.dart (84%) rename lib/shared/helpers/{ => storage}/secure_storage.dart (92%) rename lib/shared/helpers/{ => storage}/shared_preferences_storage.dart (92%) rename lib/shared/helpers/{ => storage}/storage_helper.dart (81%) diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 8706e9a0..fd6b3520 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -3,8 +3,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:hub/flutter_flow/random_data_util.dart'; import 'package:hub/main.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:integration_test/integration_test.dart'; late WidgetTester widget; diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index fcef9a98..96038903 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -4,8 +4,8 @@ import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:hub/backend/notifications/firebase_messaging_service.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/validator_util.dart'; diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index 7dc5fd4f..390a2036 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -2,8 +2,8 @@ import 'dart:developer'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'notification_service.dart'; diff --git a/lib/backend/notifications/notification_service.dart b/lib/backend/notifications/notification_service.dart index e6512034..db0a7c0f 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -8,8 +8,8 @@ import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; Future onMessageReceived(Map payload, String? extra, String? handleClick) async { 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 46f268bf..4c74c366 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,7 +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/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; // ignore: unused_import import 'package:hub/shared/utils/limited_text_size.dart'; 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 8b7c9df2..8d5da9a3 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -3,8 +3,8 @@ import 'package:hub/components/organism_components/bottom_arrow_linked_locals_co import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; import 'package:hub/shared/utils/log_util.dart'; 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 bccb05c5..300dae93 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,5 +1,5 @@ -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'local_profile_component_widget.dart' show LocalProfileComponentWidget; 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 30214c33..144f440b 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 @@ -3,8 +3,8 @@ import 'dart:developer'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import '/flutter_flow/custom_functions.dart' as functions; import '/flutter_flow/flutter_flow_theme.dart'; 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 4364203d..cbbed6e1 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -10,8 +10,8 @@ import 'package:hub/components/organism_components/menu_staggered_view_component import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:material_symbols_icons/symbols.dart'; 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 a8ae03e4..247ec513 100644 --- a/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart +++ b/lib/components/organism_components/schedule_visit_detail/schedule_visit_detail_model.dart @@ -2,8 +2,9 @@ import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + // ignore: unused_import import 'package:intl/intl.dart'; 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 211ab6ce..67f2947d 100644 --- a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart +++ b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:hub/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel { late final String devUUID; 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 5e38346f..d28b326c 100644 --- a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart +++ b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; 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 bb0d3126..d79132e3 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,8 +3,9 @@ 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/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; diff --git a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart index b9865a35..b7d768b8 100644 --- a/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart +++ b/lib/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_model.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:hub/components/templates_components/liberation_history_item_details_template_component/liberation_history_item_details_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; class LiberationHistoryItemDetailsTemplateComponentModel extends FlutterFlowModel { 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 f7366c79..7a214573 100644 --- a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart +++ b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart @@ -4,8 +4,9 @@ import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/templates_components/provisional_schedule_template/provisional_shcedule_template_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class ScheduleProvisionalVisitPageModel extends FlutterFlowModel { String cliUUID = ''; 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 494337f1..f7ff104f 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_model.dart @@ -1,8 +1,8 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/backend/api_requests/api_calls.dart'; diff --git a/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart b/lib/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart index 332234e6..fa7df0ce 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,9 +4,9 @@ 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/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:hub/shared/utils/validator_util.dart'; import '/flutter_flow/flutter_flow_animations.dart'; 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 c9153f31..2a2aa5e6 100644 --- a/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart +++ b/lib/components/templates_components/view_visit_detail/view_visit_detail_model.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart index aee5f3da..ff8624ea 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_model.dart @@ -2,8 +2,9 @@ import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel { late final String devUUID; diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index e82d3691..8eb651c3 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -29,8 +29,8 @@ import 'package:hub/pages/sign_up_page/sign_up_page_widget.dart'; import 'package:hub/pages/vehicles_on_the_property/vehicles_on_the_property.dart'; import 'package:hub/pages/visits_on_the_property/visits_on_the_property_screen.dart'; import 'package:hub/pages/welcome_page/welcome_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:provider/provider.dart'; export 'package:go_router/go_router.dart'; diff --git a/lib/main.dart b/lib/main.dart index 55765c25..73b3123b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,8 +18,8 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/forgot_password_page/forgot_password_screen.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:responsive_framework/responsive_framework.dart'; 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 046011df..3bd7ff88 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -4,8 +4,9 @@ import 'package:hub/components/molecular_components/message_opt_modal/opt_modal_ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/acess_history_page/acess_history_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class AcessHistoryPageModel extends FlutterFlowModel { late final String devUUID; 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 4cb346c3..8df206f9 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -7,8 +7,8 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart' as hub; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -25,11 +25,11 @@ class _FastPassPageWidgetState extends State { late InAppWebViewController _controllerIOS; Future> initVariables() async { - final email = (await StorageHelper().g(hub.SecureStorageKey.email.value)) ?? ''; - final name = (await StorageHelper().g(hub.KeychainStorageKey.userName.value)) ?? ''; - final devUUID = (await StorageHelper().g(hub.KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(hub.KeychainStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(hub.KeychainStorageKey.clientUUID.value)) ?? ''; + final email = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; + final name = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; final freUserData = diff --git a/lib/pages/forgot_password_page/forgot_password_screen.dart b/lib/pages/forgot_password_page/forgot_password_screen.dart index 81aa567e..bbe26afa 100644 --- a/lib/pages/forgot_password_page/forgot_password_screen.dart +++ b/lib/pages/forgot_password_page/forgot_password_screen.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import '../../flutter_flow/flutter_flow_animations.dart'; import '../../flutter_flow/flutter_flow_icon_button.dart'; diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index 17fc9a07..db3eb7e1 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -6,8 +6,9 @@ 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/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class HomePageModel extends FlutterFlowModel { HomePageModel({required this.safeSetState}); diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index ca2ff3ce..02deb34a 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -7,7 +7,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/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart'; class HomePageWidget extends StatefulWidget { diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index c7b7ea6e..9b107572 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -3,8 +3,9 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class LiberationHistoryModel extends FlutterFlowModel { late final String devUUID; 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 b51112df..7db66d8a 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -3,8 +3,8 @@ import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/message_history_page/message_history_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; class MessageHistoryPageModel extends FlutterFlowModel { late final String devUUID; diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index 80583700..c3d352f4 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -9,8 +9,8 @@ import 'package:hub/components/templates_components/details_component/details_co import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; import 'package:hub/shared/utils/log_util.dart'; diff --git a/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart b/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart index d99be82b..d706d938 100644 --- a/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart +++ b/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/people_on_the_property_page/people_on_the_property_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class PeopleOnThePropertyPageModel extends FlutterFlowModel { PeopleOnThePropertyPageModel({this.onRefresh}); diff --git a/lib/pages/pets_on_the_property_page/pets_history_screen.dart b/lib/pages/pets_on_the_property_page/pets_history_screen.dart index a7ee40c4..50c00460 100644 --- a/lib/pages/pets_on_the_property_page/pets_history_screen.dart +++ b/lib/pages/pets_on_the_property_page/pets_history_screen.dart @@ -8,8 +8,8 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/pets_page/pets_page_model.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; import 'package:hub/shared/utils/log_util.dart'; diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index ec3d6ccc..4d4fd096 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -12,8 +12,8 @@ import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/form_field_controller.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/pets_page/pets_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/image_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index f4fadd91..2339d95a 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -5,8 +5,8 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:share_plus/share_plus.dart'; diff --git a/lib/pages/qr_code_page/qr_code_page_model.dart b/lib/pages/qr_code_page/qr_code_page_model.dart index 6bd4c12b..002192ad 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -4,8 +4,8 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/qr_code_page/qr_code_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:qr_flutter/qr_flutter.dart'; class QrCodePageModel extends FlutterFlowModel { diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index 23c8e894..b2005f96 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -17,8 +17,8 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/qr_code_page/qr_code_page_model.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/biometric_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index bb4c4727..e0afe000 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 77d4c65f..dde3e076 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -10,7 +10,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/pages/reception_page/reception_page_model.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index 828f57b4..37b0fe1a 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -5,8 +5,8 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart' as hub; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/webview_util.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:webview_flutter/webview_flutter.dart'; @@ -22,11 +22,11 @@ class _ReservationPageWidgetState extends State { late WebViewController _controllerAll; Future> initVariables() async { - final email = (await StorageHelper().g(hub.SecureStorageKey.email.value)) ?? ''; - final name = (await StorageHelper().g(hub.KeychainStorageKey.userName.value)) ?? ''; - final devUUID = (await StorageHelper().g(hub.KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(hub.KeychainStorageKey.userUUID.value)) ?? ''; - final clientId = (await StorageHelper().g(hub.KeychainStorageKey.clientUUID.value)) ?? ''; + final email = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; + final name = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final clientId = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; final freUserData = 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 00d863d2..c9d070c9 100644 --- a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart +++ b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart @@ -8,8 +8,9 @@ import 'package:hub/flutter_flow/form_field_controller.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + import 'package:hub/shared/mixins/status_mixin.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; import 'package:share_plus/share_plus.dart'; 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 ccc84b83..c20c8927 100644 --- a/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/visit_history_page_widget.dart @@ -5,8 +5,8 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/mixins/status_mixin.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; diff --git a/lib/pages/sign_in_page/sign_in_page_widget.dart b/lib/pages/sign_in_page/sign_in_page_widget.dart index 471bbee2..c3d22f90 100644 --- a/lib/pages/sign_in_page/sign_in_page_widget.dart +++ b/lib/pages/sign_in_page/sign_in_page_widget.dart @@ -1,4 +1,4 @@ -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/mixins/switcher_mixin.dart'; import '/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart'; diff --git a/lib/pages/sign_up_page/sign_up_page_widget.dart b/lib/pages/sign_up_page/sign_up_page_widget.dart index 00d95f56..86425e6e 100644 --- a/lib/pages/sign_up_page/sign_up_page_widget.dart +++ b/lib/pages/sign_up_page/sign_up_page_widget.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/mixins/switcher_mixin.dart'; import '/components/templates_components/sign_up_template_component/sign_up_template_component_widget.dart'; diff --git a/lib/pages/visits_on_the_property/model.dart b/lib/pages/visits_on_the_property/model.dart index 2ec95700..c880c726 100644 --- a/lib/pages/visits_on_the_property/model.dart +++ b/lib/pages/visits_on_the_property/model.dart @@ -4,8 +4,8 @@ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/pages/vehicles_on_the_property/vehicles_on_the_property.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; class VisitsModel extends FlutterFlowModel { static VisitsModel? _instance; diff --git a/lib/pages/welcome_page/welcome_page_widget.dart b/lib/pages/welcome_page/welcome_page_widget.dart index 96cc2ec9..6effcb76 100644 --- a/lib/pages/welcome_page/welcome_page_widget.dart +++ b/lib/pages/welcome_page/welcome_page_widget.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/mixins/switcher_mixin.dart'; import '/components/templates_components/welcome_template_component/welcome_template_component_widget.dart'; diff --git a/lib/shared/helpers/database_helper.dart b/lib/shared/helpers/database/database_helper.dart similarity index 78% rename from lib/shared/helpers/database_helper.dart rename to lib/shared/helpers/database/database_helper.dart index 84b33c35..8163308b 100644 --- a/lib/shared/helpers/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -1,5 +1,5 @@ -import 'package:hub/shared/helpers/keychain_storage.dart'; -import 'package:hub/shared/helpers/license_helper.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; +import 'package:hub/shared/helpers/storage/keychain_storage.dart'; import 'package:hub/shared/services/license/license_service.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart'; @@ -22,7 +22,7 @@ class DatabaseStorage { } Future init() async { - if (_database != null && _database!.isOpen) return; + if (_database != null) return; _database = await openDatabase( join(await getDatabasesPath(), _dbName), version: _dbVersion, @@ -30,23 +30,22 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); + await LicenseService.setupLicense(database); } Future _onCreate(Database database, int version) async { log('Creating database...'); - await database.execute(KeychainDelegate.createTableQuery); - await database.execute(LicenseDelegate.createTableQuery); - await LicenseService.setupLicense(database); + await database.execute(KeychainHelper.createTableQuery); + await database.execute(LicenseHelper.createTableQuery); } Future _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2) { - await database.execute(LicenseDelegate.createTableQuery); + await database.execute(LicenseHelper.createTableQuery); await LicenseService.setupLicense(database); } } Future _onDowngrade(Database database, int oldVersion, int newVersion) async {} - } diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart new file mode 100644 index 00000000..52ee305a --- /dev/null +++ b/lib/shared/helpers/license/license_helper.dart @@ -0,0 +1,185 @@ +import 'dart:developer'; + +import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:sqflite/sqflite.dart'; + +enum InactiveLicenseKey { + residents, + vehicles, + openedVisits, +} + +enum ActiveLicenseKey { + messages, + liberations, + reservations, + access, + orders, + completeSchedule, + providerSchedule, + deliverySchedule, + fastPass, +} + +extension InactiveLicenseKeyExtension on InactiveLicenseKey { + String get value { + switch (this) { + case InactiveLicenseKey.residents: + return 'FRE-HUB-RESIDENTS'; + case InactiveLicenseKey.vehicles: + return 'FRE-HUB-VEHICLES'; + case InactiveLicenseKey.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + default: + return ''; + } + } +} + +extension ActiveLicenseKeyExtension on ActiveLicenseKey { + String get value { + switch (this) { + case ActiveLicenseKey.messages: + return 'FRE-HUB-MESSAGES'; + case ActiveLicenseKey.liberations: + return 'FRE-HUB-LIBERATIONS'; + case ActiveLicenseKey.reservations: + return 'FRE-HUB-RESERVATIONS'; + case ActiveLicenseKey.access: + return 'FRE-HUB-ACCESS'; + case ActiveLicenseKey.orders: + return 'FRE-HUB-ORDERS'; + case ActiveLicenseKey.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case ActiveLicenseKey.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case ActiveLicenseKey.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case ActiveLicenseKey.fastPass: + return 'FRE-HUB-FASTPASS'; + default: + return ''; + } + } +} + +enum LicenseStorageKey { + messages, + liberations, + reservations, + access, + openedVisits, + vehicles, + residents, + pets, + orders, + completeSchedule, + providerSchedule, + deliverySchedule, + fastPass, +} + +extension LicenseKeyExtension on LicenseStorageKey { + String get value { + switch (this) { + case LicenseStorageKey.messages: + return 'FRE-HUB-MESSAGES'; + case LicenseStorageKey.liberations: + return 'FRE-HUB-LIBERATIONS'; + case LicenseStorageKey.reservations: + return 'FRE-HUB-RESERVATIONS'; + case LicenseStorageKey.access: + return 'FRE-HUB-ACCESS'; + case LicenseStorageKey.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case LicenseStorageKey.vehicles: + return 'FRE-HUB-VEHICLES'; + case LicenseStorageKey.residents: + return 'FRE-HUB-RESIDENTS'; + case LicenseStorageKey.pets: + return 'FRE-HUB-PETS'; + case LicenseStorageKey.orders: + return 'FRE-HUB-ORDERS'; + case LicenseStorageKey.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case LicenseStorageKey.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case LicenseStorageKey.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case LicenseStorageKey.fastPass: + return 'FRE-HUB-FASTPASS'; + default: + return ''; + } + } +} + +class LicenseHelper { + LicenseHelper._(); + + static final LicenseHelper instance = LicenseHelper._(); + + static const String tableLicense = 'license'; + + static String get createTableQuery => ''' + CREATE TABLE $tableLicense ( + key TEXT UNIQUE, + display TEXT, + expirationDate TEXT, + startDate TEXT, + quantity TEXT + ); + '''; + + Future init() async { + await DatabaseStorage.instance.init(); + } + + static Future insertLicenseFoo(final List key, final String display) async { + for (var element in key) { + DatabaseStorage.database.insert( + tableLicense, + { + 'key': element, + 'display': display, + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }, + conflictAlgorithm: ConflictAlgorithm.ignore, + ); + } + } + + Future g(String key) async { + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); + if (response.isEmpty) { + return null; + } + return response.first['value'].toString(); + } + + Future s(String key, T value) async { + log('setLicense($key, $value)'); + value as Map; + + await DatabaseStorage.database.insert( + tableLicense, + { + 'key': key, + 'display': value['display'], + 'expirationDate': value['expirationDate'], + 'startDate': value['startDate'], + 'quantity': value['quantity'], + }, + conflictAlgorithm: ConflictAlgorithm.replace); + } + + Future d(String key) async { + await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); + } + + Future c() async { + await DatabaseStorage.database.delete(tableLicense); + } +} diff --git a/lib/shared/helpers/license_helper.dart b/lib/shared/helpers/license_helper.dart deleted file mode 100644 index 17896651..00000000 --- a/lib/shared/helpers/license_helper.dart +++ /dev/null @@ -1,80 +0,0 @@ -import 'dart:developer'; - -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_helper.dart'; -import 'package:sqflite/sqflite.dart'; - -class LicenseDelegate implements BaseStorage { - LicenseDelegate._(); - - static final LicenseDelegate instance = LicenseDelegate._(); - - static const String tableLicense = 'license'; - - static String get createTableQuery => ''' - CREATE TABLE $tableLicense ( - key TEXT UNIQUE, - display TEXT, - expirationDate TEXT, - startDate TEXT, - quantity TEXT - ); - '''; - - @override - Future init() async { - await DatabaseStorage.instance.init(); - } - - @override - Future get(String key) async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); - if (response.isEmpty) { - return null; - } - return response.first['value'].toString(); - } - - @override - Future set(String key, T value) async { - log('setLicense($key, $value)'); - value as Map; - - await DatabaseStorage.database.insert( - tableLicense, - { - 'key': key, - 'display': value['display'], - 'expirationDate': value['expirationDate'], - 'startDate': value['startDate'], - 'quantity': value['quantity'], - }, - conflictAlgorithm: ConflictAlgorithm.replace); - } - - static Future insertLicenseFoo(final List key, final String display) async { - for (var element in key) { - DatabaseStorage.database.insert( - LicenseDelegate.tableLicense, - { - 'key': element, - 'display': display, - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }, - conflictAlgorithm: ConflictAlgorithm.ignore, - ); - } - } - - @override - Future delete(String key) async { - await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); - } - - @override - Future clearAll() async { - await DatabaseStorage.database.delete(tableLicense); - } -} diff --git a/lib/shared/helpers/base_storage.dart b/lib/shared/helpers/storage/base_storage.dart similarity index 54% rename from lib/shared/helpers/base_storage.dart rename to lib/shared/helpers/storage/base_storage.dart index 76efbc99..972734bf 100644 --- a/lib/shared/helpers/base_storage.dart +++ b/lib/shared/helpers/storage/base_storage.dart @@ -145,113 +145,3 @@ extension KeychainStorageKeyExtension on KeychainStorageKey { } } -enum InactiveLicenseKey { - residents, - vehicles, - openedVisits, -} - -enum ActiveLicenseKey { - messages, - liberations, - reservations, - access, - orders, - completeSchedule, - providerSchedule, - deliverySchedule, - fastPass, -} - -extension InactiveLicenseKeyExtension on InactiveLicenseKey { - String get value { - switch (this) { - case InactiveLicenseKey.residents: - return 'FRE-HUB-RESIDENTS'; - case InactiveLicenseKey.vehicles: - return 'FRE-HUB-VEHICLES'; - case InactiveLicenseKey.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - default: - return ''; - } - } -} - -extension ActiveLicenseKeyExtension on ActiveLicenseKey { - String get value { - switch (this) { - case ActiveLicenseKey.messages: - return 'FRE-HUB-MESSAGES'; - case ActiveLicenseKey.liberations: - return 'FRE-HUB-LIBERATIONS'; - case ActiveLicenseKey.reservations: - return 'FRE-HUB-RESERVATIONS'; - case ActiveLicenseKey.access: - return 'FRE-HUB-ACCESS'; - case ActiveLicenseKey.orders: - return 'FRE-HUB-ORDERS'; - case ActiveLicenseKey.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case ActiveLicenseKey.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case ActiveLicenseKey.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ActiveLicenseKey.fastPass: - return 'FRE-HUB-FASTPASS'; - default: - return ''; - } - } -} - -enum LicenseStorageKey { - messages, - liberations, - reservations, - access, - openedVisits, - vehicles, - residents, - pets, - orders, - completeSchedule, - providerSchedule, - deliverySchedule, - fastPass, -} - -extension LicenseKeyExtension on LicenseStorageKey { - String get value { - switch (this) { - case LicenseStorageKey.messages: - return 'FRE-HUB-MESSAGES'; - case LicenseStorageKey.liberations: - return 'FRE-HUB-LIBERATIONS'; - case LicenseStorageKey.reservations: - return 'FRE-HUB-RESERVATIONS'; - case LicenseStorageKey.access: - return 'FRE-HUB-ACCESS'; - case LicenseStorageKey.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case LicenseStorageKey.vehicles: - return 'FRE-HUB-VEHICLES'; - case LicenseStorageKey.residents: - return 'FRE-HUB-RESIDENTS'; - case LicenseStorageKey.pets: - return 'FRE-HUB-PETS'; - case LicenseStorageKey.orders: - return 'FRE-HUB-ORDERS'; - case LicenseStorageKey.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case LicenseStorageKey.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case LicenseStorageKey.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case LicenseStorageKey.fastPass: - return 'FRE-HUB-FASTPASS'; - default: - return ''; - } - } -} diff --git a/lib/shared/helpers/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart similarity index 84% rename from lib/shared/helpers/keychain_storage.dart rename to lib/shared/helpers/storage/keychain_storage.dart index 8be43ccc..c14aa6b5 100644 --- a/lib/shared/helpers/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -1,11 +1,11 @@ -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_helper.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:sqflite/sqflite.dart'; -class KeychainDelegate implements BaseStorage { - KeychainDelegate._(); +class KeychainHelper implements BaseStorage { + KeychainHelper._(); - static final KeychainDelegate instance = KeychainDelegate._(); + static final KeychainHelper instance = KeychainHelper._(); static const String tableKeychain = 'keychain'; diff --git a/lib/shared/helpers/secure_storage.dart b/lib/shared/helpers/storage/secure_storage.dart similarity index 92% rename from lib/shared/helpers/secure_storage.dart rename to lib/shared/helpers/storage/secure_storage.dart index b579c543..1d40ee71 100644 --- a/lib/shared/helpers/secure_storage.dart +++ b/lib/shared/helpers/storage/secure_storage.dart @@ -1,5 +1,5 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; class SecureStorage implements BaseStorage { SecureStorage._(); diff --git a/lib/shared/helpers/shared_preferences_storage.dart b/lib/shared/helpers/storage/shared_preferences_storage.dart similarity index 92% rename from lib/shared/helpers/shared_preferences_storage.dart rename to lib/shared/helpers/storage/shared_preferences_storage.dart index 9a9b4fd1..3cc38a6e 100644 --- a/lib/shared/helpers/shared_preferences_storage.dart +++ b/lib/shared/helpers/storage/shared_preferences_storage.dart @@ -1,4 +1,4 @@ -import 'package:hub/shared/helpers/base_storage.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:shared_preferences/shared_preferences.dart'; class SharedPreferencesStorage implements BaseStorage { diff --git a/lib/shared/helpers/storage_helper.dart b/lib/shared/helpers/storage/storage_helper.dart similarity index 81% rename from lib/shared/helpers/storage_helper.dart rename to lib/shared/helpers/storage/storage_helper.dart index 4c5418d3..3e97ddf5 100644 --- a/lib/shared/helpers/storage_helper.dart +++ b/lib/shared/helpers/storage/storage_helper.dart @@ -1,9 +1,8 @@ import 'package:flutter/cupertino.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_helper.dart'; -import 'package:hub/shared/helpers/keychain_storage.dart'; -import 'package:hub/shared/helpers/secure_storage.dart'; -import 'package:hub/shared/helpers/shared_preferences_storage.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/keychain_storage.dart'; +import 'package:hub/shared/helpers/storage/secure_storage.dart'; +import 'package:hub/shared/helpers/storage/shared_preferences_storage.dart'; class StorageHelper { static final StorageHelper _instance = StorageHelper._internal(); @@ -21,7 +20,7 @@ class StorageHelper { Future init() async { await SecureStorage.instance.init(); await SharedPreferencesStorage.instance.init(); - await DatabaseStorage.instance.init(); + await KeychainHelper.instance.init(); String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value); @@ -38,7 +37,7 @@ class StorageHelper { case Storage.sharedPreferences: return SharedPreferencesStorage.instance; default: - return KeychainDelegate.instance; + return KeychainHelper.instance; } } @@ -48,7 +47,7 @@ class StorageHelper { } else if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) { return SharedPreferencesStorage.instance; } else { - return KeychainDelegate.instance; + return KeychainHelper.instance; } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 040087d2..db52f8bf 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + import 'package:hub/shared/utils/snackbar_util.dart'; import '../../../backend/api_requests/api_calls.dart'; diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 215aa663..bea7bc4a 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -3,11 +3,12 @@ import 'dart:developer'; import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_helper.dart'; -import 'package:hub/shared/helpers/license_helper.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; + +import 'package:hub/shared/helpers/license/license_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; import 'package:sqflite/sqflite.dart'; class LicenseService { @@ -16,8 +17,8 @@ class LicenseService { LicenseService._internal(); static Future setupLicense(Database database) async { - await LicenseDelegate.insertLicenseFoo(InactiveLicenseKey.values.map((e) => e.value).toList(), 'INVISIVEL'); - await LicenseDelegate.insertLicenseFoo(ActiveLicenseKey.values.map((e) => e.value).toList(), 'VISIVEL'); + await LicenseHelper.insertLicenseFoo(InactiveLicenseKey.values.map((e) => e.value).toList(), 'INVISIVEL'); + await LicenseHelper.insertLicenseFoo(ActiveLicenseKey.values.map((e) => e.value).toList(), 'VISIVEL'); } static Future initLicenseService() async { diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 08501be0..8a168906 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -3,12 +3,11 @@ import 'dart:developer'; import 'package:flutter/material.dart'; -import 'package:http/src/response.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/database_helper.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/license/license_service.dart'; import 'package:hub/shared/utils/dialog_util.dart'; diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index 67a4e183..511e143a 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -1,5 +1,5 @@ -import 'package:hub/shared/helpers/base_storage.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:share_plus/share_plus.dart'; class ShareUtil { From e83633430b18ac231282f3f9c4d204659808af0c Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 18 Nov 2024 16:29:53 -0300 Subject: [PATCH 11/75] WIP --- .../menu_component/menu_component_model.dart | 144 +++--------------- .../menu_component/menu_component_widget.dart | 5 +- .../helpers/license/license_helper.dart | 68 +++++---- .../services/license/license_service.dart | 6 +- 4 files changed, 63 insertions(+), 160 deletions(-) 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 cbbed6e1..3aadf479 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/atomic_components/menu_button_item/menu_button_item_widget.dart'; @@ -10,6 +12,7 @@ import 'package:hub/components/organism_components/menu_staggered_view_component import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; @@ -22,7 +25,7 @@ class MenuComponentModel extends FlutterFlowModel { final MenuView style; final MenuItem item; final bool expandable; - final List menuOptions; + final List menuOptions; MenuComponentModel({required this.style, required this.item, required this.expandable, required this.menuOptions}); @@ -45,9 +48,9 @@ class MenuComponentModel extends FlutterFlowModel { menuStaggeredViewComponentModel.dispose(); } - List generateMenuEntries(BuildContext context, MenuItem item, List options) { + Future> generateMenuEntries(BuildContext context, MenuItem item, List options) async { List entries = []; - MenuEntry? addMenuEntry(IconData icon, String enText, String ptText, Function() action) { + Future addMenuEntry(IconData icon, String enText, String ptText, Function() action) async { entries.add( item == MenuItem.button ? MenuButtonWidget( @@ -72,126 +75,23 @@ class MenuComponentModel extends FlutterFlowModel { return null; } - if (options.contains(MenuOption.WorkersOnTheProperty)) - addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', 'Agendar Prestadores', () async { - if (await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true') - await open(context, '/provisionalSchedule'); - else + for (var opt in options) { + String? v = await LicenseHelper().g(opt.value); + log('Module: ${opt.value} - License: $v'); + switch (v) { + case 'VISIVEL': + addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', 'Agendar Prestadores', () async { + await open(context, '/provisionalSchedule'); + }); + break; + case 'INVISIVEL': DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.DeliverySchedule)) - addMenuEntry(Icons.sports_motorsports_outlined, 'Schedule Deliveries', 'Agendar Entregas', () async { - if (await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true') - await open(context, '/deliverySchedule'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.FastPassSchedule)) - addMenuEntry(Icons.attach_email_outlined, 'Invite Visitor', 'Convidar Visitante', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/fastPassPage'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.CompleteSchedule)) - addMenuEntry(Icons.event, 'Complete Schedule', 'Agenda Completa', () async { - await open(context, '/scheduleCompleteVisitPage'); - safeSetState; - }); - if (options.contains(MenuOption.PackagesOnTheProperty)) - addMenuEntry(Icons.inventory_2_outlined, 'Orders', 'Encomendas', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/packageOrder'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.ReservationsOnTheLocal)) - addMenuEntry(Icons.event_available, 'Reservations', 'Reservas', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/reservation'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.VisitorsRegister)) - addMenuEntry(Icons.person_add_alt_1_outlined, 'Register Visitor', 'Cadastrar Visitante', () async { - await open(context, '/registerVisitorPage'); - safeSetState; - }); - if (options.contains(MenuOption.QRCodeAccessInProperty)) - addMenuEntry(Icons.qr_code, 'QRCode Access', 'QRCode de Acesso', () async { - await open(context, '/qrCodePage'); - safeSetState; - }); - if (options.contains(MenuOption.PetsOnTheProperty)) - addMenuEntry(Icons.pets, 'Pets', 'Pets', () async { - if (await StorageHelper().g(KeychainStorageKey.pets.value) == 'true') - await open(context, '/petsOnThePropertyPage'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.PetsRegister)) - addMenuEntry(Icons.pets, 'Pets Register', 'Cadastrar Pet', () async { - if (await StorageHelper().g(KeychainStorageKey.pets.value) == 'true') - await open(context, '/petsPage'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.AccessOnTheProperty)) - addMenuEntry(Icons.transfer_within_a_station_outlined, 'Access History', 'Consultar Acessos', () async { - await open(context, '/acessHistoryPage'); - safeSetState; - }); - if (options.contains(MenuOption.ResidentsOnTheProperty)) - addMenuEntry(Icons.groups, 'Residents', 'Moradores', () async { - await open(context, '/peopleOnThePropertyPage'); - safeSetState; - }); - if (options.contains(MenuOption.LiberationsOnTheProperty)) - addMenuEntry(Icons.how_to_reg_outlined, 'Liberations History', 'Consultar Liberações', () async { - await open(context, '/liberationHistory'); - safeSetState; - }); - if (options.contains(MenuOption.MessagesOnTheProperty)) - addMenuEntry(Icons.chat_outlined, 'Message History', 'Consultar Mensagens', () async { - await open(context, '/messageHistoryPage'); - safeSetState; - }); - if (options.contains(MenuOption.VehiclesOnTheProperty)) - addMenuEntry(Symbols.directions_car, 'Vehicles', 'Veículos', () async { - await open(context, '/vehiclesOnThePropertyPage'); - safeSetState; - }); - if (options.contains(MenuOption.VisitsOnTheProperty)) - addMenuEntry(Symbols.perm_contact_calendar, 'Opened Visits', 'Visitas em Aberto', () async { - await open(context, '/visitsOnThePropertyPage'); - safeSetState; - }); - - if (options.contains(MenuOption.AboutProperty)) - addMenuEntry(Icons.home, 'About Property', 'Sobre a Propriedade', () async { - if (await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true') - await open(context, '/aboutProperty'); - else - DialogUnavailable.unavailableFeature(context); - safeSetState; - }); - if (options.contains(MenuOption.SettingsOnTheApp)) - addMenuEntry(Icons.settings, 'System Settings', 'Opções do Sistema', () async { - await open(context, '/preferencesSettings'); - safeSetState; - }); - if (options.contains(MenuOption.LogoutOnTheApp)) - addMenuEntry(Icons.logout, 'Logout', 'Sair', () async { - await out(context); - safeSetState; - }); + break; + default: + break; + } + safeSetState(); + } return entries; } diff --git a/lib/components/organism_components/menu_component/menu_component_widget.dart b/lib/components/organism_components/menu_component/menu_component_widget.dart index 795982cd..b6cb84ca 100644 --- a/lib/components/organism_components/menu_component/menu_component_widget.dart +++ b/lib/components/organism_components/menu_component/menu_component_widget.dart @@ -30,9 +30,10 @@ class _MenuComponentWidgetState extends State { } @override - void didChangeDependencies() { + void didChangeDependencies() async { super.didChangeDependencies(); - widget.model.menuEntries = widget.model.generateMenuEntries(context, widget.model.item, widget.model.menuOptions); + widget.model.menuEntries = + await widget.model.generateMenuEntries(context, widget.model.item, widget.model.menuOptions); } @override diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index 52ee305a..6ca74666 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -3,13 +3,13 @@ import 'dart:developer'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:sqflite/sqflite.dart'; -enum InactiveLicenseKey { +enum InactiveModuleKey { residents, vehicles, openedVisits, } -enum ActiveLicenseKey { +enum ActiveModuleKey { messages, liberations, reservations, @@ -21,14 +21,14 @@ enum ActiveLicenseKey { fastPass, } -extension InactiveLicenseKeyExtension on InactiveLicenseKey { +extension InactiveModuleKeyExtension on InactiveModuleKey { String get value { switch (this) { - case InactiveLicenseKey.residents: + case InactiveModuleKey.residents: return 'FRE-HUB-RESIDENTS'; - case InactiveLicenseKey.vehicles: + case InactiveModuleKey.vehicles: return 'FRE-HUB-VEHICLES'; - case InactiveLicenseKey.openedVisits: + case InactiveModuleKey.openedVisits: return 'FRE-HUB-OPENED-VISITS'; default: return ''; @@ -36,26 +36,26 @@ extension InactiveLicenseKeyExtension on InactiveLicenseKey { } } -extension ActiveLicenseKeyExtension on ActiveLicenseKey { +extension ActiveModuleKeyExtension on ActiveModuleKey { String get value { switch (this) { - case ActiveLicenseKey.messages: + case ActiveModuleKey.messages: return 'FRE-HUB-MESSAGES'; - case ActiveLicenseKey.liberations: + case ActiveModuleKey.liberations: return 'FRE-HUB-LIBERATIONS'; - case ActiveLicenseKey.reservations: + case ActiveModuleKey.reservations: return 'FRE-HUB-RESERVATIONS'; - case ActiveLicenseKey.access: + case ActiveModuleKey.access: return 'FRE-HUB-ACCESS'; - case ActiveLicenseKey.orders: + case ActiveModuleKey.orders: return 'FRE-HUB-ORDERS'; - case ActiveLicenseKey.completeSchedule: + case ActiveModuleKey.completeSchedule: return 'FRE-HUB-COMPLETE-SCHEDULE'; - case ActiveLicenseKey.providerSchedule: + case ActiveModuleKey.providerSchedule: return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case ActiveLicenseKey.deliverySchedule: + case ActiveModuleKey.deliverySchedule: return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ActiveLicenseKey.fastPass: + case ActiveModuleKey.fastPass: return 'FRE-HUB-FASTPASS'; default: return ''; @@ -63,7 +63,7 @@ extension ActiveLicenseKeyExtension on ActiveLicenseKey { } } -enum LicenseStorageKey { +enum Module { messages, liberations, reservations, @@ -79,34 +79,34 @@ enum LicenseStorageKey { fastPass, } -extension LicenseKeyExtension on LicenseStorageKey { +extension LicenseKeyExtension on Module { String get value { switch (this) { - case LicenseStorageKey.messages: + case Module.messages: return 'FRE-HUB-MESSAGES'; - case LicenseStorageKey.liberations: + case Module.liberations: return 'FRE-HUB-LIBERATIONS'; - case LicenseStorageKey.reservations: + case Module.reservations: return 'FRE-HUB-RESERVATIONS'; - case LicenseStorageKey.access: + case Module.access: return 'FRE-HUB-ACCESS'; - case LicenseStorageKey.openedVisits: + case Module.openedVisits: return 'FRE-HUB-OPENED-VISITS'; - case LicenseStorageKey.vehicles: + case Module.vehicles: return 'FRE-HUB-VEHICLES'; - case LicenseStorageKey.residents: + case Module.residents: return 'FRE-HUB-RESIDENTS'; - case LicenseStorageKey.pets: + case Module.pets: return 'FRE-HUB-PETS'; - case LicenseStorageKey.orders: + case Module.orders: return 'FRE-HUB-ORDERS'; - case LicenseStorageKey.completeSchedule: + case Module.completeSchedule: return 'FRE-HUB-COMPLETE-SCHEDULE'; - case LicenseStorageKey.providerSchedule: + case Module.providerSchedule: return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case LicenseStorageKey.deliverySchedule: + case Module.deliverySchedule: return 'FRE-HUB-AGE-PROV-DELIVERY'; - case LicenseStorageKey.fastPass: + case Module.fastPass: return 'FRE-HUB-FASTPASS'; default: return ''; @@ -115,9 +115,11 @@ extension LicenseKeyExtension on LicenseStorageKey { } class LicenseHelper { - LicenseHelper._(); + static final LicenseHelper _instance = LicenseHelper._internal(); - static final LicenseHelper instance = LicenseHelper._(); + factory LicenseHelper() => _instance; + + LicenseHelper._internal(); static const String tableLicense = 'license'; diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index bea7bc4a..b2ea7651 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -17,8 +17,8 @@ class LicenseService { LicenseService._internal(); static Future setupLicense(Database database) async { - await LicenseHelper.insertLicenseFoo(InactiveLicenseKey.values.map((e) => e.value).toList(), 'INVISIVEL'); - await LicenseHelper.insertLicenseFoo(ActiveLicenseKey.values.map((e) => e.value).toList(), 'VISIVEL'); + await LicenseHelper.insertLicenseFoo(InactiveModuleKey.values.map((e) => e.value).toList(), 'INVISIVEL'); + await LicenseHelper.insertLicenseFoo(ActiveModuleKey.values.map((e) => e.value).toList(), 'VISIVEL'); } static Future initLicenseService() async { @@ -74,7 +74,7 @@ class LicenseService { } static bool licenseContainsKey(final String key) { - return LicenseStorageKey.values.map((e) => e.value).toList().contains(key); + return Module.values.map((e) => e.value).toList().contains(key); } static Future _saveModule(final dynamic body) async { From 65f91ef10797fccdae9a649f2ae4c1bda80a58a9 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 18 Nov 2024 17:15:32 -0300 Subject: [PATCH 12/75] WIP --- .../helpers/license/license_helper.dart | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index 6ca74666..ab47f094 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -112,6 +112,39 @@ extension LicenseKeyExtension on Module { return ''; } } + + String get route { + switch (this) { + case Module.messages: + return '/messages'; + case Module.liberations: + return '/liberations'; + case Module.reservations: + return '/reservations'; + case Module.access: + return '/access'; + case Module.openedVisits: + return '/opened-visits'; + case Module.vehicles: + return '/vehicles'; + case Module.residents: + return '/residents'; + case Module.pets: + return '/pets'; + case Module.orders: + return '/orders'; + case Module.completeSchedule: + return '/complete-schedule'; + case Module.providerSchedule: + return '/provider-schedule'; + case Module.deliverySchedule: + return '/delivery-schedule'; + case Module.fastPass: + return '/fast-pass'; + default: + return ''; + } + } } class LicenseHelper { From 8e5d40ff2f659653c0e462293bf94f84b9a01b50 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 21 Nov 2024 16:15:14 -0300 Subject: [PATCH 13/75] WIP --- .../menu_component/menu_component_model.dart | 62 ++++++++----- lib/flutter_flow/nav/nav.dart | 5 -- lib/main.dart | 1 + .../about_property_model.dart | 19 ++-- lib/pages/home_page/home_page_model.dart | 88 +++++++++++-------- .../helpers/database/database_helper.dart | 12 ++- .../helpers/license/license_helper.dart | 40 +++++---- .../helpers/storage/keychain_storage.dart | 9 +- .../helpers/storage/secure_storage.dart | 3 + .../storage/shared_preferences_storage.dart | 3 + .../helpers/storage/storage_helper.dart | 15 ++-- .../services/deeplink/deep_link_service.dart | 2 +- 12 files changed, 159 insertions(+), 100 deletions(-) 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 3aadf479..213ad4cf 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -27,19 +27,25 @@ class MenuComponentModel extends FlutterFlowModel { final bool expandable; final List menuOptions; - MenuComponentModel({required this.style, required this.item, required this.expandable, required this.menuOptions}); + MenuComponentModel( + {required this.style, + required this.item, + required this.expandable, + required this.menuOptions}); bool isGrid = false; late MenuListViewComponentModel menuListViewComponentModel; late MenuStaggeredViewComponentModel menuStaggeredViewComponentModel; late VoidCallback safeSetState; - late List menuEntries; + List menuEntries = []; @override void initState(BuildContext context) { - menuListViewComponentModel = createModel(context, () => MenuListViewComponentModel()); - menuStaggeredViewComponentModel = createModel(context, () => MenuStaggeredViewComponentModel()); + menuListViewComponentModel = + createModel(context, () => MenuListViewComponentModel()); + menuStaggeredViewComponentModel = + createModel(context, () => MenuStaggeredViewComponentModel()); } @override @@ -48,27 +54,32 @@ class MenuComponentModel extends FlutterFlowModel { menuStaggeredViewComponentModel.dispose(); } - Future> generateMenuEntries(BuildContext context, MenuItem item, List options) async { + Future> generateMenuEntries( + BuildContext context, MenuItem item, List options) async { List entries = []; - Future addMenuEntry(IconData icon, String enText, String ptText, Function() action) async { + Future addMenuEntry( + IconData icon, String enText, String ptText, Function() action) async { entries.add( item == MenuItem.button ? MenuButtonWidget( icon: icon, action: action, - title: FFLocalizations.of(context).getVariableText(enText: enText, ptText: ptText), + title: FFLocalizations.of(context) + .getVariableText(enText: enText, ptText: ptText), safeSetState: safeSetState) : item == MenuItem.card ? MenuCardItem( icon: icon, action: action, - title: FFLocalizations.of(context).getVariableText(enText: enText, ptText: ptText), + title: FFLocalizations.of(context) + .getVariableText(enText: enText, ptText: ptText), safeSetState: safeSetState) : item == MenuItem.tile ? MenuCardItem( icon: icon, action: action, - title: FFLocalizations.of(context).getVariableText(enText: enText, ptText: ptText), + title: FFLocalizations.of(context) + .getVariableText(enText: enText, ptText: ptText), safeSetState: safeSetState) : null, ); @@ -80,15 +91,18 @@ class MenuComponentModel extends FlutterFlowModel { log('Module: ${opt.value} - License: $v'); switch (v) { case 'VISIVEL': - addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', 'Agendar Prestadores', () async { + addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', + 'Agendar Prestadores', () async { await open(context, '/provisionalSchedule'); }); break; - case 'INVISIVEL': + case 'BLOQUEADO': DialogUnavailable.unavailableFeature(context); break; - default: + case 'INVISIVEL': break; + default: + throw Exception('Invalid license value'); } safeSetState(); } @@ -118,11 +132,13 @@ class MenuComponentModel extends FlutterFlowModel { ptText: 'Tem certeza que deseja sair?', enText: 'Are you sure you want to logout?', ); - showAlertDialog(context, title, content, () async => await AuthenticationService.signOut(context)); + showAlertDialog(context, title, content, + () async => await AuthenticationService.signOut(context)); } Future openDeliverySchedule(BuildContext context) async { - final bool isProvisional = await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; + final bool isProvisional = + await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; if (isProvisional == true) { context.push( '/deliverySchedule', @@ -140,7 +156,8 @@ class MenuComponentModel extends FlutterFlowModel { } Future openProvisionalSchedule(BuildContext context) async { - final isProvisional = await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; + final isProvisional = + await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; if (isProvisional == true) { context.push( '/provisionalSchedule', @@ -158,7 +175,8 @@ class MenuComponentModel extends FlutterFlowModel { } Future openFastPassSchedule(BuildContext context) async { - final isWpp = await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; + final isWpp = + await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; if (isWpp) { context.push( '/fastPassPage', @@ -250,7 +268,8 @@ class MenuComponentModel extends FlutterFlowModel { ptText: 'Tem certeza que deseja sair?', enText: 'Are you sure you want to logout?', ); - showAlertDialog(context, title, content, () async => await AuthenticationService.signOut(context)); + showAlertDialog(context, title, content, + () async => await AuthenticationService.signOut(context)); } Future openPreferencesSettings(BuildContext context) async { @@ -267,7 +286,8 @@ class MenuComponentModel extends FlutterFlowModel { } Future openMyOrders(BuildContext context) async { - final isWpp = await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; + final isWpp = + await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; ; if (isWpp) { context.push( @@ -286,7 +306,8 @@ class MenuComponentModel extends FlutterFlowModel { } Future openReservations(BuildContext context) async { - final isWpp = await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; + final isWpp = + await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; ; if (isWpp) { context.push( @@ -403,7 +424,8 @@ class MenuComponentModel extends FlutterFlowModel { } Future openPetsRegister(BuildContext context) async { - bool isPet = await StorageHelper().g(KeychainStorageKey.pets.value) == 'true'; + bool isPet = + await StorageHelper().g(KeychainStorageKey.pets.value) == 'true'; ; if (isPet) { context.push( diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 994467d0..6ff6dd73 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -148,11 +148,6 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { name: 'vehiclesOnThePropertyPage', path: '/vehiclesOnThePropertyPage', builder: (context, params) => const VehicleOnTheProperty()), - FFRoute( - name: 'homePage', - path: '/homePage', - builder: (context, params) => HomePageWidget(key: UniqueKey()), - ), FFRoute( name: 'receptionPage', path: '/receptionPage', diff --git a/lib/main.dart b/lib/main.dart index 143bc33c..0bcabe17 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,6 +16,7 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; diff --git a/lib/pages/about_property_page/about_property_model.dart b/lib/pages/about_property_page/about_property_model.dart index 4bd5e867..df559059 100644 --- a/lib/pages/about_property_page/about_property_model.dart +++ b/lib/pages/about_property_page/about_property_model.dart @@ -6,6 +6,7 @@ import 'package:hub/components/organism_components/menu_component/menu_component import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/about_property_page/about_property_screen.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; class AboutPropertyModel extends FlutterFlowModel { dynamic item; @@ -22,13 +23,17 @@ class AboutPropertyModel extends FlutterFlowModel { void initState(BuildContext context) { menuComponentModel = createModel( context, - () => MenuComponentModel(expandable: true, style: MenuView.list_grid, item: MenuItem.button, menuOptions: [ - MenuOption.PetsOnTheProperty, - MenuOption.ResidentsOnTheProperty, - MenuOption.VisitsOnTheProperty, - MenuOption.VehiclesOnTheProperty, - MenuOption.PackagesOnTheProperty, - ])); + () => MenuComponentModel( + expandable: true, + style: MenuView.list_grid, + item: MenuItem.button, + menuOptions: [ + Module.pets, + Module.residents, + Module.openedVisits, + Module.vehicles, + Module.orders, + ])); initAsync(); } diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart index db3eb7e1..e68faf34 100644 --- a/lib/pages/home_page/home_page_model.dart +++ b/lib/pages/home_page/home_page_model.dart @@ -6,10 +6,10 @@ 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/license/license_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - class HomePageModel extends FlutterFlowModel { HomePageModel({required this.safeSetState}); late final VoidCallback safeSetState; @@ -32,54 +32,64 @@ class HomePageModel extends FlutterFlowModel { Future _initVariable() async { devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - userName = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; + userUUID = + (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = + (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + userName = + (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; userEmail = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; } @override void initState(BuildContext context) { _initVariable(); - localComponentModel = createModel(context, () => LocalProfileComponentModel()); + localComponentModel = + createModel(context, () => LocalProfileComponentModel()); homeMenuComponentModel = createModel( context, - () => MenuComponentModel(expandable: true, style: MenuView.list_grid, item: MenuItem.button, menuOptions: [ - MenuOption.SettingsOnTheApp, - MenuOption.MessagesOnTheProperty, - MenuOption.AccessOnTheProperty, - MenuOption.PetsRegister, - MenuOption.VisitorsRegister, - MenuOption.ReservationsOnTheLocal, - MenuOption.PackagesOnTheProperty, - MenuOption.DeliverySchedule, - MenuOption.WorkersOnTheProperty, - MenuOption.AboutProperty, - MenuOption.CompleteSchedule, - MenuOption.FastPassSchedule, - MenuOption.LiberationsOnTheProperty, - MenuOption.QRCodeAccessInProperty, - ])); + () => MenuComponentModel( + expandable: true, + style: MenuView.list_grid, + item: MenuItem.button, + menuOptions: [ + Module.messages, + Module.access, + Module.pets, + Module.openedVisits, + Module.reservations, + Module.orders, + Module.providerSchedule, + Module.deliverySchedule, + Module.completeSchedule, + Module.fastPass, + Module.liberations, + Module.qrCode, + Module.settings, + ])); drawerMenuComponentModel = createModel( context, - () => MenuComponentModel(expandable: false, style: MenuView.list, item: MenuItem.tile, menuOptions: [ - MenuOption.SettingsOnTheApp, - MenuOption.MessagesOnTheProperty, - MenuOption.AccessOnTheProperty, - MenuOption.PetsRegister, - MenuOption.VisitorsRegister, - MenuOption.ReservationsOnTheLocal, - MenuOption.PackagesOnTheProperty, - MenuOption.DeliverySchedule, - MenuOption.WorkersOnTheProperty, - MenuOption.AboutProperty, - MenuOption.CompleteSchedule, - MenuOption.FastPassSchedule, - MenuOption.LiberationsOnTheProperty, - MenuOption.QRCodeAccessInProperty, - MenuOption.LogoutOnTheApp, - ])); - messageWellComponentModel = createModel(context, () => MessageWellComponentModel()); + () => MenuComponentModel( + expandable: false, + style: MenuView.list, + item: MenuItem.tile, + menuOptions: [ + Module.messages, + Module.access, + Module.pets, + Module.openedVisits, + Module.reservations, + Module.orders, + Module.providerSchedule, + Module.deliverySchedule, + Module.completeSchedule, + Module.fastPass, + Module.liberations, + Module.qrCode, + Module.logout, + ])); + messageWellComponentModel = + createModel(context, () => MessageWellComponentModel()); } @override diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 8163308b..0166e34c 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -21,8 +21,10 @@ class DatabaseStorage { return _database!; } + bool isInitialized = false; + Future init() async { - if (_database != null) return; + if (isInitialized) return; _database = await openDatabase( join(await getDatabasesPath(), _dbName), version: _dbVersion, @@ -31,6 +33,7 @@ class DatabaseStorage { onDowngrade: _onDowngrade, ); await LicenseService.setupLicense(database); + isInitialized = true; } Future _onCreate(Database database, int version) async { @@ -39,13 +42,14 @@ class DatabaseStorage { await database.execute(LicenseHelper.createTableQuery); } - Future _onUpgrade(Database database, int oldVersion, int newVersion) async { + Future _onUpgrade( + Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2) { await database.execute(LicenseHelper.createTableQuery); - await LicenseService.setupLicense(database); } } - Future _onDowngrade(Database database, int oldVersion, int newVersion) async {} + Future _onDowngrade( + Database database, int oldVersion, int newVersion) async {} } diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index ab47f094..7c55abcd 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -77,6 +77,9 @@ enum Module { providerSchedule, deliverySchedule, fastPass, + qrCode, + settings, + logout, } extension LicenseKeyExtension on Module { @@ -116,31 +119,31 @@ extension LicenseKeyExtension on Module { String get route { switch (this) { case Module.messages: - return '/messages'; + return '/messageHistoryPage'; case Module.liberations: - return '/liberations'; + return '/liberationHistory'; case Module.reservations: - return '/reservations'; + return '/reservation'; case Module.access: - return '/access'; + return '/acessHistoryPage'; case Module.openedVisits: - return '/opened-visits'; + return '/visitsOnTheProperty'; case Module.vehicles: - return '/vehicles'; + return '/vehiclesOnThePropertyPage'; case Module.residents: - return '/residents'; + return '/peopleOnThePropertyPage'; case Module.pets: - return '/pets'; + return '/petsPage'; case Module.orders: - return '/orders'; + return '/packageOrder'; case Module.completeSchedule: - return '/complete-schedule'; + return '/scheduleCompleteVisitPage'; case Module.providerSchedule: - return '/provider-schedule'; + return '/provisionalSchedule'; case Module.deliverySchedule: - return '/delivery-schedule'; + return '/deliverySchedule'; case Module.fastPass: - return '/fast-pass'; + return '/fastPassPage'; default: return ''; } @@ -170,7 +173,8 @@ class LicenseHelper { await DatabaseStorage.instance.init(); } - static Future insertLicenseFoo(final List key, final String display) async { + static Future insertLicenseFoo( + final List key, final String display) async { for (var element in key) { DatabaseStorage.database.insert( tableLicense, @@ -187,11 +191,12 @@ class LicenseHelper { } Future g(String key) async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); + var response = await DatabaseStorage.database.query(tableLicense, + where: 'key = ?', whereArgs: [key], columns: ['display']); if (response.isEmpty) { return null; } - return response.first['value'].toString(); + return response.first['display'].toString(); } Future s(String key, T value) async { @@ -211,7 +216,8 @@ class LicenseHelper { } Future d(String key) async { - await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); + await DatabaseStorage.database + .delete(tableLicense, where: 'key = ?', whereArgs: [key]); } Future c() async { diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index c14aa6b5..e7116864 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -8,6 +8,7 @@ class KeychainHelper implements BaseStorage { static final KeychainHelper instance = KeychainHelper._(); static const String tableKeychain = 'keychain'; + bool _isInitialized = false; static String get createTableQuery => ''' CREATE TABLE $tableKeychain ( @@ -22,12 +23,15 @@ class KeychainHelper implements BaseStorage { @override Future init() async { + if (_isInitialized) return; await DatabaseStorage.instance.init(); + _isInitialized = true; } @override Future get(String key) async { - var response = await DatabaseStorage.database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); + var response = await DatabaseStorage.database + .query(tableKeychain, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; } @@ -52,7 +56,8 @@ class KeychainHelper implements BaseStorage { @override Future delete(String key) async { - await DatabaseStorage.database.delete(tableKeychain, where: 'key = ?', whereArgs: [key]); + await DatabaseStorage.database + .delete(tableKeychain, where: 'key = ?', whereArgs: [key]); } @override diff --git a/lib/shared/helpers/storage/secure_storage.dart b/lib/shared/helpers/storage/secure_storage.dart index 1d40ee71..59125aa2 100644 --- a/lib/shared/helpers/storage/secure_storage.dart +++ b/lib/shared/helpers/storage/secure_storage.dart @@ -7,10 +7,13 @@ class SecureStorage implements BaseStorage { static final SecureStorage instance = SecureStorage._(); late final FlutterSecureStorage _secureStorage; + bool _isInitialized = false; @override Future init() async { + if (_isInitialized) return; _secureStorage = const FlutterSecureStorage(); + _isInitialized = true; } @override diff --git a/lib/shared/helpers/storage/shared_preferences_storage.dart b/lib/shared/helpers/storage/shared_preferences_storage.dart index 3cc38a6e..a2561e2a 100644 --- a/lib/shared/helpers/storage/shared_preferences_storage.dart +++ b/lib/shared/helpers/storage/shared_preferences_storage.dart @@ -7,10 +7,13 @@ class SharedPreferencesStorage implements BaseStorage { static final SharedPreferencesStorage instance = SharedPreferencesStorage._(); late final SharedPreferences _prefs; + bool _isInitialized = false; @override Future init() async { + if (_isInitialized) return; _prefs = await SharedPreferences.getInstance(); + _isInitialized = true; } @override diff --git a/lib/shared/helpers/storage/storage_helper.dart b/lib/shared/helpers/storage/storage_helper.dart index 3e97ddf5..f5536d4b 100644 --- a/lib/shared/helpers/storage/storage_helper.dart +++ b/lib/shared/helpers/storage/storage_helper.dart @@ -10,10 +10,10 @@ class StorageHelper { StorageHelper._internal(); late BuildContext? _context; - late bool _isRecovered = false; BuildContext? get context => _context; set context(BuildContext? context) => _context = context; + late bool _isRecovered = false; bool get isRecovered => _isRecovered; set isRecovered(bool isRecovered) => _isRecovered = isRecovered; @@ -22,10 +22,12 @@ class StorageHelper { await SharedPreferencesStorage.instance.init(); await KeychainHelper.instance.init(); - String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value); + String? isFirstRun = await SharedPreferencesStorage.instance + .get(SharedPreferencesKey.isFirstRun.value); - if (isFirstRun == 'true') { - await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, false); + if (isFirstRun != 'false') { + await SharedPreferencesStorage.instance + .set(SharedPreferencesKey.isFirstRun.value, false); await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); } } @@ -44,7 +46,10 @@ class StorageHelper { static BaseStorage getInstanceByKey(String key) { if (SecureStorageKey.values.map((e) => e.value).toList().contains(key)) { return SecureStorage.instance; - } else if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) { + } else if (SharedPreferencesKey.values + .map((e) => e.value) + .toList() + .contains(key)) { return SharedPreferencesStorage.instance; } else { return KeychainHelper.instance; diff --git a/lib/shared/services/deeplink/deep_link_service.dart b/lib/shared/services/deeplink/deep_link_service.dart index 76715219..42cf083d 100644 --- a/lib/shared/services/deeplink/deep_link_service.dart +++ b/lib/shared/services/deeplink/deep_link_service.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/forgot_password_page/forgot_password_screen.dart'; -import 'package:hub/shared/helpers/storage_helper.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; class DeepLinkService { static final DeepLinkService _instance = DeepLinkService._internal(); From ee4c257710d6ffc6c8dadead88fed5a00a3c3b85 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 21 Nov 2024 16:55:22 -0300 Subject: [PATCH 14/75] WIP --- .../menu_component/menu_component_model.dart | 296 +----------------- .../menu_component/menu_component_widget.dart | 4 +- .../helpers/license/license_helper.dart | 130 ++++++++ .../services/license/license_service.dart | 13 +- .../localization/localization_service.dart | 139 +++++--- 5 files changed, 245 insertions(+), 337 deletions(-) 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 213ad4cf..2f3f66c9 100644 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ b/lib/components/organism_components/menu_component/menu_component_model.dart @@ -58,28 +58,25 @@ class MenuComponentModel extends FlutterFlowModel { BuildContext context, MenuItem item, List options) async { List entries = []; Future addMenuEntry( - IconData icon, String enText, String ptText, Function() action) async { + IconData icon, String text, Function() action) async { entries.add( item == MenuItem.button ? MenuButtonWidget( icon: icon, action: action, - title: FFLocalizations.of(context) - .getVariableText(enText: enText, ptText: ptText), + title: text, safeSetState: safeSetState) : item == MenuItem.card ? MenuCardItem( icon: icon, action: action, - title: FFLocalizations.of(context) - .getVariableText(enText: enText, ptText: ptText), + title: text, safeSetState: safeSetState) : item == MenuItem.tile ? MenuCardItem( icon: icon, action: action, - title: FFLocalizations.of(context) - .getVariableText(enText: enText, ptText: ptText), + title: text, safeSetState: safeSetState) : null, ); @@ -91,18 +88,19 @@ class MenuComponentModel extends FlutterFlowModel { log('Module: ${opt.value} - License: $v'); switch (v) { case 'VISIVEL': - addMenuEntry(Icons.engineering_outlined, 'Schedule Providers', - 'Agendar Prestadores', () async { - await open(context, '/provisionalSchedule'); + await addMenuEntry(opt.icon, opt.name, () async { + await open(context, opt.route); }); break; case 'BLOQUEADO': - DialogUnavailable.unavailableFeature(context); + await addMenuEntry(opt.icon, opt.name, () async { + await DialogUnavailable.unavailableFeature(context); + }); break; case 'INVISIVEL': break; default: - throw Exception('Invalid license value'); + break; } safeSetState(); } @@ -136,129 +134,6 @@ class MenuComponentModel extends FlutterFlowModel { () async => await AuthenticationService.signOut(context)); } - Future openDeliverySchedule(BuildContext context) async { - final bool isProvisional = - await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; - if (isProvisional == true) { - context.push( - '/deliverySchedule', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } else { - DialogUnavailable.unavailableFeature(context); - } - } - - Future openProvisionalSchedule(BuildContext context) async { - final isProvisional = - await StorageHelper().g(KeychainStorageKey.provisional.value) == 'true'; - if (isProvisional == true) { - context.push( - '/provisionalSchedule', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } else { - DialogUnavailable.unavailableFeature(context); - } - } - - Future openFastPassSchedule(BuildContext context) async { - final isWpp = - await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; - if (isWpp) { - context.push( - '/fastPassPage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } else { - DialogUnavailable.unavailableFeature(context); - } - } - - Future showSchedules(BuildContext context) async { - final routesListStr = [ - 'scheduleProvisionalVisitPage', - 'fastPassPage', - 'scheduleCompleteVisitPage', - ]; - final iconsListIcon = [ - Icons.date_range_rounded, - Icons.date_range_rounded, - Icons.date_range_rounded, - ]; - final nameListStr = [ - FFLocalizations.of(context).getVariableText( - ptText: 'Visita\nProvisória', - enText: 'Provisional\nSchedule', - ), - FFLocalizations.of(context).getVariableText( - ptText: 'Visita\nRápida', - enText: 'Fast\nSchedule', - ), - FFLocalizations.of(context).getVariableText( - ptText: 'Visita\nCompleta', - enText: 'Complete\nSchedule', - ), - ]; - await showAdaptiveDialog( - context: context, - builder: (context) { - return Padding( - padding: MediaQuery.viewInsetsOf(context), - child: OptionSelectionModalWidget( - routesListStr: routesListStr, - iconsListIcon: iconsListIcon, - nameListStr: nameListStr, - ), - ); - }, - ); - } - - Future openVisitorsRegister(BuildContext context) async { - context.push( - '/registerVisitorPage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } - - Future openPoepleOnTheProperty(BuildContext context) async { - context.push( - '/peopleOnThePropertyPage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } - Future Logout(BuildContext context) async { final String title = FFLocalizations.of(context).getVariableText( ptText: 'Sair', @@ -272,7 +147,7 @@ class MenuComponentModel extends FlutterFlowModel { () async => await AuthenticationService.signOut(context)); } - Future openPreferencesSettings(BuildContext context) async { + Future settings(BuildContext context) async { context.push( '/preferencesSettings', extra: { @@ -285,95 +160,9 @@ class MenuComponentModel extends FlutterFlowModel { ); } - Future openMyOrders(BuildContext context) async { - final isWpp = - await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; - ; - if (isWpp) { - context.push( - '/packageOrder', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } else { - DialogUnavailable.unavailableFeature(context); - } - } - - Future openReservations(BuildContext context) async { - final isWpp = - await StorageHelper().g(KeychainStorageKey.whatsapp.value) == 'true'; - ; - if (isWpp) { - context.push( - '/reservation', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } else { - DialogUnavailable.unavailableFeature(context); - } - } - - Future showHistories(BuildContext context) async { - await showAdaptiveDialog( - // isScrollControlled: true, - // backgroundColor: Colors.transparent, - // enableDrag: false, - context: context, - builder: (context) { - return Padding( - padding: MediaQuery.viewInsetsOf(context), - child: OptionSelectionModalWidget( - routesListStr: const [ - 'liberationHistory', - 'acessHistoryPage', - 'scheduleCompleteVisitPage', - 'messageHistoryPage' - ], - iconsListIcon: const [ - Icons.history_rounded, - Icons.history_rounded, - Icons.history_rounded, - Icons.history_rounded, - ], - nameListStr: [ - FFLocalizations.of(context).getVariableText( - ptText: 'Histórico\nde Liberação', - enText: 'Liberation\nHistory', - ), - FFLocalizations.of(context).getVariableText( - ptText: 'Histórico\nde Acesso', - enText: 'Access\nHistory', - ), - FFLocalizations.of(context).getVariableText( - ptText: 'Histórico\nde Visita', - enText: 'Visit\nHistory', - ), - FFLocalizations.of(context).getVariableText( - ptText: 'Histórico\nde Mensagens', - enText: 'Message\nHistory', - ), - ], - ), - ); - }, - ); - } - - Future openLiberationsHistory(BuildContext context) async { + Future about(BuildContext context) async { context.push( - '/liberationHistory', + '/aboutProperty', extra: { kTransitionInfoKey: const TransitionInfo( hasTransition: false, @@ -383,63 +172,4 @@ class MenuComponentModel extends FlutterFlowModel { }, ); } - - Future openAccessHistory(BuildContext context) async { - context.push( - '/acessHistoryPage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } - - Future openVisitsHistory(BuildContext context) async { - context.push( - '/scheduleCompleteVisitPage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } - - Future openMessagesHistory(BuildContext context) async { - context.push( - '/messageHistoryPage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } - - Future openPetsRegister(BuildContext context) async { - bool isPet = - await StorageHelper().g(KeychainStorageKey.pets.value) == 'true'; - ; - if (isPet) { - context.push( - '/petsPage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } else { - DialogUnavailable.unavailableFeature(context); - } - } } diff --git a/lib/components/organism_components/menu_component/menu_component_widget.dart b/lib/components/organism_components/menu_component/menu_component_widget.dart index b6cb84ca..a687ba3f 100644 --- a/lib/components/organism_components/menu_component/menu_component_widget.dart +++ b/lib/components/organism_components/menu_component/menu_component_widget.dart @@ -32,8 +32,8 @@ class _MenuComponentWidgetState extends State { @override void didChangeDependencies() async { super.didChangeDependencies(); - widget.model.menuEntries = - await widget.model.generateMenuEntries(context, widget.model.item, widget.model.menuOptions); + widget.model.menuEntries = await widget.model.generateMenuEntries( + context, widget.model.item, widget.model.menuOptions); } @override diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index 7c55abcd..a0e6164a 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -1,5 +1,8 @@ import 'dart:developer'; +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:sqflite/sqflite.dart'; @@ -19,6 +22,7 @@ enum ActiveModuleKey { providerSchedule, deliverySchedule, fastPass, + qrCode, } extension InactiveModuleKeyExtension on InactiveModuleKey { @@ -57,6 +61,8 @@ extension ActiveModuleKeyExtension on ActiveModuleKey { return 'FRE-HUB-AGE-PROV-DELIVERY'; case ActiveModuleKey.fastPass: return 'FRE-HUB-FASTPASS'; + case ActiveModuleKey.qrCode: + return 'FRE-HUB-QRCODE'; default: return ''; } @@ -111,11 +117,135 @@ extension LicenseKeyExtension on Module { return 'FRE-HUB-AGE-PROV-DELIVERY'; case Module.fastPass: return 'FRE-HUB-FASTPASS'; + case Module.qrCode: + return 'FRE-HUB-QRCODE'; default: return ''; } } + String get name { + switch (this) { + case Module.messages: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Mensagens', + enText: 'Messages', + ); + case Module.liberations: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Liberar', + enText: 'Liberations', + ); + case Module.reservations: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case Module.access: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Acessos', + enText: 'Access', + ); + case Module.openedVisits: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Visitas Abertas', + enText: 'Opened Visits', + ); + case Module.vehicles: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Veículos', + enText: 'Vehicles', + ); + case Module.residents: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ); + case Module.pets: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case Module.orders: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Encomendas', + enText: 'Orders', + ); + case Module.completeSchedule: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case Module.providerSchedule: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case Module.deliverySchedule: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case Module.fastPass: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case Module.qrCode: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'QR Code', + enText: 'QR Code', + ); + case Module.settings: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + case Module.logout: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ); + } + } + + IconData get icon { + switch (this) { + case Module.messages: + return Icons.message; + case Module.liberations: + return Icons.lock_open; + case Module.reservations: + return Icons.calendar_today; + case Module.access: + return Icons.access_time; + case Module.openedVisits: + return Icons.people; + case Module.vehicles: + return Icons.directions_car; + case Module.residents: + return Icons.person; + case Module.pets: + return Icons.pets; + case Module.orders: + return Icons.shopping_cart; + case Module.completeSchedule: + return Icons.schedule; + case Module.providerSchedule: + return Icons.engineering_outlined; + case Module.deliverySchedule: + return Icons.delivery_dining; + case Module.fastPass: + return Icons.fastfood; + case Module.qrCode: + return Icons.qr_code; + case Module.settings: + return Icons.settings; + case Module.logout: + return Icons.logout; + } + } + String get route { switch (this) { case Module.messages: diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index b2ea7651..9c5e8710 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -17,8 +17,10 @@ class LicenseService { LicenseService._internal(); static Future setupLicense(Database database) async { - await LicenseHelper.insertLicenseFoo(InactiveModuleKey.values.map((e) => e.value).toList(), 'INVISIVEL'); - await LicenseHelper.insertLicenseFoo(ActiveModuleKey.values.map((e) => e.value).toList(), 'VISIVEL'); + await LicenseHelper.insertLicenseFoo( + InactiveModuleKey.values.map((e) => e.value).toList(), 'INVISIVEL'); + await LicenseHelper.insertLicenseFoo( + ActiveModuleKey.values.map((e) => e.value).toList(), 'VISIVEL'); } static Future initLicenseService() async { @@ -68,6 +70,7 @@ class LicenseService { } return true; } catch (e) { + log('Erro ao obter licenças: $e'); await setupLicense(DatabaseStorage.database); return true; } @@ -78,9 +81,11 @@ class LicenseService { } static Future _saveModule(final dynamic body) async { - if (body is Map) log('Salvando módulo: ${body.toString()}'); + if (body is Map) + log('Salvando módulo: ${body.toString()}'); // if (body is Map) await StorageHelper().s(body['key'], ''); - if (body is Map) await StorageHelper().s(body['key'], body); + if (body is Map) + await StorageHelper().s(body['key'], body); // StorageHelper.getInstance(Storage.SQLiteStorage).set(key, value); } diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 8a168906..019133fa 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -34,13 +34,15 @@ class LocalizationService { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg) + .whenComplete(() => selectLocal(context, response)); return; } final List locals = response.jsonBody['locais'] ?? []; final bool isEmpty = locals.isEmpty; - final bool isActive = locals.where((local) => local['CLU_STATUS'] != 'B').isNotEmpty; + final bool isActive = + locals.where((local) => local['CLU_STATUS'] != 'B').isNotEmpty; final bool isEnable = !isEmpty && isActive; if (isEnable) { @@ -72,7 +74,8 @@ class LocalizationService { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg) + .whenComplete(() => selectLocal(context, response)); return false; } @@ -83,7 +86,8 @@ class LocalizationService { final bool isInactived = await _isInactived(locals); final bool isPending = _isPending(locals); final bool isUnique = locals.length == 1; - final bool isBlocked = locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty; + final bool isBlocked = + locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty; final bool isEnabled = isUnique && isActive; final bool isDisabled = isUnique && isBlocked; final bool isUnselected = await _isUnselected(); @@ -123,7 +127,8 @@ class LocalizationService { enText: 'Error getting locals, verify your connection', ptText: 'Erro ao obter locais, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); + await DialogUtil.error(context, errorMsg) + .whenComplete(() => selectLocal(context, null)); return false; } } @@ -138,7 +143,8 @@ class LocalizationService { final GetLocalsCall callback = PhpGroup.getLocalsCall; response = await callback.call(); final String errorMsg = response.jsonBody['error_msg']; - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg) + .whenComplete(() => selectLocal(context, response)); return false; } else if (response.jsonBody == null) { final GetLocalsCall callback = PhpGroup.getLocalsCall; @@ -147,15 +153,16 @@ class LocalizationService { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg) + .whenComplete(() => selectLocal(context, response)); return false; } else { - final bool isNewVersion = await _updateStorageUtil(response.jsonBody); - if (!isNewVersion) { - await LicenseService.setupLicense(DatabaseStorage.database); - return false; - } - return await LicenseService.fetchLicenses(); + // final bool isNewVersion = await _updateStorageUtil(response.jsonBody); + // if (!isNewVersion) { + await LicenseService.setupLicense(DatabaseStorage.database); + return false; + // } + // return await LicenseService.fetchLicenses(); } } catch (e, s) { log('() => stack processData: $s'); @@ -164,12 +171,14 @@ class LocalizationService { enText: 'Error getting data, verify your connection', ptText: 'Erro ao obter dados, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); + await DialogUtil.error(context, errorMsg) + .whenComplete(() => selectLocal(context, null)); return false; } } - static Future selectLocal(BuildContext context, ApiCallResponse? response) async { + static Future selectLocal( + BuildContext context, ApiCallResponse? response) async { return await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, @@ -233,10 +242,13 @@ class LocalizationService { } static void _handleError(BuildContext context, String errorMsg) async { - final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; - final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; + final String devUUID = + await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; + final String userUUID = + await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; - final bool isDevLinked = !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); + final bool isDevLinked = + !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); log('() => isLinked: $errorMsg'); log('() => isLinked: $errorMsg'); if (!isAuthenticated) { @@ -256,15 +268,20 @@ class LocalizationService { await DialogUtil.warning(context, errorMsg); return; } - await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); + await DialogUtil.error(context, errorMsg) + .whenComplete(() async => await selectLocal(context, null)); } - static Future _handleUnavailable(BuildContext context, List locals) async { + static Future _handleUnavailable( + BuildContext context, List locals) async { log('() => isUnavailable'); try { - await StorageHelper().s(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); - await StorageHelper().s(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); - await StorageHelper().s(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); + await StorageHelper() + .s(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); + await StorageHelper() + .s(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); + await StorageHelper() + .s(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); @@ -272,21 +289,28 @@ class LocalizationService { await StorageHelper().s(KeychainStorageKey.clientName.value, ''); return false; } - if (response.jsonBody['error'] == false) return await processData(context).then((value) => value); + if (response.jsonBody['error'] == false) + return await processData(context).then((value) => value); } catch (e, s) { await DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed('responderVinculo.php', '', 'Responder Vínculo', e, s); + LogUtil.requestAPIFailed( + 'responderVinculo.php', '', 'Responder Vínculo', e, s); return false; } return false; } - static Future _handleEnabled(BuildContext context, dynamic local) async { + static Future _handleEnabled( + BuildContext context, dynamic local) async { log('() => isEnabled'); - await StorageHelper().s(KeychainStorageKey.clientUUID.value, local['CLI_ID']); - await StorageHelper().s(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); - await StorageHelper().s(KeychainStorageKey.clientName.value, local['CLI_NOME']); - await StorageHelper().s(KeychainStorageKey.userName.value, local['USU_NOME']); + await StorageHelper() + .s(KeychainStorageKey.clientUUID.value, local['CLI_ID']); + await StorageHelper() + .s(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); + await StorageHelper() + .s(KeychainStorageKey.clientName.value, local['CLI_NOME']); + await StorageHelper() + .s(KeychainStorageKey.userName.value, local['USU_NOME']); return await processData(context); } @@ -298,19 +322,24 @@ class LocalizationService { } static Future _updateStorageUtil(Map jsonBody) async { - await StorageHelper().s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp']); - await StorageHelper() - .s(KeychainStorageKey.provisional.value, jsonBody['provisional'] != null && jsonBody['provisional']); - await StorageHelper().s(KeychainStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet']); + await StorageHelper().s(KeychainStorageKey.whatsapp.value, + jsonBody['whatsapp'] != null && jsonBody['whatsapp']); + await StorageHelper().s(KeychainStorageKey.provisional.value, + jsonBody['provisional'] != null && jsonBody['provisional']); + await StorageHelper().s(KeychainStorageKey.pets.value, + jsonBody['pet'] != null && jsonBody['pet']); await StorageHelper().s( KeychainStorageKey.petAmount.value, - jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty + jsonBody['petAmountRegister'] != null && + jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString()); - await StorageHelper().s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); await StorageHelper() - .s(KeychainStorageKey.isNewVersion.value, jsonBody['newVersion'] != null && jsonBody['newVersion']); - return jsonBody['newVersion'] != null && jsonBody['newVersion']; + .s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); + await StorageHelper().s(KeychainStorageKey.isNewVersion.value, + jsonBody['newVersion'] != null && jsonBody['newVersion']); + log('() => isNewVersion: ${jsonBody['newVersion']}'); + return jsonBody['newVersion'] == true; } static bool _isActive(List locals) { @@ -318,30 +347,44 @@ class LocalizationService { } static Future _isInactived(List locals) async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; + String cliUUID = + (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + return locals + .where( + (local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A') + .isNotEmpty; } static bool _isPending(List locals) { - return locals.where((local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A').isNotEmpty; + return locals + .where( + (local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A') + .isNotEmpty; } static Future _isUnselected() async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - String ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; + String cliUUID = + (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = + (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + String ownerUUID = + (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; } static Future _isSelected(bool isInactived) async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + String cliUUID = + (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = + (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; } static Future _isAvailable() async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + String cliUUID = + (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = + (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty; } } From 9891165ca995e6c3cbcf0cb7151107759ce8a694 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 22 Nov 2024 13:30:16 -0300 Subject: [PATCH 15/75] WIP --- lib/initialization.dart | 62 +++++++++++++++++++ lib/main.dart | 53 ++-------------- .../helpers/license/license_helper.dart | 1 + .../services/license/license_service.dart | 2 +- 4 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 lib/initialization.dart diff --git a/lib/initialization.dart b/lib/initialization.dart new file mode 100644 index 00000000..f5f4b023 --- /dev/null +++ b/lib/initialization.dart @@ -0,0 +1,62 @@ +import 'dart:developer'; + +import 'package:app_tracking_transparency/app_tracking_transparency.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_web_plugins/url_strategy.dart'; +import 'package:hub/backend/notifications/notification_service.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:hub/shared/services/localization/localization_service.dart'; + +Future initializeApp() async { + WidgetsFlutterBinding.ensureInitialized(); + await _initializeTracking(); + await StorageHelper().init(); + + await _initializeFirebase(); + await _initializeNotificationService(); + _initializeUrlStrategy(); + _initializeSystemSettings(); + await _initializeFlutterFlow(); +} + +Future _initializeTracking() async { + await AppTrackingTransparency.requestTrackingAuthorization(); +} + +Future _initializeFirebase() async { + await Firebase.initializeApp(); +} + +Future _initializeNotificationService() async { + await NotificationService.initialize(); +} + +void _initializeUrlStrategy() { + setUrlStrategy(PathUrlStrategy()); +} + +void _initializeSystemSettings() { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + if (kDebugMode) { + log("Aplicativo em Debug Mode, crashlytics desabilitado!"); + } else { + final crashlyticsInstance = FirebaseCrashlytics.instance; + if (crashlyticsInstance.isCrashlyticsCollectionEnabled) { + FlutterError.onError = crashlyticsInstance.recordFlutterError; + } + } +} + +Future _initializeFlutterFlow() async { + await FlutterFlowTheme.initialize(); + await FFLocalizations.initialize(); + GoRouter.optionURLReflectsImperativeAPIs = true; + usePathUrlStrategy(); +} diff --git a/lib/main.dart b/lib/main.dart index 0bcabe17..16354664 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,64 +22,19 @@ import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:responsive_framework/responsive_framework.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'backend/notifications/firebase_messaging_service.dart'; +import 'initialization.dart'; final GlobalKey navigatorKey = GlobalKey(); void main() async { await initializeApp(); - runApp(const App()); + runApp(const ProviderScope(child: App())); FirebaseMessaging.onBackgroundMessage(_backgroundHandlerMessage); } -Future initializeApp() async { - WidgetsFlutterBinding.ensureInitialized(); - await _initializeTracking(); - await StorageHelper().init(); - - await _initializeFirebase(); - await _initializeNotificationService(); - _initializeUrlStrategy(); - _initializeSystemSettings(); - await _initializeFlutterFlow(); -} - -Future _initializeTracking() async { - await AppTrackingTransparency.requestTrackingAuthorization(); -} - -Future _initializeFirebase() async { - await Firebase.initializeApp(); -} - -Future _initializeNotificationService() async { - await NotificationService.initialize(); -} - -void _initializeUrlStrategy() { - setUrlStrategy(PathUrlStrategy()); -} - -void _initializeSystemSettings() { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - if (kDebugMode) { - log("Aplicativo em Debug Mode, crashlytics desabilitado!"); - } else { - final crashlyticsInstance = FirebaseCrashlytics.instance; - if (crashlyticsInstance.isCrashlyticsCollectionEnabled) { - FlutterError.onError = crashlyticsInstance.recordFlutterError; - } - } -} - -Future _initializeFlutterFlow() async { - await FlutterFlowTheme.initialize(); - await FFLocalizations.initialize(); - GoRouter.optionURLReflectsImperativeAPIs = true; - usePathUrlStrategy(); -} - Future _foregroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { await StorageHelper().s(SecureStorageKey.haveLocal.value, true); @@ -246,7 +201,7 @@ class _AppState extends State with WidgetsBindingObserver { void didChangeAppLifecycleState(AppLifecycleState state) async { if (state == AppLifecycleState.detached) { await LocalizationService.processLocals(context); - FirebaseMessagingService().updateDeviceToken(); + await FirebaseMessagingService().updateDeviceToken(); } } diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index a0e6164a..827954b7 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -306,6 +306,7 @@ class LicenseHelper { static Future insertLicenseFoo( final List key, final String display) async { for (var element in key) { + log('insertLicenseFoo($element, $display)'); DatabaseStorage.database.insert( tableLicense, { diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 9c5e8710..b9d6693a 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -85,7 +85,7 @@ class LicenseService { log('Salvando módulo: ${body.toString()}'); // if (body is Map) await StorageHelper().s(body['key'], ''); if (body is Map) - await StorageHelper().s(body['key'], body); + await LicenseHelper().s(body['key'], body); // StorageHelper.getInstance(Storage.SQLiteStorage).set(key, value); } From 5cda31ea0d4a355ec6f0766ee6b7a564be180b20 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 27 Nov 2024 15:43:50 -0300 Subject: [PATCH 16/75] =?UTF-8?q?milestone=20modulariza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menu_button_item_widget.dart | 1 - .../menu_card_item/menu_card_item.dart | 1 - .../menu_item/menu_item.dart | 2 - .../local_profile_bloc.dart | 52 +++ .../local_profile_component_model.dart | 28 -- .../local_profile_component_widget.dart | 244 +++++------ .../menu_component/menu_component_bloc.dart | 103 +++++ .../menu_component/menu_component_model.dart | 175 -------- .../menu_component/menu_component_widget.dart | 134 ++++--- ...p_arrow_linked_locals_component_model.dart | 1 - ...cation_modal_template_component_model.dart | 1 - .../change_pass_widget.dart | 1 - .../provisional_schedule_template_model.dart | 1 - .../view_visit_detail_model.dart | 1 - ...search_modal_template_component_model.dart | 1 - lib/flutter_flow/nav/nav.dart | 197 +++------ lib/index.dart | 7 +- lib/main.dart | 9 +- .../about_property_model.dart | 20 - .../about_property_screen.dart | 49 ++- .../acess_history_page_model.dart | 1 - lib/pages/home_page/home_bloc.dart | 25 ++ lib/pages/home_page/home_events.dart | 1 + .../{home_page_widget.dart => home_page.dart} | 73 ++-- lib/pages/home_page/home_page_model.dart | 105 ----- lib/pages/home_page/home_state.dart | 35 ++ lib/pages/home_page/index.dart | 3 + .../liberation_history_model.dart | 1 - .../people_on_the_property_page_model.dart | 18 +- .../people_on_the_property_page_widget.dart | 336 ++++++---------- .../residents_on_the_property_model.dart | 30 ++ .../residents_on_the_property_screen.dart | 248 ++++++++++++ lib/shared/extensions/string_extensions.dart | 11 + .../helpers/database/database_helper.dart | 8 +- .../helpers/license/license_helper.dart | 209 ++++++---- lib/shared/helpers/storage/base_storage.dart | 1 - .../helpers/storage/keychain_storage.dart | 9 +- .../helpers/storage/storage_helper.dart | 11 +- .../services/deeplink/deep_link_service.dart | 3 +- .../services/keychain/keychain_service.dart | 2 - .../services/license/license_service.dart | 65 ++- .../localization/localization_service.dart | 168 +++----- .../widgets/drawer_widget/drawer_widget.dart | 98 +++-- test/integration_test/app_test.dart | 378 +++++++++--------- 44 files changed, 1426 insertions(+), 1441 deletions(-) create mode 100644 lib/components/organism_components/local_profile_component/local_profile_bloc.dart delete mode 100644 lib/components/organism_components/local_profile_component/local_profile_component_model.dart create mode 100644 lib/components/organism_components/menu_component/menu_component_bloc.dart delete mode 100644 lib/components/organism_components/menu_component/menu_component_model.dart create mode 100644 lib/pages/home_page/home_bloc.dart create mode 100644 lib/pages/home_page/home_events.dart rename lib/pages/home_page/{home_page_widget.dart => home_page.dart} (69%) delete mode 100644 lib/pages/home_page/home_page_model.dart create mode 100644 lib/pages/home_page/home_state.dart create mode 100644 lib/pages/home_page/index.dart create mode 100644 lib/pages/residents_on_the_property/residents_on_the_property_model.dart create mode 100644 lib/pages/residents_on_the_property/residents_on_the_property_screen.dart create mode 100644 lib/shared/extensions/string_extensions.dart 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 ced0373e..d446d4a7 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 @@ -9,7 +9,6 @@ class MenuButtonWidget extends MenuEntry { required this.action, required this.title, required this.icon, - required super.safeSetState, }) : super(action: action, title: title, icon: icon); @override diff --git a/lib/components/atomic_components/menu_card_item/menu_card_item.dart b/lib/components/atomic_components/menu_card_item/menu_card_item.dart index 5696f83a..c4c5cbaf 100644 --- a/lib/components/atomic_components/menu_card_item/menu_card_item.dart +++ b/lib/components/atomic_components/menu_card_item/menu_card_item.dart @@ -9,7 +9,6 @@ class MenuCardItem extends MenuEntry { required this.action, required this.title, required this.icon, - required super.safeSetState, }) : super(action: action, title: title, icon: icon); @override diff --git a/lib/components/molecular_components/menu_item/menu_item.dart b/lib/components/molecular_components/menu_item/menu_item.dart index fe97affd..77734bc1 100644 --- a/lib/components/molecular_components/menu_item/menu_item.dart +++ b/lib/components/molecular_components/menu_item/menu_item.dart @@ -28,11 +28,9 @@ abstract class MenuEntry extends StatefulWidget { required this.action, required this.title, required this.icon, - required this.safeSetState, }); final Function() action; final String title; final IconData icon; - final VoidCallback safeSetState; } diff --git a/lib/components/organism_components/local_profile_component/local_profile_bloc.dart b/lib/components/organism_components/local_profile_component/local_profile_bloc.dart new file mode 100644 index 00000000..5aacf75e --- /dev/null +++ b/lib/components/organism_components/local_profile_component/local_profile_bloc.dart @@ -0,0 +1,52 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter/material.dart'; +import 'package:hub/components/organism_components/local_profile_component/local_profile_component_widget.dart'; +import 'package:hub/flutter_flow/flutter_flow_model.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + +class LocalProfileEvent {} + +class LocalProfileState { + final String cliName; + final String cliUUID; + + LocalProfileState({this.cliName = '', this.cliUUID = ''}); + + LocalProfileState copyWith({String? cliName, String? cliUUID}) { + return LocalProfileState( + cliName: cliName ?? this.cliName, + cliUUID: cliUUID ?? this.cliUUID, + ); + } +} + +class LocalProfileBloc extends Bloc { + LocalProfileBloc() : super(LocalProfileState()) { + on((event, emit) async { + final cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); + }); + } +} + +class LocalProfileComponentModel extends FlutterFlowModel { + String cliName = ''; + String cliUUID = ''; + VoidCallback? setStateCallback; + + @override + void initState(BuildContext context) { + getData(); + } + + Future getData() async { + cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + setStateCallback?.call(); + } + + @override + void dispose() {} +} 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 deleted file mode 100644 index 300dae93..00000000 --- a/lib/components/organism_components/local_profile_component/local_profile_component_model.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; - -import '/flutter_flow/flutter_flow_util.dart'; -import 'local_profile_component_widget.dart' show LocalProfileComponentWidget; -import 'package:flutter/material.dart'; - -/// - -class LocalProfileComponentModel extends FlutterFlowModel { - String cliName = ''; - String cliUUID = ''; - VoidCallback? setStateCallback; - - @override - void initState(BuildContext context) { - getData(); - } - - Future getData() async { - cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - setStateCallback?.call(); - } - - @override - void dispose() {} -} 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 144f440b..cfbe2109 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 @@ -1,18 +1,14 @@ -import 'dart:developer'; - import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/components/organism_components/local_profile_component/local_profile_bloc.dart'; +import 'package:hub/flutter_flow/custom_functions.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - -import '/flutter_flow/custom_functions.dart' as functions; -import '/flutter_flow/flutter_flow_theme.dart'; -import '/flutter_flow/flutter_flow_util.dart'; -import '../../../shared/services/localization/localization_service.dart'; -import 'local_profile_component_model.dart'; - -export 'local_profile_component_model.dart'; +import 'package:hub/shared/services/localization/localization_service.dart'; class LocalProfileComponentWidget extends StatefulWidget { const LocalProfileComponentWidget({super.key}); @@ -22,145 +18,115 @@ class LocalProfileComponentWidget extends StatefulWidget { } class _LocalProfileComponentWidgetState extends State { - late LocalProfileComponentModel _model; - - @override - void setState(VoidCallback callback) { - super.setState(callback); - callback(); - } - - @override - void initState() { - super.initState(); - _model = createModel(context, () => LocalProfileComponentModel()); - _model.setOnUpdate(onUpdate: () => safeSetState(() {})); - _model.setStateCallback = () => safeSetState(() {}); - - WidgetsBinding.instance.addPostFrameCallback((_) async { - bool initialized = false; - bool isDevLinked = _model.cliUUID.isNotEmpty; - if (!isDevLinked && !initialized) { - initialized = true; - await LocalizationService.processLocals(context).then((value) => value == true ? onUpdate() : null); - } - }); - } - - @override - void dispose() { - _model.maybeDispose(); - - super.dispose(); - } - - void onUpdate() async { - log('() => onUpdate()'); - await _model.getData(); - safeSetState(() {}); - } - @override Widget build(BuildContext context) { - final textScaler = MediaQuery.textScalerOf(context); - final double baseFontSize = 14.0; - final double scaledFontSize = baseFontSize * textScaler.scale(1); - final double limitedFontSize = scaledFontSize > 20 ? 12 : scaledFontSize; + return BlocProvider( + create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), + child: BlocBuilder( + builder: (context, state) { + final textScaler = MediaQuery.textScalerOf(context); + final double baseFontSize = 14.0; + final double scaledFontSize = baseFontSize * textScaler.scale(1); + final double limitedFontSize = scaledFontSize > 20 ? 12 : scaledFontSize; - return Container( - decoration: const BoxDecoration(), - child: Align( - alignment: const AlignmentDirectional(0.0, -1.0), - child: Material( - color: Colors.transparent, - elevation: 0.0, - child: Container( - width: double.infinity, - height: 119.0, - decoration: BoxDecoration( - color: FlutterFlowTheme.of(context).primary, - border: Border.all( - color: FlutterFlowTheme.of(context).primary, - ), - ), - child: Row( - mainAxisSize: MainAxisSize.max, - children: [ - Align( - alignment: const AlignmentDirectional(-1.0, 0.0), - child: Padding( - padding: const EdgeInsets.all(2.0), - child: InkWell( - splashColor: Colors.transparent, - focusColor: Colors.transparent, - hoverColor: Colors.transparent, - highlightColor: Colors.transparent, - onTap: () async { - await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); - await LocalizationService.processLocals(context).whenComplete(() => onUpdate()); - }, - child: ClipRRect( - borderRadius: BorderRadius.circular(200.0), - child: CachedNetworkImage( - imageBuilder: (context, imageProvider) => Container( - decoration: BoxDecoration( - image: DecorationImage( - image: imageProvider, - fit: BoxFit.cover, - ), - ), - ), - imageUrl: valueOrDefault( - 'https://freaccess.com.br/freaccess/Images/Clients/${_model.cliUUID}.png', - 'assets/images/home.png'), - width: 80.0, - height: 80.0, - fit: BoxFit.cover, - alignment: const Alignment(0.0, 0.0), - placeholder: (context, url) => Image.asset('assets/images/home.png'), - errorListener: (_) => Image.asset('assets/images/home.png'), - errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), - ), - )), - ), - ), - Expanded( - child: Tooltip( - message: valueOrDefault( - functions.convertToUppercase(_model.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', - ), + return Container( + decoration: const BoxDecoration(), + child: Align( + alignment: const AlignmentDirectional(0.0, -1.0), + child: Material( + color: Colors.transparent, + elevation: 0.0, + child: Container( + width: double.infinity, + height: 119.0, + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primary, + border: Border.all( + color: FlutterFlowTheme.of(context).primary, ), - child: Text( - valueOrDefault( - functions.convertToUppercase(_model.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', + ), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: const AlignmentDirectional(-1.0, 0.0), + child: Padding( + padding: const EdgeInsets.all(2.0), + child: InkWell( + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: () async { + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await LocalizationService.processLocals(context).whenComplete( + () async => context.read().add(LocalProfileEvent())); + }, + child: ClipRRect( + borderRadius: BorderRadius.circular(200.0), + child: CachedNetworkImage( + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + ), + ), + ), + imageUrl: valueOrDefault( + 'https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', + 'assets/images/home.png'), + width: 80.0, + height: 80.0, + fit: BoxFit.cover, + alignment: const Alignment(0.0, 0.0), + placeholder: (context, url) => Image.asset('assets/images/home.png'), + errorListener: (_) => Image.asset('assets/images/home.png'), + errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), + ), + )), ), ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Nunito', - color: FlutterFlowTheme.of(context).info, - fontSize: limitedFontSize, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + Expanded( + child: Tooltip( + message: valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), ), - ), + child: Text( + valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), + ), + ), + ), + ] + .divide(const SizedBox(width: 20.0)) + .addToStart(const SizedBox(width: 20.0)) + .addToEnd(const SizedBox(width: 20.0)), ), ), - ] - .divide(const SizedBox(width: 20.0)) - .addToStart(const SizedBox(width: 20.0)) - .addToEnd(const SizedBox(width: 20.0)), + ), ), - ), - ), + ); + }, ), ); } diff --git a/lib/components/organism_components/menu_component/menu_component_bloc.dart b/lib/components/organism_components/menu_component/menu_component_bloc.dart new file mode 100644 index 00000000..b5f7876e --- /dev/null +++ b/lib/components/organism_components/menu_component/menu_component_bloc.dart @@ -0,0 +1,103 @@ +import 'dart:developer'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/schema/enums/enums.dart'; +import 'package:hub/components/atomic_components/menu_button_item/menu_button_item_widget.dart'; +import 'package:hub/components/atomic_components/menu_card_item/menu_card_item.dart'; +import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; + +class MenuEvent {} + +class MenuState { + final List menuEntries; + final bool isGrid; + + MenuState({this.menuEntries = const [], this.isGrid = false}); + + MenuState copyWith({List? menuEntries, bool? isGrid}) { + return MenuState( + menuEntries: menuEntries ?? this.menuEntries, + isGrid: isGrid ?? this.isGrid, + ); + } +} + +class MenuBloc extends Bloc { + final MenuView style; + final MenuItem item; + final bool expandable; + final List menuOptions; + + MenuBloc({required this.style, required this.item, required this.expandable, required this.menuOptions}) : super(MenuState()) { + on((event, emit) async { + final entries = await generateMenuEntries(); + emit(state.copyWith(menuEntries: entries)); + }); + } + + Future> generateMenuEntries() async { + List entries = []; + Future addMenuEntry(IconData icon, String text, Function() action) async { + entries.add( + item == MenuItem.button + ? MenuButtonWidget(icon: icon, action: action, title: text) + : item == MenuItem.card + ? MenuCardItem(icon: icon, action: action, title: text) + : item == MenuItem.tile + ? MenuCardItem(icon: icon, action: action, title: text) + : null, + ); + return null; + } + + for (var opt in menuOptions) { + String? v = await LicenseHelper().g(opt.value); + log('Module: ${opt.value} - License: $v'); + switch (v) { + case 'VISIVEL': + await addMenuEntry(opt.icon, opt.name, () async { + await nav(opt.route); + }); + continue; + case 'DESABILITADO': + await addMenuEntry(opt.icon, opt.name, () async { + await DialogUnavailable.unavailableFeature(key.currentContext!); + }); + continue; + case 'INVISIVEL': + continue; + default: + continue; + } + } + + return entries; + } + + Future nav(String link) async { + log('Opening: $link'); + key.currentContext!.push(link, extra: { + kTransitionInfoKey: const TransitionInfo( + hasTransition: false, + transitionType: PageTransitionType.scale, + alignment: Alignment.bottomCenter, + ), + }); + } + + Future logout() async { + // Implement logout logic here + } + + Future settings() async { + // Implement settings navigation logic here + } + + Future about() async { + // Implement about navigation logic here + } +} diff --git a/lib/components/organism_components/menu_component/menu_component_model.dart b/lib/components/organism_components/menu_component/menu_component_model.dart deleted file mode 100644 index 2f3f66c9..00000000 --- a/lib/components/organism_components/menu_component/menu_component_model.dart +++ /dev/null @@ -1,175 +0,0 @@ -import 'dart:developer'; - -import 'package:flutter/material.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/atomic_components/menu_button_item/menu_button_item_widget.dart'; -import 'package:hub/components/atomic_components/menu_card_item/menu_card_item.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; -import 'package:hub/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart'; -import 'package:hub/components/organism_components/menu_component/menu_component_widget.dart'; -import 'package:hub/components/organism_components/menu_list_view_component/menu_list_view_component_model.dart'; -import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/extensions/dialog_extensions.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; -import 'package:hub/shared/services/authentication/authentication_service.dart'; -import 'package:material_symbols_icons/symbols.dart'; - -import '/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart'; -import 'menu_component_widget.dart' show MenuComponentWidget; - -class MenuComponentModel extends FlutterFlowModel { - final MenuView style; - final MenuItem item; - final bool expandable; - final List menuOptions; - - MenuComponentModel( - {required this.style, - required this.item, - required this.expandable, - required this.menuOptions}); - - bool isGrid = false; - - late MenuListViewComponentModel menuListViewComponentModel; - late MenuStaggeredViewComponentModel menuStaggeredViewComponentModel; - late VoidCallback safeSetState; - List menuEntries = []; - - @override - void initState(BuildContext context) { - menuListViewComponentModel = - createModel(context, () => MenuListViewComponentModel()); - menuStaggeredViewComponentModel = - createModel(context, () => MenuStaggeredViewComponentModel()); - } - - @override - void dispose() { - menuListViewComponentModel.dispose(); - menuStaggeredViewComponentModel.dispose(); - } - - Future> generateMenuEntries( - BuildContext context, MenuItem item, List options) async { - List entries = []; - Future addMenuEntry( - IconData icon, String text, Function() action) async { - entries.add( - item == MenuItem.button - ? MenuButtonWidget( - icon: icon, - action: action, - title: text, - safeSetState: safeSetState) - : item == MenuItem.card - ? MenuCardItem( - icon: icon, - action: action, - title: text, - safeSetState: safeSetState) - : item == MenuItem.tile - ? MenuCardItem( - icon: icon, - action: action, - title: text, - safeSetState: safeSetState) - : null, - ); - return null; - } - - for (var opt in options) { - String? v = await LicenseHelper().g(opt.value); - log('Module: ${opt.value} - License: $v'); - switch (v) { - case 'VISIVEL': - await addMenuEntry(opt.icon, opt.name, () async { - await open(context, opt.route); - }); - break; - case 'BLOQUEADO': - await addMenuEntry(opt.icon, opt.name, () async { - await DialogUnavailable.unavailableFeature(context); - }); - break; - case 'INVISIVEL': - break; - default: - break; - } - safeSetState(); - } - - return entries; - } - - Future open(BuildContext context, String link) async { - context.push( - link, - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } - - Future out(BuildContext context) async { - final String title = FFLocalizations.of(context).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - final String content = FFLocalizations.of(context).getVariableText( - ptText: 'Tem certeza que deseja sair?', - enText: 'Are you sure you want to logout?', - ); - showAlertDialog(context, title, content, - () async => await AuthenticationService.signOut(context)); - } - - Future Logout(BuildContext context) async { - final String title = FFLocalizations.of(context).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - final String content = FFLocalizations.of(context).getVariableText( - ptText: 'Tem certeza que deseja sair?', - enText: 'Are you sure you want to logout?', - ); - showAlertDialog(context, title, content, - () async => await AuthenticationService.signOut(context)); - } - - Future settings(BuildContext context) async { - context.push( - '/preferencesSettings', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } - - Future about(BuildContext context) async { - context.push( - '/aboutProperty', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - } -} diff --git a/lib/components/organism_components/menu_component/menu_component_widget.dart b/lib/components/organism_components/menu_component/menu_component_widget.dart index a687ba3f..6277c62a 100644 --- a/lib/components/organism_components/menu_component/menu_component_widget.dart +++ b/lib/components/organism_components/menu_component/menu_component_widget.dart @@ -1,78 +1,80 @@ +import 'package:hub/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/backend/schema/enums/enums.dart'; +import 'package:hub/components/organism_components/menu_component/menu_component_bloc.dart'; +import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; +import 'package:hub/shared/services/license/license_service.dart'; -import '/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart'; -import '/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart'; -import '/flutter_flow/flutter_flow_util.dart'; -import 'menu_component_model.dart'; +class MenuComponentWidget extends StatelessWidget { + final MenuView style; + final MenuItem item; + final bool expandable; + final List menuOptions; -export 'menu_component_model.dart'; - -class MenuComponentWidget extends StatefulWidget { - final MenuComponentModel model; - const MenuComponentWidget({super.key, required this.model}); - - @override - State createState() => _MenuComponentWidgetState(); -} - -class _MenuComponentWidgetState extends State { - @override - void setState(VoidCallback callback) { - super.setState(callback); - widget.model.onUpdate(); - } - - @override - void initState() { - super.initState(); - widget.model.safeSetState = () => safeSetState(() {}); - } - - @override - void didChangeDependencies() async { - super.didChangeDependencies(); - widget.model.menuEntries = await widget.model.generateMenuEntries( - context, widget.model.item, widget.model.menuOptions); - } - - @override - void dispose() { - widget.model.maybeDispose(); - super.dispose(); - } + const MenuComponentWidget({ + super.key, + required this.style, + required this.item, + required this.expandable, + required this.menuOptions, + }); @override Widget build(BuildContext context) { - return Builder( - builder: (context) { - if (widget.model.style == MenuView.list_grid) - return wrapWithModel( - model: widget.model.menuStaggeredViewComponentModel, - updateCallback: () => setState(() {}), - updateOnChange: true, - child: MenuStaggeredViewComponentWidget( - options: widget.model.menuEntries, - expandable: widget.model.expandable, - item: widget.model.item, - changeMenuStyle: () async {}, - isGrid: widget.model.isGrid, + return StreamBuilder>( + stream: LicenseService().licenseStream, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center( + child: CircularProgressIndicator(), + ); + } else if (snapshot.hasError) { + return Center( + child: Text('Error: ${snapshot.error}'), + ); + } else if (!snapshot.hasData || snapshot.data!.isEmpty) { + return Center( + child: Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), + child: CircularProgressIndicator( + backgroundColor: FlutterFlowTheme.of(key.currentContext!).primaryBackground, + color: FlutterFlowTheme.of(key.currentContext!).primary), ), ); - if (widget.model.style == MenuView.list) - return wrapWithModel( - model: widget.model.menuListViewComponentModel, - updateCallback: () => setState(() {}), - updateOnChange: true, - child: MenuListViewComponentWidget( - options: widget.model.menuEntries, - expandable: widget.model.expandable, - item: widget.model.item, - changeMenuStyle: () async {}, - ), - ); - - return const SizedBox(); + } + return BlocProvider( + create: (context) => MenuBloc( + style: style, + item: item, + expandable: expandable, + menuOptions: menuOptions, + )..add(MenuEvent()), + child: BlocBuilder( + builder: (context, state) { + if (style == MenuView.list_grid) { + return MenuStaggeredViewComponentWidget( + options: state.menuEntries, + expandable: expandable, + item: item, + changeMenuStyle: () async {}, + isGrid: state.isGrid, + ); + } else if (style == MenuView.list) { + return MenuListViewComponentWidget( + options: state.menuEntries, + expandable: expandable, + item: item, + changeMenuStyle: () async {}, + ); + } + return const SizedBox(); + }, + ), + ); }, ); } 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 67f2947d..746a34fe 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 @@ -4,7 +4,6 @@ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel { late final String devUUID; late final String userUUID; 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 d28b326c..114242ef 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 @@ -3,7 +3,6 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'access_notification_modal_template_component_widget.dart' show AccessNotificationModalTemplateComponentWidget; 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 d79132e3..0e52975f 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 @@ -6,7 +6,6 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/flutter_flow/flutter_flow_widgets.dart'; diff --git a/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart b/lib/components/templates_components/provisional_schedule_template/provisional_schedule_template_model.dart index 7a214573..b57237ad 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:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - class ScheduleProvisionalVisitPageModel extends FlutterFlowModel { String cliUUID = ''; String devUUID = ''; 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 2a2aa5e6..58ea89e5 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 @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'view_visit_detail_widget.dart' show ViewVisitDetailWidget; 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 ff8624ea..ab8f9fc4 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 @@ -5,7 +5,6 @@ import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel { late final String devUUID; late final String userUUID; diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 6ff6dd73..112dfc6c 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -11,7 +11,7 @@ import 'package:hub/pages/acess_history_page/acess_history_page_widget.dart'; import 'package:hub/pages/delivery_schedule_page/delivery_schedule_widget.dart'; import 'package:hub/pages/fast_pass_page/fast_pass_page_widget.dart'; import 'package:hub/pages/forgot_password_page/forgot_password_screen.dart'; -import 'package:hub/pages/home_page/home_page_widget.dart'; +import 'package:hub/pages/home_page/home_page.dart'; import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; import 'package:hub/pages/message_history_page/message_history_page_widget.dart'; import 'package:hub/pages/package_order_page/package_order_page.dart'; @@ -24,6 +24,7 @@ import 'package:hub/pages/qr_code_page/qr_code_page_widget.dart'; import 'package:hub/pages/reception_page/reception_page_widget.dart'; import 'package:hub/pages/register_visitor_page/register_visitor_page_widget.dart'; import 'package:hub/pages/reservation_page/reservation_page_widget.dart'; +import 'package:hub/pages/residents_on_the_property/residents_on_the_property_screen.dart'; import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart'; import 'package:hub/pages/sign_in_page/sign_in_page_widget.dart'; import 'package:hub/pages/sign_up_page/sign_up_page_widget.dart'; @@ -84,25 +85,13 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { builder: (context, _) { return FutureBuilder( future: () async { - final bool isLogged = - await StorageHelper().g(SecureStorageKey.isLogged.value) == - 'true'; - final bool haveLocal = - await StorageHelper().g(SecureStorageKey.haveLocal.value) == - 'true'; - final bool haveUserUUID = - (await StorageHelper().g(KeychainStorageKey.userUUID.value)) - ?.isNotEmpty ?? - false; - final bool haveDevUUID = - (await StorageHelper().g(KeychainStorageKey.devUUID.value)) - ?.isNotEmpty ?? - false; + final bool isLogged = await StorageHelper().g(SecureStorageKey.isLogged.value) == 'true'; + final bool haveLocal = await StorageHelper().g(SecureStorageKey.haveLocal.value) == 'true'; + final bool haveUserUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value))?.isNotEmpty ?? false; + final bool haveDevUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value))?.isNotEmpty ?? false; if (isLogged && haveDevUUID && haveUserUUID) { - return haveLocal - ? const HomePageWidget() - : const ReceptionPageWidget(); + return haveLocal ? const HomePageWidget() : const ReceptionPageWidget(); } else { return const WelcomePageWidget(); } @@ -124,10 +113,8 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { name: 'forgotPassword', path: '/forgotPassword', builder: (context, params) { - late final String email = - params.getParam('email', ParamType.String); - late final String token = - params.getParam('token', ParamType.String); + late final String email = params.getParam('email', ParamType.String); + late final String token = params.getParam('token', ParamType.String); return ForgotPasswordScreen( key: UniqueKey(), @@ -135,100 +122,32 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { token: token, ); }), - FFRoute( - name: 'homePage', - path: '/homePage', - builder: (context, params) => HomePageWidget(key: UniqueKey())), - FFRoute( - name: 'petsOnThePropertyPage', - path: '/petsOnThePropertyPage', - builder: (context, params) => - Scaffold(body: const PetsHistoryScreen(isApp: true))), - FFRoute( - name: 'vehiclesOnThePropertyPage', - path: '/vehiclesOnThePropertyPage', - builder: (context, params) => const VehicleOnTheProperty()), - FFRoute( - name: 'receptionPage', - path: '/receptionPage', - builder: (context, params) => const ReceptionPageWidget()), - FFRoute( - name: 'messageHistoryPage', - path: '/messageHistoryPage', - builder: (context, params) => const MessageHistoryPageWidget()), - FFRoute( - name: 'registerVisitorPage', - path: '/registerVisitorPage', - builder: (context, params) => const RegisterVisitorPageWidget()), - FFRoute( - name: 'scheduleCompleteVisitPage', - path: '/scheduleCompleteVisitPage', - builder: (context, params) => - const ScheduleCompleteVisitPageWidget()), - FFRoute( - name: 'deliverySchedule', - path: '/deliverySchedule', - builder: (context, params) => const DeliverySchedule()), - FFRoute( - name: 'provisionalSchedule', - path: '/provisionalSchedule', - builder: (context, params) => const ProvisionalSchedule()), - FFRoute( - name: 'fastPassPage', - path: '/fastPassPage', - builder: (context, params) => /*const*/ FastPassPageWidget()), - FFRoute( - name: 'preferencesSettings', - path: '/preferencesSettings', - builder: (context, params) => PreferencesPageWidget()), - FFRoute( - name: 'aboutProperty', - path: '/aboutProperty', - builder: (context, params) => AboutPropertyPage()), - FFRoute( - name: 'peopleOnThePropertyPage', - path: '/peopleOnThePropertyPage', - builder: (context, params) => PeopleOnThePropertyPage()), + FFRoute(name: 'homePage', path: '/homePage', builder: (context, params) => HomePageWidget(key: UniqueKey())), + FFRoute(name: 'petsOnThePropertyPage', path: '/petsOnThePropertyPage', builder: (context, params) => Scaffold(body: const PetsHistoryScreen(isApp: true))), + FFRoute(name: 'vehiclesOnThePropertyPage', path: '/vehiclesOnThePropertyPage', builder: (context, params) => const VehicleOnTheProperty()), + FFRoute(name: 'receptionPage', path: '/receptionPage', builder: (context, params) => const ReceptionPageWidget()), + FFRoute(name: 'messageHistoryPage', path: '/messageHistoryPage', builder: (context, params) => const MessageHistoryPageWidget()), + FFRoute(name: 'registerVisitorPage', path: '/registerVisitorPage', builder: (context, params) => const RegisterVisitorPageWidget()), + FFRoute(name: 'scheduleCompleteVisitPage', path: '/scheduleCompleteVisitPage', builder: (context, params) => const ScheduleCompleteVisitPageWidget()), + FFRoute(name: 'deliverySchedule', path: '/deliverySchedule', builder: (context, params) => const DeliverySchedule()), + FFRoute(name: 'provisionalSchedule', path: '/provisionalSchedule', builder: (context, params) => const ProvisionalSchedule()), + FFRoute(name: 'fastPassPage', path: '/fastPassPage', builder: (context, params) => /*const*/ FastPassPageWidget()), + FFRoute(name: 'preferencesSettings', path: '/preferencesSettings', builder: (context, params) => PreferencesPageWidget()), + FFRoute(name: 'aboutProperty', path: '/aboutProperty', builder: (context, params) => AboutPropertyPage()), + FFRoute(name: 'residentsOnThePropertyPage', path: '/residentsOnThePropertyPage', builder: (context, params) => ResidentsOnTheProperty()), + FFRoute(name: 'peopleOnThePropertyPage', path: '/peopleOnThePropertyPage', builder: (context, params) => PeopleOnThePropertyPage()), FFRoute( name: 'acessHistoryPage', path: '/acessHistoryPage', - builder: (context, params) => AccessHistoryScreen(opt: const { - 'personType': '.*', - 'accessType': '.*', - 'search': '.*' - })), - FFRoute( - name: 'liberationHistory', - path: '/liberationHistory', - builder: (context, params) => const LiberationHistoryWidget()), - FFRoute( - name: 'signInPage', - path: '/signInPage', - builder: (context, params) => const SignInPageWidget()), - FFRoute( - name: 'signUpPage', - path: '/signUpPage', - builder: (context, params) => const SignUpPageWidget()), - FFRoute( - name: 'welcomePage', - path: '/welcomePage', - builder: (context, params) => const WelcomePageWidget()), - FFRoute( - name: 'qrCodePage', - path: '/qrCodePage', - builder: (context, params) => const QrCodePageWidget()), - FFRoute( - name: 'preferencesPage', - path: '/preferencesPage', - builder: (context, params) => PreferencesPageWidget()), - FFRoute( - name: 'packageOrder', - path: '/packageOrder', - builder: (context, params) => const PackageOrderPage()), - FFRoute( - name: 'reservation', - path: '/reservation', - builder: (context, params) => ReservationPageWidget()), + builder: (context, params) => AccessHistoryScreen(opt: const {'personType': '.*', 'accessType': '.*', 'search': '.*'})), + FFRoute(name: 'liberationHistory', path: '/liberationHistory', builder: (context, params) => const LiberationHistoryWidget()), + FFRoute(name: 'signInPage', path: '/signInPage', builder: (context, params) => const SignInPageWidget()), + FFRoute(name: 'signUpPage', path: '/signUpPage', builder: (context, params) => const SignUpPageWidget()), + FFRoute(name: 'welcomePage', path: '/welcomePage', builder: (context, params) => const WelcomePageWidget()), + FFRoute(name: 'qrCodePage', path: '/qrCodePage', builder: (context, params) => const QrCodePageWidget()), + FFRoute(name: 'preferencesPage', path: '/preferencesPage', builder: (context, params) => PreferencesPageWidget()), + FFRoute(name: 'packageOrder', path: '/packageOrder', builder: (context, params) => const PackageOrderPage()), + FFRoute(name: 'reservation', path: '/reservation', builder: (context, params) => ReservationPageWidget()), FFRoute( name: 'petsPage', path: '/petsPage', @@ -244,9 +163,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { extension NavParamExtensions on Map { Map get withoutNulls => Map.fromEntries( - entries - .where((e) => e.value != null) - .map((e) => MapEntry(e.key, e.value!)), + entries.where((e) => e.value != null).map((e) => MapEntry(e.key, e.value!)), ); } @@ -260,23 +177,18 @@ extension NavigationExtensions on BuildContext { } extension _GoRouterStateExtensions on GoRouterState { - Map get extraMap => - extra != null ? extra as Map : {}; + Map get extraMap => extra != null ? extra as Map : {}; Map get allParams => {} ..addAll(pathParameters) ..addAll(uri.queryParameters) ..addAll(extraMap); - TransitionInfo get transitionInfo => extraMap.containsKey(kTransitionInfoKey) - ? extraMap[kTransitionInfoKey] as TransitionInfo - : TransitionInfo.appDefault(); + TransitionInfo get transitionInfo => extraMap.containsKey(kTransitionInfoKey) ? extraMap[kTransitionInfoKey] as TransitionInfo : TransitionInfo.appDefault(); } extension GoRouterLocationExtension on GoRouter { String getCurrentLocation() { final RouteMatch lastMatch = routerDelegate.currentConfiguration.last; - final RouteMatchList matchList = lastMatch is ImperativeRouteMatch - ? lastMatch.matches - : routerDelegate.currentConfiguration; + final RouteMatchList matchList = lastMatch is ImperativeRouteMatch ? lastMatch.matches : routerDelegate.currentConfiguration; return matchList.uri.toString(); } } @@ -288,18 +200,13 @@ class FFParameters { final Map Function(String)> asyncParams; Map futureParamValues = {}; - bool get isEmpty => - state.allParams.isEmpty || - (state.allParams.length == 1 && - state.extraMap.containsKey(kTransitionInfoKey)); - bool isAsyncParam(MapEntry param) => - asyncParams.containsKey(param.key) && param.value is String; + bool get isEmpty => state.allParams.isEmpty || (state.allParams.length == 1 && state.extraMap.containsKey(kTransitionInfoKey)); + bool isAsyncParam(MapEntry param) => asyncParams.containsKey(param.key) && param.value is String; bool get hasFutures => state.allParams.entries.any(isAsyncParam); Future completeFutures() => Future.wait( state.allParams.entries.where(isAsyncParam).map( (param) async { - final doc = await asyncParams[param.key]!(param.value) - .onError((_, __) => null); + final doc = await asyncParams[param.key]!(param.value).onError((_, __) => null); if (doc != null) { futureParamValues[param.key] = doc; return true; @@ -309,15 +216,12 @@ class FFParameters { ), ).onError((_, __) => [false]).then((v) => v.every((e) => e)); - dynamic getParam(String paramName, ParamType type, - {bool isList = false, StructBuilder? structBuilder}) { - if (futureParamValues.containsKey(paramName)) - return futureParamValues[paramName]; + dynamic getParam(String paramName, ParamType type, {bool isList = false, StructBuilder? structBuilder}) { + if (futureParamValues.containsKey(paramName)) return futureParamValues[paramName]; if (!state.allParams.containsKey(paramName)) return null; final param = state.allParams[paramName]; if (param is! String) return param; - return deserializeParam(param, type, isList, - structBuilder: structBuilder); + return deserializeParam(param, type, isList, structBuilder: structBuilder); } } @@ -357,16 +261,13 @@ class FFRoute { key: state.pageKey, child: child, transitionDuration: transitionInfo.duration, - transitionsBuilder: - (context, animation, secondaryAnimation, child) => - PageTransition( + transitionsBuilder: (context, animation, secondaryAnimation, child) => PageTransition( type: transitionInfo.transitionType, duration: transitionInfo.duration, reverseDuration: transitionInfo.duration, alignment: transitionInfo.alignment, child: child, - ).buildTransitions( - context, animation, secondaryAnimation, child), + ).buildTransitions(context, animation, secondaryAnimation, child), ) : MaterialPage(key: state.pageKey, child: child); }, @@ -387,8 +288,7 @@ class TransitionInfo { final Duration duration; final Alignment? alignment; - static TransitionInfo appDefault() => - const TransitionInfo(hasTransition: false); + static TransitionInfo appDefault() => const TransitionInfo(hasTransition: false); } class RootPageContext { @@ -400,11 +300,8 @@ class RootPageContext { final rootPageContext = context.read(); final isRootPage = rootPageContext?.isRootPage ?? false; final location = GoRouterState.of(context).uri.toString(); - return isRootPage && - location != '/' && - location != rootPageContext?.errorRoute; + return isRootPage && location != '/' && location != rootPageContext?.errorRoute; } - static Widget wrap(Widget child, {String? errorRoute}) => - Provider.value(value: RootPageContext(true, errorRoute), child: child); + static Widget wrap(Widget child, {String? errorRoute}) => Provider.value(value: RootPageContext(true, errorRoute), child: child); } diff --git a/lib/index.dart b/lib/index.dart index 73ea1557..bfe5bac8 100644 --- a/lib/index.dart +++ b/lib/index.dart @@ -1,12 +1,11 @@ export 'pages/acess_history_page/acess_history_page_widget.dart' show AccessHistoryScreen; -export 'pages/home_page/home_page_widget.dart' show HomePageWidget; +export 'pages/home_page/home_page.dart' show HomePageWidget; export 'pages/liberation_history/liberation_history_widget.dart' show LiberationHistoryWidget; -export 'pages/people_on_the_property_page/people_on_the_property_page_widget.dart' show PeopleOnThePropertyPageWidget; +export 'pages/people_on_the_property_page/people_on_the_property_page_widget.dart' show PeopleOnThePropertyPage; export 'pages/preferences_settings_page/preferences_settings_widget.dart' show PreferencesPageWidget; export 'pages/qr_code_page/qr_code_page_widget.dart' show QrCodePageWidget; export 'pages/register_visitor_page/register_visitor_page_widget.dart' show RegisterVisitorPageWidget; -export 'pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart' - show ScheduleCompleteVisitPageWidget; +export 'pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart' show ScheduleCompleteVisitPageWidget; export 'pages/sign_in_page/sign_in_page_widget.dart' show SignInPageWidget; export 'pages/sign_up_page/sign_up_page_widget.dart' show SignUpPageWidget; export 'pages/welcome_page/welcome_page_widget.dart' show WelcomePageWidget; diff --git a/lib/main.dart b/lib/main.dart index 16354664..ba520190 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -62,8 +62,7 @@ class App extends StatefulWidget { @override State createState() => _AppState(); - static _AppState of(BuildContext context) => - context.findAncestorStateOfType<_AppState>()!; + static _AppState of(BuildContext context) => context.findAncestorStateOfType<_AppState>()!; } class _AppState extends State with WidgetsBindingObserver { @@ -105,8 +104,7 @@ class _AppState extends State with WidgetsBindingObserver { }), ), ); - final Iterable>? localizationsDelegates = - const [ + final Iterable>? localizationsDelegates = const [ FFLocalizationsDelegate(), GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, @@ -148,8 +146,7 @@ class _AppState extends State with WidgetsBindingObserver { await StorageHelper().s(SecureStorageKey.haveLocal.value, true); log('onMessageOpenedApp'); } else { - onMessageReceived(message.data, message.notification!.body, - message.data['click_action']); + onMessageReceived(message.data, message.notification!.body, message.data['click_action']); } }); FirebaseMessaging.instance.getInitialMessage().then((message) async { diff --git a/lib/pages/about_property_page/about_property_model.dart b/lib/pages/about_property_page/about_property_model.dart index df559059..aefdc762 100644 --- a/lib/pages/about_property_page/about_property_model.dart +++ b/lib/pages/about_property_page/about_property_model.dart @@ -1,40 +1,20 @@ import 'package:flutter/material.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; -import 'package:hub/components/organism_components/menu_component/menu_component_model.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/about_property_page/about_property_screen.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; class AboutPropertyModel extends FlutterFlowModel { dynamic item; VoidCallback? safeSetState; - late MenuComponentModel menuComponentModel; - Future initAsync() async { safeSetState?.call(); } @override void initState(BuildContext context) { - menuComponentModel = createModel( - context, - () => MenuComponentModel( - expandable: true, - style: MenuView.list_grid, - item: MenuItem.button, - menuOptions: [ - Module.pets, - Module.residents, - Module.openedVisits, - Module.vehicles, - Module.orders, - ])); - initAsync(); } diff --git a/lib/pages/about_property_page/about_property_screen.dart b/lib/pages/about_property_page/about_property_screen.dart index 9a80615a..f36f7e97 100644 --- a/lib/pages/about_property_page/about_property_screen.dart +++ b/lib/pages/about_property_page/about_property_screen.dart @@ -1,5 +1,6 @@ // ignore: must_be_immutable import 'package:flutter/material.dart'; +import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/appbar.dart'; import 'package:hub/components/organism_components/menu_component/menu_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; @@ -7,6 +8,31 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/about_property_page/about_property_model.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; + +enum AboutPropertyModules { + residents, + vehicles, + openedVisits, + petsHistory, +} + +extension AboutPropertyModulesExtension on AboutPropertyModules { + String get value { + switch (this) { + case AboutPropertyModules.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case AboutPropertyModules.vehicles: + return 'FRE-HUB-VEHICLES'; + case AboutPropertyModules.residents: + return 'FRE-HUB-RESIDENTS'; + case AboutPropertyModules.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + default: + return ''; + } + } +} // ignore: must_be_immutable class AboutPropertyPage extends StatefulWidget { @@ -43,15 +69,11 @@ class _AboutPropertyPageState extends State with SingleTicker @override Widget build(BuildContext context) { - return Scaffold( - appBar: _buildAppBar(context), - backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - body: _buildBody(context)); + return Scaffold(appBar: _buildAppBar(context), backgroundColor: FlutterFlowTheme.of(context).primaryBackground, body: _buildBody(context)); } PreferredSizeWidget _buildAppBar(BuildContext context) { - final String title = - FFLocalizations.of(context).getVariableText(ptText: "Sobre a Propriedade", enText: "About the Property"); + final String title = FFLocalizations.of(context).getVariableText(ptText: "Sobre a Propriedade", enText: "About the Property"); return AppBarUtil( title: title, onBackButtonPressed: () => context.pop(), @@ -62,14 +84,13 @@ class _AboutPropertyPageState extends State with SingleTicker return SingleChildScrollView( child: Container( color: FlutterFlowTheme.of(context).primaryBackground, - child: wrapWithModel( - model: _model.menuComponentModel, - updateCallback: () => setState(() {}), - child: Padding( - padding: EdgeInsets.only(bottom: 40), - child: MenuComponentWidget(model: _model.menuComponentModel), - ), - ), + child: MenuComponentWidget(expandable: true, style: MenuView.list_grid, item: MenuItem.button, menuOptions: [ + Module.pets, + Module.residents, + Module.openedVisits, + Module.vehicles, + Module.orders, + ]), ), ); } 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 3bd7ff88..98a33bf6 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/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - class AcessHistoryPageModel extends FlutterFlowModel { late final String devUUID; late final String userUUID; diff --git a/lib/pages/home_page/home_bloc.dart b/lib/pages/home_page/home_bloc.dart new file mode 100644 index 00000000..b92d32b3 --- /dev/null +++ b/lib/pages/home_page/home_bloc.dart @@ -0,0 +1,25 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + +import 'index.dart'; + +class HomeBloc extends Bloc { + HomeBloc() : super(HomeState()) { + on((event, emit) async { + final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final userName = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; + final userEmail = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; + + emit(state.copyWith( + devUUID: devUUID, + userUUID: userUUID, + cliUUID: cliUUID, + userName: userName, + userEmail: userEmail, + )); + }); + } +} diff --git a/lib/pages/home_page/home_events.dart b/lib/pages/home_page/home_events.dart new file mode 100644 index 00000000..bb0442c1 --- /dev/null +++ b/lib/pages/home_page/home_events.dart @@ -0,0 +1 @@ +class HomeEvent {} diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page.dart similarity index 69% rename from lib/pages/home_page/home_page_widget.dart rename to lib/pages/home_page/home_page.dart index 02deb34a..24516974 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page.dart @@ -1,15 +1,18 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/organism_components/local_profile_component/local_profile_component_widget.dart'; import 'package:hub/components/organism_components/menu_component/menu_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/pages/home_page/home_page_model.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; import 'package:hub/shared/widgets/drawer_widget/drawer_widget.dart'; +import 'index.dart'; + class HomePageWidget extends StatefulWidget { const HomePageWidget({super.key}); @@ -18,43 +21,21 @@ class HomePageWidget extends StatefulWidget { } class _HomePageWidgetState extends State { - late HomePageModel _model; final scaffoldKey = GlobalKey(); - late LocalProfileComponentWidget _localProfileComponentWidget; - - _HomePageWidgetState() { - _localProfileComponentWidget = LocalProfileComponentWidget(); - } - - @override - void dispose() { - super.dispose(); - _model.dispose(); - } - - @override - void initState() { - super.initState(); - - _model = createModel(context, () => HomePageModel(safeSetState: () => safeSetState(() {}))); - - _model.textController ??= TextEditingController(); - _model.textFieldFocusNode ??= FocusNode(); - } - @override Widget build(BuildContext context) { - StorageHelper().context = context; - return Scaffold( - key: scaffoldKey, - backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - // drawer: buildDrawer(context), - drawerEnableOpenDragGesture: true, - drawerDragStartBehavior: DragStartBehavior.start, - drawer: CustomDrawer(model: _model), - appBar: buildAppBar(context), - body: buildPage(context), + return BlocProvider( + create: (context) => HomeBloc()..add(HomeEvent()), + child: Scaffold( + key: scaffoldKey, + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + drawerEnableOpenDragGesture: true, + drawerDragStartBehavior: DragStartBehavior.start, + drawer: CustomDrawer(), + appBar: buildAppBar(context), + body: buildPage(context), + ), ); } @@ -139,25 +120,19 @@ class _HomePageWidgetState extends State { Widget buildBody() { return Container( color: FlutterFlowTheme.of(context).primaryBackground, - child: wrapWithModel( - model: _model.homeMenuComponentModel, - updateOnChange: true, - updateCallback: () => setState(() {}), - child: Padding( - padding: const EdgeInsets.only(bottom: 40), - child: MenuComponentWidget( - model: _model.homeMenuComponentModel, - ), + child: Padding( + padding: const EdgeInsets.only(bottom: 40), + child: MenuComponentWidget( + expandable: true, + style: MenuView.list_grid, + item: MenuItem.button, + menuOptions: Module.values.where((e) => e != Module.logout).toList(), ), ), ); } Widget buildLocal() { - return wrapWithModel( - model: _model.localComponentModel, - updateCallback: () => safeSetState(() {}), - child: _localProfileComponentWidget, - ); + return LocalProfileComponentWidget(); } } diff --git a/lib/pages/home_page/home_page_model.dart b/lib/pages/home_page/home_page_model.dart deleted file mode 100644 index e68faf34..00000000 --- a/lib/pages/home_page/home_page_model.dart +++ /dev/null @@ -1,105 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; -import 'package:hub/components/organism_components/local_profile_component/local_profile_component_model.dart'; -import 'package:hub/components/organism_components/menu_component/menu_component_model.dart'; -import 'package:hub/components/organism_components/message_well_component/message_well_component_model.dart'; -import 'package:hub/flutter_flow/flutter_flow_model.dart'; -import 'package:hub/pages/home_page/home_page_widget.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; - -class HomePageModel extends FlutterFlowModel { - HomePageModel({required this.safeSetState}); - late final VoidCallback safeSetState; - - bool isGrid = false; - late final String devUUID; - late final String cliUUID; - late final String userUUID; - late final String userName; - late final String userEmail; - - final unfocusNode = FocusNode(); - FocusNode? textFieldFocusNode; - TextEditingController? textController; - String? Function(BuildContext, String?)? textControllerValidator; - late LocalProfileComponentModel localComponentModel; - late MenuComponentModel homeMenuComponentModel; - late MenuComponentModel drawerMenuComponentModel; - late MessageWellComponentModel messageWellComponentModel; - - Future _initVariable() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = - (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = - (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - userName = - (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; - userEmail = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; - } - - @override - void initState(BuildContext context) { - _initVariable(); - localComponentModel = - createModel(context, () => LocalProfileComponentModel()); - homeMenuComponentModel = createModel( - context, - () => MenuComponentModel( - expandable: true, - style: MenuView.list_grid, - item: MenuItem.button, - menuOptions: [ - Module.messages, - Module.access, - Module.pets, - Module.openedVisits, - Module.reservations, - Module.orders, - Module.providerSchedule, - Module.deliverySchedule, - Module.completeSchedule, - Module.fastPass, - Module.liberations, - Module.qrCode, - Module.settings, - ])); - drawerMenuComponentModel = createModel( - context, - () => MenuComponentModel( - expandable: false, - style: MenuView.list, - item: MenuItem.tile, - menuOptions: [ - Module.messages, - Module.access, - Module.pets, - Module.openedVisits, - Module.reservations, - Module.orders, - Module.providerSchedule, - Module.deliverySchedule, - Module.completeSchedule, - Module.fastPass, - Module.liberations, - Module.qrCode, - Module.logout, - ])); - messageWellComponentModel = - createModel(context, () => MessageWellComponentModel()); - } - - @override - void dispose() { - unfocusNode.dispose(); - textFieldFocusNode?.dispose(); - textController?.dispose(); - - localComponentModel.dispose(); - homeMenuComponentModel.dispose(); - messageWellComponentModel.dispose(); - } -} diff --git a/lib/pages/home_page/home_state.dart b/lib/pages/home_page/home_state.dart new file mode 100644 index 00000000..b2a0c708 --- /dev/null +++ b/lib/pages/home_page/home_state.dart @@ -0,0 +1,35 @@ +class HomeState { + final bool isGrid; + final String devUUID; + final String cliUUID; + final String userUUID; + final String userName; + final String userEmail; + + HomeState({ + this.isGrid = false, + this.devUUID = '', + this.cliUUID = '', + this.userUUID = '', + this.userName = '', + this.userEmail = '', + }); + + HomeState copyWith({ + bool? isGrid, + String? devUUID, + String? cliUUID, + String? userUUID, + String? userName, + String? userEmail, + }) { + return HomeState( + isGrid: isGrid ?? this.isGrid, + devUUID: devUUID ?? this.devUUID, + cliUUID: cliUUID ?? this.cliUUID, + userUUID: userUUID ?? this.userUUID, + userName: userName ?? this.userName, + userEmail: userEmail ?? this.userEmail, + ); + } +} diff --git a/lib/pages/home_page/index.dart b/lib/pages/home_page/index.dart new file mode 100644 index 00000000..d06783d6 --- /dev/null +++ b/lib/pages/home_page/index.dart @@ -0,0 +1,3 @@ +export 'home_bloc.dart'; +export 'home_events.dart'; +export 'home_state.dart'; diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index 9b107572..7c64039a 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -6,7 +6,6 @@ import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; - class LiberationHistoryModel extends FlutterFlowModel { late final String devUUID; late final String userUUID; diff --git a/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart b/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart index d706d938..de07033f 100644 --- a/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart +++ b/lib/pages/people_on_the_property_page/people_on_the_property_page_model.dart @@ -1,28 +1,14 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/pages/people_on_the_property_page/people_on_the_property_page_widget.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; - class PeopleOnThePropertyPageModel extends FlutterFlowModel { - PeopleOnThePropertyPageModel({this.onRefresh}); - late final VoidCallback? onRefresh; + /// State fields for stateful widgets in this page. final unfocusNode = FocusNode(); - late final String devUUID; - late final String cliUUID; @override - void initState(BuildContext context) { - initVariables(); - } - - void initVariables() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - onRefresh?.call(); - } + void initState(BuildContext context) {} @override void dispose() { 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 be16c18d..a1146aeb 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 @@ -1,135 +1,68 @@ +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/people_on_the_property_page/people_on_the_property_page_model.dart'; -import 'package:hub/shared/utils/dialog_util.dart'; -import 'package:hub/shared/utils/limited_text_size.dart'; -import 'package:hub/shared/utils/log_util.dart'; + +import '../../shared/utils/log_util.dart'; class PeopleOnThePropertyPage extends StatefulWidget { const PeopleOnThePropertyPage({super.key}); @override - _PeopleOnThePropertyPageState createState() => _PeopleOnThePropertyPageState(); + State createState() => _PeopleOnThePropertyPageState(); } -class _PeopleOnThePropertyPageState extends State with TickerProviderStateMixin { - late ScrollController _scrollController; +class _PeopleOnThePropertyPageState extends State { + late PeopleOnThePropertyPageModel _model; - int _pageNumber = 1; - bool _hasData = false; - bool _loading = false; - int count = 0; - - late final PeopleOnThePropertyPageModel model; - - late Future _future; - List _wrap = []; + final scaffoldKey = GlobalKey(); @override void initState() { super.initState(); - model = createModel(context, () => PeopleOnThePropertyPageModel(onRefresh: () => safeSetState(() {}))); - _future = _fetchVisits(); - - _scrollController = ScrollController() - ..addListener(() { - if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { - _loadMore(); - } - }); + _model = createModel(context, () => PeopleOnThePropertyPageModel()); } @override void dispose() { - _scrollController.dispose(); + _model.dispose(); + super.dispose(); } @override Widget build(BuildContext context) { - late final limitedHeaderTextSize = LimitedFontSizeUtil.getHeaderFontSize(context); - return Scaffold( - appBar: _appBar(context), + key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - body: Column( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - if (_hasData == false && _pageNumber <= 1 && _loading == false) - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - Center( - child: Text( - FFLocalizations.of(context).getVariableText( - ptText: "Nenhum morador encontrado!", - enText: "No residents found!", - ), - style: TextStyle( - fontFamily: 'Nunito', - fontSize: limitedHeaderTextSize, - ), - ), - ) - ], - ), - ) - else if (_hasData == true || _pageNumber >= 1) - Expanded( - child: FutureBuilder( - future: _future, - builder: (context, snapshot) { - return ListView.builder( - shrinkWrap: true, - physics: const BouncingScrollPhysics(), - controller: _scrollController, - itemCount: _wrap.length + 1, - itemBuilder: (context, index) { - if (index == 0) { - // Add your item here - return Padding( - padding: const EdgeInsets.only(right: 30, top: 10), - child: Text( - '', - textAlign: TextAlign.right, - ), - ); - } else { - final item = _wrap[index - 1]; - return _item(context, item); - } - }); - }, - )), - if (_hasData == true && _loading == true) - Container( - padding: const EdgeInsets.only(top: 15, bottom: 15), - child: Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - FlutterFlowTheme.of(context).primary, - ), - ), - ), - ) - ].addToStart(const SizedBox(height: 0)), - ), - ); - } - - PreferredSizeWidget _appBar(BuildContext context) { - return AppBar( - backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - automaticallyImplyLeading: false, - title: Text(FFLocalizations.of(context).getVariableText(ptText: 'Moradores', enText: 'Residents'), + appBar: AppBar( + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + automaticallyImplyLeading: false, + forceMaterialTransparency: true, + leading: FlutterFlowIconButton( + borderColor: Colors.transparent, + borderRadius: 30.0, + borderWidth: 1.0, + buttonSize: 60.0, + icon: Icon( + Icons.keyboard_arrow_left, + color: FlutterFlowTheme.of(context).primaryText, + size: 30.0, + ), + onPressed: () async { + context.pop(); + }, + ), + title: Text( + FFLocalizations.of(context).getText( + 'nsu13r5d' /* Pessoas na Propriedade */, + ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).primaryText, @@ -137,114 +70,103 @@ class _PeopleOnThePropertyPageState extends State with letterSpacing: 0.0, fontWeight: FontWeight.bold, useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), - )), - leading: _backButton(context, FlutterFlowTheme.of(context)), - centerTitle: true, - elevation: 0.0, - actions: [], - ); - } - - Widget _backButton(BuildContext context, FlutterFlowTheme theme) { - return FlutterFlowIconButton( - borderColor: Colors.transparent, - borderRadius: 30.0, - borderWidth: 1.0, - buttonSize: 60.0, - icon: Icon( - Icons.keyboard_arrow_left, - color: theme.primaryText, - size: 30.0, - ), - onPressed: () => Navigator.of(context).pop(), - ); - } - - Future _fetchVisits() async { - try { - setState(() => _loading = true); - - var response = await PhpGroup.getResidentsByProperty.call(_pageNumber.toString()); - - final List residents = response.jsonBody['residents'] ?? []; - safeSetState(() => count = response.jsonBody['total_rows'] ?? 0); - - if (residents.isNotEmpty) { - setState(() { - _wrap.addAll(residents); - _hasData = true; - _loading = false; - }); - - return response; - } - - _showNoMoreDataSnackBar(context); - - setState(() { - _hasData = false; - _loading = false; - }); - - return null; - } catch (e, s) { - DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de moradores", e, s); - setState(() { - _hasData = false; - _loading = false; - }); - } - return null; - } - - void _loadMore() { - if (_hasData == true) { - _pageNumber++; - - _future = _fetchVisits(); - } - } - - void _showNoMoreDataSnackBar(BuildContext context) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - FFLocalizations.of(context).getVariableText( - ptText: "Não há mais dados.", - enText: "No more data.", - ), - style: TextStyle( - color: Colors.white, - fontSize: LimitedFontSizeUtil.getBodyFontSize(context), - ), + ), ), - duration: const Duration(seconds: 3), - backgroundColor: FlutterFlowTheme.of(context).primary, + actions: const [], + centerTitle: true, + elevation: 0.0, ), - ); - } - - Widget _item(BuildContext context, dynamic uItem) { - return CardItemTemplateComponentWidget( - imagePath: - 'https://freaccess.com.br/freaccess/getImage.php?devUUID=${model.devUUID}&cliID=${model.cliUUID}&atividade=getFoto&Documento=${uItem['documento']}&tipo=Z', - labelsHashMap: { - '${FFLocalizations.of(context).getVariableText(ptText: "Nome", enText: "Name")}:': uItem['nome'] ?? '', - //statusweb - '${FFLocalizations.of(context).getVariableText(ptText: "Possui App", enText: "Has App")}:': - uItem['statusweb'] == "A" - ? FFLocalizations.of(context).getVariableText( - ptText: 'Sim', - enText: 'Yes', - ) - : FFLocalizations.of(context).getVariableText( - ptText: 'Não', - enText: 'No', + body: SafeArea( + top: true, + child: FutureBuilder( + future: PhpGroup.getPessoasLocalCall.call(), + builder: (context, snapshot) { + // Customize what your widget looks like when it's loading. + if (!snapshot.hasData) { + return Center( + child: SizedBox( + width: 50.0, + height: 50.0, + child: SpinKitCircle( + color: FlutterFlowTheme.of(context).primary, + size: 50.0, ), - }, - statusHashMap: [], - onTapCardItemAction: () async {}, + ), + ); + } + + if (snapshot.hasError || snapshot.data?.exception != null) { + if (snapshot.error != null && snapshot.stackTrace != null) { + LogUtil.requestAPIFailed('getPessoasLocal.php', "", 'Busca Pessoas no Local', snapshot.error, snapshot.stackTrace!); + } + + return Center( + child: SizedBox( + width: double.infinity, + height: 100, + child: Text( + FFLocalizations.of(context).getVariableText(ptText: "Pessoas não encontradas", enText: "Persons not found"), + textAlign: TextAlign.center, + ), + ), + ); + } + + final columnGetPessoasLocalResponse = snapshot.data!; + final getPoepleProperty = PhpGroup.getPessoasLocalCall + .pessoas( + columnGetPessoasLocalResponse.jsonBody, + ) + ?.toList() ?? + []; + + return ListView.builder( + physics: const AlwaysScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: getPoepleProperty.length, + itemBuilder: (context, index) { + final getPoeplePropertyItem = getPoepleProperty[index]; + return Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.all(4.0), + child: Container( + width: 50.0, + height: 50.0, + clipBehavior: Clip.antiAlias, + decoration: const BoxDecoration( + shape: BoxShape.circle, + ), + child: CachedNetworkImage( + fadeInDuration: const Duration(milliseconds: 500), + fadeOutDuration: const Duration(milliseconds: 500), + imageUrl: + 'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg', + fit: BoxFit.cover, + ), + ), + ), + Text( + getJsonField( + getPoeplePropertyItem, + r'''$.USU_NOME''', + ).toString(), + style: FlutterFlowTheme.of(context).bodyMedium.override( + fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, + fontSize: 14.0, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).bodyMediumFamily), + ), + ), + ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 40.0)), + ); + }, + ); + }, + ), + ), ); } } diff --git a/lib/pages/residents_on_the_property/residents_on_the_property_model.dart b/lib/pages/residents_on_the_property/residents_on_the_property_model.dart new file mode 100644 index 00000000..e5f1f84c --- /dev/null +++ b/lib/pages/residents_on_the_property/residents_on_the_property_model.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/flutter_flow_model.dart'; +import 'package:hub/pages/residents_on_the_property/residents_on_the_property_screen.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + +class ResidentsOnThePropertyModel extends FlutterFlowModel { + ResidentsOnThePropertyModel({this.onRefresh}); + late final VoidCallback? onRefresh; + + final unfocusNode = FocusNode(); + late final String devUUID; + late final String cliUUID; + + @override + void initState(BuildContext context) { + initVariables(); + } + + void initVariables() async { + devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + onRefresh?.call(); + } + + @override + void dispose() { + unfocusNode.dispose(); + } +} diff --git a/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart new file mode 100644 index 00000000..fb3b4696 --- /dev/null +++ b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart @@ -0,0 +1,248 @@ +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; +import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/pages/residents_on_the_property/residents_on_the_property_model.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/limited_text_size.dart'; +import 'package:hub/shared/utils/log_util.dart'; + +class ResidentsOnTheProperty extends StatefulWidget { + const ResidentsOnTheProperty({super.key}); + + @override + _ResidentsOnThePropertyState createState() => _ResidentsOnThePropertyState(); +} + +class _ResidentsOnThePropertyState extends State with TickerProviderStateMixin { + late ScrollController _scrollController; + + int _pageNumber = 1; + bool _hasData = false; + bool _loading = false; + int count = 0; + + late final ResidentsOnThePropertyModel model; + + late Future _future; + List _wrap = []; + + @override + void initState() { + super.initState(); + model = createModel(context, () => ResidentsOnThePropertyModel(onRefresh: () => safeSetState(() {}))); + _future = _fetchVisits(); + + _scrollController = ScrollController() + ..addListener(() { + if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { + _loadMore(); + } + }); + } + + @override + void dispose() { + _scrollController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + late final limitedHeaderTextSize = LimitedFontSizeUtil.getHeaderFontSize(context); + + return Scaffold( + appBar: _appBar(context), + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + body: Column( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + if (_hasData == false && _pageNumber <= 1 && _loading == false) + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + children: [ + Center( + child: Text( + FFLocalizations.of(context).getVariableText( + ptText: "Nenhum morador encontrado!", + enText: "No residents found!", + ), + style: TextStyle( + fontFamily: 'Nunito', + fontSize: limitedHeaderTextSize, + ), + ), + ) + ], + ), + ) + else if (_hasData == true || _pageNumber >= 1) + Expanded( + child: FutureBuilder( + future: _future, + builder: (context, snapshot) { + return ListView.builder( + shrinkWrap: true, + physics: const BouncingScrollPhysics(), + controller: _scrollController, + itemCount: _wrap.length + 1, + itemBuilder: (context, index) { + if (index == 0) { + // Add your item here + return Padding( + padding: const EdgeInsets.only(right: 30, top: 10), + child: Text( + '', + textAlign: TextAlign.right, + ), + ); + } else { + final item = _wrap[index - 1]; + return _item(context, item); + } + }); + }, + )), + if (_hasData == true && _loading == true) + Container( + padding: const EdgeInsets.only(top: 15, bottom: 15), + child: Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + FlutterFlowTheme.of(context).primary, + ), + ), + ), + ) + ].addToStart(const SizedBox(height: 0)), + ), + ); + } + + PreferredSizeWidget _appBar(BuildContext context) { + return AppBar( + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + automaticallyImplyLeading: false, + title: Text(FFLocalizations.of(context).getVariableText(ptText: 'Moradores', enText: 'Residents'), + style: FlutterFlowTheme.of(context).headlineMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).primaryText, + fontSize: 15.0, + letterSpacing: 0.0, + fontWeight: FontWeight.bold, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + )), + leading: _backButton(context, FlutterFlowTheme.of(context)), + centerTitle: true, + elevation: 0.0, + actions: [], + ); + } + + Widget _backButton(BuildContext context, FlutterFlowTheme theme) { + return FlutterFlowIconButton( + borderColor: Colors.transparent, + borderRadius: 30.0, + borderWidth: 1.0, + buttonSize: 60.0, + icon: Icon( + Icons.keyboard_arrow_left, + color: theme.primaryText, + size: 30.0, + ), + onPressed: () => Navigator.of(context).pop(), + ); + } + + Future _fetchVisits() async { + try { + setState(() => _loading = true); + + var response = await PhpGroup.getResidentsByProperty.call(_pageNumber.toString()); + + final List residents = response.jsonBody['residents'] ?? []; + safeSetState(() => count = response.jsonBody['total_rows'] ?? 0); + + if (residents.isNotEmpty) { + setState(() { + _wrap.addAll(residents); + _hasData = true; + _loading = false; + }); + + return response; + } + + _showNoMoreDataSnackBar(context); + + setState(() { + _hasData = false; + _loading = false; + }); + + return null; + } catch (e, s) { + DialogUtil.errorDefault(context); + LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de moradores", e, s); + setState(() { + _hasData = false; + _loading = false; + }); + } + return null; + } + + void _loadMore() { + if (_hasData == true) { + _pageNumber++; + + _future = _fetchVisits(); + } + } + + void _showNoMoreDataSnackBar(BuildContext context) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + FFLocalizations.of(context).getVariableText( + ptText: "Não há mais dados.", + enText: "No more data.", + ), + style: TextStyle( + color: Colors.white, + fontSize: LimitedFontSizeUtil.getBodyFontSize(context), + ), + ), + duration: const Duration(seconds: 3), + backgroundColor: FlutterFlowTheme.of(context).primary, + ), + ); + } + + Widget _item(BuildContext context, dynamic uItem) { + return CardItemTemplateComponentWidget( + imagePath: 'https://freaccess.com.br/freaccess/getImage.php?devUUID=${model.devUUID}&cliID=${model.cliUUID}&atividade=getFoto&Documento=${uItem['documento']}&tipo=Z', + labelsHashMap: { + '${FFLocalizations.of(context).getVariableText(ptText: "Nome", enText: "Name")}:': uItem['nome'] ?? '', + //statusweb + '${FFLocalizations.of(context).getVariableText(ptText: "Possui App", enText: "Has App")}:': uItem['statusweb'] == "A" + ? FFLocalizations.of(context).getVariableText( + ptText: 'Sim', + enText: 'Yes', + ) + : FFLocalizations.of(context).getVariableText( + ptText: 'Não', + enText: 'No', + ), + }, + statusHashMap: [], + onTapCardItemAction: () async {}, + ); + } +} diff --git a/lib/shared/extensions/string_extensions.dart b/lib/shared/extensions/string_extensions.dart new file mode 100644 index 00000000..0538bb7c --- /dev/null +++ b/lib/shared/extensions/string_extensions.dart @@ -0,0 +1,11 @@ +extension StringNullableExtensions on String? { + bool toBoolean() { + return this!.toLowerCase() == 'true'; + } +} + +extension StringExtensions on String { + bool toBoolean() { + return this.toLowerCase() == 'true'; + } +} diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 0166e34c..1a9d1513 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -32,7 +32,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - await LicenseService.setupLicense(database); + await LicenseService().setupLicense(database); isInitialized = true; } @@ -42,14 +42,12 @@ class DatabaseStorage { await database.execute(LicenseHelper.createTableQuery); } - Future _onUpgrade( - Database database, int oldVersion, int newVersion) async { + Future _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2) { await database.execute(LicenseHelper.createTableQuery); } } - Future _onDowngrade( - Database database, int oldVersion, int newVersion) async {} + Future _onDowngrade(Database database, int oldVersion, int newVersion) async {} } diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index 827954b7..5a1f7dc7 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -10,6 +10,39 @@ enum InactiveModuleKey { residents, vehicles, openedVisits, + petsHistory, +} + +extension InactiveModuleKeyExtension on InactiveModuleKey { + String get value { + switch (this) { + case InactiveModuleKey.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case InactiveModuleKey.vehicles: + return 'FRE-HUB-VEHICLES'; + case InactiveModuleKey.residents: + return 'FRE-HUB-RESIDENTS'; + case InactiveModuleKey.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + default: + return ''; + } + } +} + +enum DisabledModuleKey { + fastPass, +} + +extension DisabledModuleKeyExtension on DisabledModuleKey { + String get value { + switch (this) { + case DisabledModuleKey.fastPass: + return 'FRE-HUB-FASTPASS'; + default: + return ''; + } + } } enum ActiveModuleKey { @@ -17,27 +50,16 @@ enum ActiveModuleKey { liberations, reservations, access, + pets, orders, completeSchedule, providerSchedule, deliverySchedule, - fastPass, qrCode, -} - -extension InactiveModuleKeyExtension on InactiveModuleKey { - String get value { - switch (this) { - case InactiveModuleKey.residents: - return 'FRE-HUB-RESIDENTS'; - case InactiveModuleKey.vehicles: - return 'FRE-HUB-VEHICLES'; - case InactiveModuleKey.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - default: - return ''; - } - } + visitors, + peopleOnTheProperty, + settings, + logout, } extension ActiveModuleKeyExtension on ActiveModuleKey { @@ -51,6 +73,8 @@ extension ActiveModuleKeyExtension on ActiveModuleKey { return 'FRE-HUB-RESERVATIONS'; case ActiveModuleKey.access: return 'FRE-HUB-ACCESS'; + case ActiveModuleKey.pets: + return 'FRE-HUB-PETS'; case ActiveModuleKey.orders: return 'FRE-HUB-ORDERS'; case ActiveModuleKey.completeSchedule: @@ -59,10 +83,12 @@ extension ActiveModuleKeyExtension on ActiveModuleKey { return 'FRE-HUB-AGE-PROV-PRESTADOR'; case ActiveModuleKey.deliverySchedule: return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ActiveModuleKey.fastPass: - return 'FRE-HUB-FASTPASS'; + case ActiveModuleKey.visitors: + return 'FRE-HUB-VISITORS'; case ActiveModuleKey.qrCode: return 'FRE-HUB-QRCODE'; + case ActiveModuleKey.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; default: return ''; } @@ -70,20 +96,24 @@ extension ActiveModuleKeyExtension on ActiveModuleKey { } enum Module { - messages, - liberations, - reservations, - access, - openedVisits, - vehicles, - residents, - pets, - orders, - completeSchedule, providerSchedule, deliverySchedule, fastPass, + completeSchedule, + orders, + reservations, + visitors, + vehicles, + residents, + openedVisits, qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + petsHistory, + peopleOnTheProperty, settings, logout, } @@ -115,10 +145,18 @@ extension LicenseKeyExtension on Module { return 'FRE-HUB-AGE-PROV-PRESTADOR'; case Module.deliverySchedule: return 'FRE-HUB-AGE-PROV-DELIVERY'; + case Module.aboutProperty: + return 'FRE-HUB-PROPERTY'; case Module.fastPass: return 'FRE-HUB-FASTPASS'; + case Module.visitors: + return 'FRE-HUB-VISITORS'; case Module.qrCode: return 'FRE-HUB-QRCODE'; + case Module.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + case Module.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; default: return ''; } @@ -128,13 +166,13 @@ extension LicenseKeyExtension on Module { switch (this) { case Module.messages: return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Mensagens', - enText: 'Messages', + ptText: 'Consultar Mensagens', + enText: 'Messages History', ); case Module.liberations: return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Liberar', - enText: 'Liberations', + ptText: 'Consultar Liberações', + enText: 'Liberations History', ); case Module.reservations: return FFLocalizations.of(key.currentContext!).getVariableText( @@ -143,12 +181,12 @@ extension LicenseKeyExtension on Module { ); case Module.access: return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Acessos', - enText: 'Access', + ptText: 'Consultar Acessos', + enText: 'Access History', ); case Module.openedVisits: return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Visitas Abertas', + ptText: 'Visitas em Aberto', enText: 'Opened Visits', ); case Module.vehicles: @@ -166,10 +204,20 @@ extension LicenseKeyExtension on Module { ptText: 'Pets', enText: 'Pets', ); + case Module.petsHistory: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case Module.peopleOnTheProperty: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); case Module.orders: return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Encomendas', - enText: 'Orders', + ptText: 'Minhas Encomendas', + enText: 'My Orders', ); case Module.completeSchedule: return FFLocalizations.of(key.currentContext!).getVariableText( @@ -193,8 +241,18 @@ extension LicenseKeyExtension on Module { ); case Module.qrCode: return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'QR Code', - enText: 'QR Code', + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case Module.visitors: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case Module.aboutProperty: + return FFLocalizations.of(key.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', ); case Module.settings: return FFLocalizations.of(key.currentContext!).getVariableText( @@ -212,33 +270,41 @@ extension LicenseKeyExtension on Module { IconData get icon { switch (this) { case Module.messages: - return Icons.message; + return Icons.chat_outlined; case Module.liberations: - return Icons.lock_open; + return Icons.how_to_reg_outlined; case Module.reservations: - return Icons.calendar_today; + return Icons.event_available; case Module.access: - return Icons.access_time; + return Icons.transfer_within_a_station_outlined; case Module.openedVisits: - return Icons.people; + return Icons.perm_contact_calendar; case Module.vehicles: return Icons.directions_car; case Module.residents: - return Icons.person; + return Icons.groups; case Module.pets: return Icons.pets; + case Module.petsHistory: + return Icons.pets; + case Module.peopleOnTheProperty: + return Icons.groups; case Module.orders: - return Icons.shopping_cart; + return Icons.inventory_2_outlined; case Module.completeSchedule: - return Icons.schedule; + return Icons.event; case Module.providerSchedule: return Icons.engineering_outlined; case Module.deliverySchedule: - return Icons.delivery_dining; + return Icons.sports_motorsports_outlined; case Module.fastPass: - return Icons.fastfood; + return Icons.attach_email_outlined; case Module.qrCode: return Icons.qr_code; + case Module.visitors: + return Icons.person_add_alt_1_outlined; + case Module.aboutProperty: + return Icons.home; case Module.settings: return Icons.settings; case Module.logout: @@ -257,23 +323,37 @@ extension LicenseKeyExtension on Module { case Module.access: return '/acessHistoryPage'; case Module.openedVisits: - return '/visitsOnTheProperty'; + return '/visitsOnThePropertyPage'; case Module.vehicles: return '/vehiclesOnThePropertyPage'; case Module.residents: - return '/peopleOnThePropertyPage'; + return '/residentsOnThePropertyPage'; case Module.pets: return '/petsPage'; + case Module.petsHistory: + return '/petsHistoryPage'; + case Module.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; case Module.orders: return '/packageOrder'; case Module.completeSchedule: return '/scheduleCompleteVisitPage'; case Module.providerSchedule: return '/provisionalSchedule'; + case Module.aboutProperty: + return '/aboutProperty'; case Module.deliverySchedule: return '/deliverySchedule'; case Module.fastPass: return '/fastPassPage'; + case Module.qrCode: + return '/qrCodePage'; + case Module.visitors: + return '/registerVisitorPage'; + case Module.settings: + return '/preferencesSettings'; + case Module.logout: + return '/WelcomePage'; default: return ''; } @@ -303,27 +383,19 @@ class LicenseHelper { await DatabaseStorage.instance.init(); } - static Future insertLicenseFoo( - final List key, final String display) async { + Future setByKey(final List key, final String display) async { for (var element in key) { - log('insertLicenseFoo($element, $display)'); - DatabaseStorage.database.insert( - tableLicense, - { - 'key': element, - 'display': display, - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }, - conflictAlgorithm: ConflictAlgorithm.ignore, - ); + await s(element, { + 'display': display, + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }); } } Future g(String key) async { - var response = await DatabaseStorage.database.query(tableLicense, - where: 'key = ?', whereArgs: [key], columns: ['display']); + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key], columns: ['display']); if (response.isEmpty) { return null; } @@ -347,8 +419,7 @@ class LicenseHelper { } Future d(String key) async { - await DatabaseStorage.database - .delete(tableLicense, where: 'key = ?', whereArgs: [key]); + await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); } Future c() async { diff --git a/lib/shared/helpers/storage/base_storage.dart b/lib/shared/helpers/storage/base_storage.dart index 972734bf..fa1d47c7 100644 --- a/lib/shared/helpers/storage/base_storage.dart +++ b/lib/shared/helpers/storage/base_storage.dart @@ -144,4 +144,3 @@ extension KeychainStorageKeyExtension on KeychainStorageKey { } } } - diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index e7116864..4ddd3587 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:sqflite/sqflite.dart'; @@ -30,8 +32,8 @@ class KeychainHelper implements BaseStorage { @override Future get(String key) async { - var response = await DatabaseStorage.database - .query(tableKeychain, where: 'key = ?', whereArgs: [key]); + log('KeychainHelper.get: $key'); + var response = await DatabaseStorage.database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; } @@ -56,8 +58,7 @@ class KeychainHelper implements BaseStorage { @override Future delete(String key) async { - await DatabaseStorage.database - .delete(tableKeychain, where: 'key = ?', whereArgs: [key]); + await DatabaseStorage.database.delete(tableKeychain, where: 'key = ?', whereArgs: [key]); } @override diff --git a/lib/shared/helpers/storage/storage_helper.dart b/lib/shared/helpers/storage/storage_helper.dart index f5536d4b..cb5a3e1b 100644 --- a/lib/shared/helpers/storage/storage_helper.dart +++ b/lib/shared/helpers/storage/storage_helper.dart @@ -22,12 +22,10 @@ class StorageHelper { await SharedPreferencesStorage.instance.init(); await KeychainHelper.instance.init(); - String? isFirstRun = await SharedPreferencesStorage.instance - .get(SharedPreferencesKey.isFirstRun.value); + String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value); if (isFirstRun != 'false') { - await SharedPreferencesStorage.instance - .set(SharedPreferencesKey.isFirstRun.value, false); + await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, false); await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); } } @@ -46,10 +44,7 @@ class StorageHelper { static BaseStorage getInstanceByKey(String key) { if (SecureStorageKey.values.map((e) => e.value).toList().contains(key)) { return SecureStorage.instance; - } else if (SharedPreferencesKey.values - .map((e) => e.value) - .toList() - .contains(key)) { + } else if (SharedPreferencesKey.values.map((e) => e.value).toList().contains(key)) { return SharedPreferencesStorage.instance; } else { return KeychainHelper.instance; diff --git a/lib/shared/services/deeplink/deep_link_service.dart b/lib/shared/services/deeplink/deep_link_service.dart index 42cf083d..f24c6093 100644 --- a/lib/shared/services/deeplink/deep_link_service.dart +++ b/lib/shared/services/deeplink/deep_link_service.dart @@ -63,8 +63,7 @@ class DeepLinkService { child: ForgotPasswordScreen(email: email, token: token), ), isScrollControlled: true, - backgroundColor: - FlutterFlowTheme.of(key.currentContext!).primaryBackground, + backgroundColor: FlutterFlowTheme.of(key.currentContext!).primaryBackground, showDragHandle: true, useSafeArea: true, enableDrag: true, diff --git a/lib/shared/services/keychain/keychain_service.dart b/lib/shared/services/keychain/keychain_service.dart index 13fa5ceb..a5497f9d 100644 --- a/lib/shared/services/keychain/keychain_service.dart +++ b/lib/shared/services/keychain/keychain_service.dart @@ -1,5 +1,3 @@ - - class KeychainService { static final KeychainService _instance = KeychainService._internal(); factory KeychainService() => _instance; diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index b9d6693a..57ba57f1 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -3,12 +3,11 @@ import 'dart:developer'; import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/pages/about_property_page/about_property_model.dart'; +import 'package:hub/pages/about_property_page/about_property_screen.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; - import 'package:hub/shared/helpers/license/license_helper.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; - +import 'package:rxdart/rxdart.dart'; import 'package:sqflite/sqflite.dart'; class LicenseService { @@ -16,32 +15,23 @@ class LicenseService { factory LicenseService() => _instance; LicenseService._internal(); - static Future setupLicense(Database database) async { - await LicenseHelper.insertLicenseFoo( - InactiveModuleKey.values.map((e) => e.value).toList(), 'INVISIVEL'); - await LicenseHelper.insertLicenseFoo( - ActiveModuleKey.values.map((e) => e.value).toList(), 'VISIVEL'); + final _licenseSubject = BehaviorSubject>(); + + Stream> get licenseStream => _licenseSubject.stream; + + Future cleanLicense() async { + _licenseSubject.add([]); } - static Future initLicenseService() async { - // for (var element in LicenseStorageKey.values.map((e) => e.value)) { - // await SQLiteStorage.database.insert( - // SQLiteStorage.tableLicense, - // { - // 'key': element, - // 'display': 'VISIVEL', - // 'expirationDate': '', - // 'startDate': '', - // 'quantity': '', - // }, - // conflictAlgorithm: ConflictAlgorithm.ignore, - // ); - // } + Future setupLicense(Database database) async { + final List inactiveModuleKey = InactiveModuleKey.values.map((e) => e.value).toList(); + final List activeModuleKey = ActiveModuleKey.values.map((e) => e.value).toList(); + await LicenseHelper().setByKey(inactiveModuleKey, 'INVISIVEL'); + await LicenseHelper().setByKey(activeModuleKey, 'VISIVEL'); + _licenseSubject.add([...activeModuleKey]); } - static Future processLicense() async {} - - static Future fetchLicenses() async { + Future fetchLicenses() async { try { log('Obtendo licenças...'); final response = await PhpGroup.getLicense(); @@ -60,7 +50,8 @@ class LicenseService { if (responseBody == []) { await setupLicense(DatabaseStorage.database); - return true; + _licenseSubject.add([]); + return false; } for (var element in responseBody) { @@ -68,11 +59,12 @@ class LicenseService { _saveModule(element); } } + _licenseSubject.add(responseBody); return true; } catch (e) { log('Erro ao obter licenças: $e'); await setupLicense(DatabaseStorage.database); - return true; + return false; } } @@ -81,15 +73,16 @@ class LicenseService { } static Future _saveModule(final dynamic body) async { - if (body is Map) + if (body is Map) { log('Salvando módulo: ${body.toString()}'); - // if (body is Map) await StorageHelper().s(body['key'], ''); - if (body is Map) await LicenseHelper().s(body['key'], body); - // StorageHelper.getInstance(Storage.SQLiteStorage).set(key, value); + log('body[key]: ${body['key']}'); + if (body['key'] == Module.pets.value) if (body['display'] == 'VISIVEL') { + await LicenseHelper().s(Module.petsHistory.value, body); + } + if (AboutPropertyModules.values.any((e) => e.value == body['key']) && body['display'] == 'VISIVEL') { + await LicenseHelper().s(Module.aboutProperty.value, body); + } + } } - - static Future updateLicense(final dynamic body) async {} - - static Future catchLicense() async {} } diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 019133fa..a53e2ba9 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -3,20 +3,21 @@ import 'dart:developer'; import 'package:flutter/material.dart'; -import 'package:hub/backend/api_requests/api_manager.dart'; +import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; + import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:hub/shared/services/license/license_service.dart'; import 'package:hub/shared/utils/dialog_util.dart'; - -import '../../../backend/api_requests/api_calls.dart'; -import '../../../components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart'; -import '../../../flutter_flow/flutter_flow_util.dart'; -import '../../utils/log_util.dart'; -import '../../utils/snackbar_util.dart'; -import '../authentication/authentication_service.dart'; +import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/shared/utils/snackbar_util.dart'; +import 'package:hub/shared/extensions/string_extensions.dart'; class LocalizationService { static Future checkLocals(BuildContext context) async { @@ -34,15 +35,13 @@ class LocalizationService { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg) - .whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return; } final List locals = response.jsonBody['locais'] ?? []; final bool isEmpty = locals.isEmpty; - final bool isActive = - locals.where((local) => local['CLU_STATUS'] != 'B').isNotEmpty; + final bool isActive = locals.where((local) => local['CLU_STATUS'] != 'B').isNotEmpty; final bool isEnable = !isEmpty && isActive; if (isEnable) { @@ -60,6 +59,7 @@ class LocalizationService { static Future processLocals(BuildContext context) async { try { + await LicenseService().cleanLicense(); final GetLocalsCall callback = PhpGroup.getLocalsCall; final ApiCallResponse response = await callback.call(); final bool? isError = response.jsonBody['error']; @@ -74,8 +74,7 @@ class LocalizationService { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg) - .whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } @@ -86,8 +85,7 @@ class LocalizationService { final bool isInactived = await _isInactived(locals); final bool isPending = _isPending(locals); final bool isUnique = locals.length == 1; - final bool isBlocked = - locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty; + final bool isBlocked = locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty; final bool isEnabled = isUnique && isActive; final bool isDisabled = isUnique && isBlocked; final bool isUnselected = await _isUnselected(); @@ -127,8 +125,7 @@ class LocalizationService { enText: 'Error getting locals, verify your connection', ptText: 'Erro ao obter locais, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg) - .whenComplete(() => selectLocal(context, null)); + await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); return false; } } @@ -143,8 +140,7 @@ class LocalizationService { final GetLocalsCall callback = PhpGroup.getLocalsCall; response = await callback.call(); final String errorMsg = response.jsonBody['error_msg']; - await DialogUtil.error(context, errorMsg) - .whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } else if (response.jsonBody == null) { final GetLocalsCall callback = PhpGroup.getLocalsCall; @@ -153,16 +149,18 @@ class LocalizationService { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg) - .whenComplete(() => selectLocal(context, response)); + await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } else { - // final bool isNewVersion = await _updateStorageUtil(response.jsonBody); - // if (!isNewVersion) { - await LicenseService.setupLicense(DatabaseStorage.database); + final bool isNewVersion = await _updateStorageUtil(response.jsonBody); + if (isNewVersion) { + return await LicenseService().fetchLicenses(); + } else { + await LicenseService().setupLicense(DatabaseStorage.database); + } + log('() => isNewVersion: $isNewVersion'); + return false; - // } - // return await LicenseService.fetchLicenses(); } } catch (e, s) { log('() => stack processData: $s'); @@ -171,14 +169,12 @@ class LocalizationService { enText: 'Error getting data, verify your connection', ptText: 'Erro ao obter dados, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg) - .whenComplete(() => selectLocal(context, null)); + await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); return false; } } - static Future selectLocal( - BuildContext context, ApiCallResponse? response) async { + static Future selectLocal(BuildContext context, ApiCallResponse? response) async { return await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, @@ -242,13 +238,10 @@ class LocalizationService { } static void _handleError(BuildContext context, String errorMsg) async { - final String devUUID = - await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; - final String userUUID = - await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; + final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; - final bool isDevLinked = - !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); + final bool isDevLinked = !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); log('() => isLinked: $errorMsg'); log('() => isLinked: $errorMsg'); if (!isAuthenticated) { @@ -268,20 +261,15 @@ class LocalizationService { await DialogUtil.warning(context, errorMsg); return; } - await DialogUtil.error(context, errorMsg) - .whenComplete(() async => await selectLocal(context, null)); + await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); } - static Future _handleUnavailable( - BuildContext context, List locals) async { + static Future _handleUnavailable(BuildContext context, List locals) async { log('() => isUnavailable'); try { - await StorageHelper() - .s(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); - await StorageHelper() - .s(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); - await StorageHelper() - .s(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); + await StorageHelper().s(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); + await StorageHelper().s(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); @@ -289,28 +277,21 @@ class LocalizationService { await StorageHelper().s(KeychainStorageKey.clientName.value, ''); return false; } - if (response.jsonBody['error'] == false) - return await processData(context).then((value) => value); + if (response.jsonBody['error'] == false) return await processData(context).then((value) => value); } catch (e, s) { await DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed( - 'responderVinculo.php', '', 'Responder Vínculo', e, s); + LogUtil.requestAPIFailed('responderVinculo.php', '', 'Responder Vínculo', e, s); return false; } return false; } - static Future _handleEnabled( - BuildContext context, dynamic local) async { + static Future _handleEnabled(BuildContext context, dynamic local) async { log('() => isEnabled'); - await StorageHelper() - .s(KeychainStorageKey.clientUUID.value, local['CLI_ID']); - await StorageHelper() - .s(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); - await StorageHelper() - .s(KeychainStorageKey.clientName.value, local['CLI_NOME']); - await StorageHelper() - .s(KeychainStorageKey.userName.value, local['USU_NOME']); + await StorageHelper().s(KeychainStorageKey.clientUUID.value, local['CLI_ID']); + await StorageHelper().s(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); + await StorageHelper().s(KeychainStorageKey.clientName.value, local['CLI_NOME']); + await StorageHelper().s(KeychainStorageKey.userName.value, local['USU_NOME']); return await processData(context); } @@ -322,24 +303,21 @@ class LocalizationService { } static Future _updateStorageUtil(Map jsonBody) async { - await StorageHelper().s(KeychainStorageKey.whatsapp.value, - jsonBody['whatsapp'] != null && jsonBody['whatsapp']); - await StorageHelper().s(KeychainStorageKey.provisional.value, - jsonBody['provisional'] != null && jsonBody['provisional']); - await StorageHelper().s(KeychainStorageKey.pets.value, - jsonBody['pet'] != null && jsonBody['pet']); - await StorageHelper().s( - KeychainStorageKey.petAmount.value, - jsonBody['petAmountRegister'] != null && - jsonBody['petAmountRegister'].toString().isEmpty - ? '0' - : jsonBody['petAmountRegister'].toString()); - await StorageHelper() - .s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); - await StorageHelper().s(KeychainStorageKey.isNewVersion.value, - jsonBody['newVersion'] != null && jsonBody['newVersion']); + await StorageHelper().s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp']); + await StorageHelper().s(KeychainStorageKey.provisional.value, jsonBody['provisional'] != null && jsonBody['provisional']); + await StorageHelper().s(KeychainStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet']); + await StorageHelper().s(KeychainStorageKey.petAmount.value, + jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString()); + await StorageHelper().s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); + + late final bool isNewVersion; + if (jsonBody['newVersion'] != null) + isNewVersion = jsonBody['newVersion']; + else + isNewVersion = false; log('() => isNewVersion: ${jsonBody['newVersion']}'); - return jsonBody['newVersion'] == true; + await StorageHelper().s(KeychainStorageKey.isNewVersion.value, isNewVersion); + return isNewVersion; } static bool _isActive(List locals) { @@ -347,44 +325,30 @@ class LocalizationService { } static Future _isInactived(List locals) async { - String cliUUID = - (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - return locals - .where( - (local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A') - .isNotEmpty; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; } static bool _isPending(List locals) { - return locals - .where( - (local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A') - .isNotEmpty; + return locals.where((local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A').isNotEmpty; } static Future _isUnselected() async { - String cliUUID = - (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = - (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - String ownerUUID = - (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + String ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; } static Future _isSelected(bool isInactived) async { - String cliUUID = - (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = - (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; } static Future _isAvailable() async { - String cliUUID = - (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = - (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty; } } diff --git a/lib/shared/widgets/drawer_widget/drawer_widget.dart b/lib/shared/widgets/drawer_widget/drawer_widget.dart index 0e43594b..ddd81a47 100644 --- a/lib/shared/widgets/drawer_widget/drawer_widget.dart +++ b/lib/shared/widgets/drawer_widget/drawer_widget.dart @@ -1,37 +1,70 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/organism_components/menu_component/menu_component_widget.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/pages/home_page/home_bloc.dart'; +import 'package:hub/pages/home_page/home_state.dart'; +import 'package:hub/shared/helpers/license/license_helper.dart'; +import 'package:hub/shared/services/license/license_service.dart'; class CustomDrawer extends StatelessWidget { - const CustomDrawer({super.key, required this.model}); - final HomePageModel model; + const CustomDrawer({super.key}); @override Widget build(BuildContext context) { - return SafeArea( - child: SizedBox( - width: MediaQuery.of(context).size.width * 0.8, - child: Drawer( - elevation: 16.0, - child: Container( - color: FlutterFlowTheme.of(context).primaryBackground, - child: Column( - children: [ - _buildDrawerHeader(context), - // _buildSearchBar(context), - _buildDrawerBody(), - ].addToStart(const SizedBox(height: 20)), + return StreamBuilder>( + stream: LicenseService().licenseStream, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center( + child: CircularProgressIndicator(), + ); + } else if (snapshot.hasError) { + return Center( + child: Text('Error: ${snapshot.error}'), + ); + } else if (!snapshot.hasData || snapshot.data!.isEmpty) { + return Center( + child: Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), + child: CircularProgressIndicator( + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + color: FlutterFlowTheme.of(context).primary, + ), ), - ), - ), - ), + ); + } + return BlocBuilder( + builder: (context, state) { + return SafeArea( + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.8, + child: Drawer( + elevation: 16.0, + child: Container( + color: FlutterFlowTheme.of(context).primaryBackground, + child: Column( + children: [ + _buildDrawerHeader(context, state), + // _buildSearchBar(context, state), + _buildDrawerBody(context), + ].addToStart(const SizedBox(height: 20)), + ), + ), + ), + ), + ); + }, + ); + }, ); } - Container _buildDrawerHeader(BuildContext context) { + Container _buildDrawerHeader(BuildContext context, HomeState state) { return Container( decoration: const BoxDecoration( borderRadius: BorderRadius.only( @@ -56,7 +89,7 @@ class CustomDrawer extends StatelessWidget { child: CachedNetworkImage( imageUrl: valueOrDefault( 'assets/images/person.jpg', - 'https://freaccess.com.br/freaccess/Images/Clients/${model.cliUUID}.png', + 'https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', ), width: 80.0, height: 80.0, @@ -75,7 +108,7 @@ class CustomDrawer extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - model.userName, + state.userName, style: FlutterFlowTheme.of(context).bodyLarge.override( fontFamily: 'Nunito Sans', color: FlutterFlowTheme.of(context).primaryText, @@ -85,7 +118,7 @@ class CustomDrawer extends StatelessWidget { ), ), Text( - model.userEmail, + state.userEmail, style: FlutterFlowTheme.of(context).bodySmall.override( fontFamily: 'Nunito Sans', color: FlutterFlowTheme.of(context).primaryText, @@ -102,7 +135,7 @@ class CustomDrawer extends StatelessWidget { ); } - Padding _buildSearchBar(BuildContext context) { + Padding _buildSearchBar(BuildContext context, HomeState state) { final theme = FlutterFlowTheme.of(context); final errorColor = theme.error; final primaryColor = theme.primary; @@ -111,8 +144,8 @@ class CustomDrawer extends StatelessWidget { return Padding( padding: const EdgeInsets.symmetric(vertical: 10.0), child: TextFormField( - controller: model.textController, - focusNode: model.textFieldFocusNode, + controller: TextEditingController(), // Replace with appropriate controller + focusNode: FocusNode(), // Replace with appropriate focus node autofocus: false, obscureText: false, decoration: InputDecoration( @@ -153,16 +186,17 @@ class CustomDrawer extends StatelessWidget { fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, letterSpacing: 0.0, ), - validator: model.textControllerValidator.asValidator(context), + // validator: model.textControllerValidator.asValidator(context), ), ); } - Widget _buildDrawerBody() { - return wrapWithModel( - model: model.drawerMenuComponentModel, - updateCallback: () {}, - child: MenuComponentWidget(model: model.drawerMenuComponentModel), + Widget _buildDrawerBody(BuildContext context) { + return MenuComponentWidget( + style: MenuView.list, + item: MenuItem.tile, + expandable: false, + menuOptions: Module.values.where((e) => e != Module.settings).toList(), ); } } diff --git a/test/integration_test/app_test.dart b/test/integration_test/app_test.dart index fd6b3520..f5a03e8c 100644 --- a/test/integration_test/app_test.dart +++ b/test/integration_test/app_test.dart @@ -1,210 +1,210 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:hub/flutter_flow/random_data_util.dart'; -import 'package:hub/main.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; -import 'package:integration_test/integration_test.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter/services.dart'; +// import 'package:flutter_test/flutter_test.dart'; +// import 'package:hub/flutter_flow/random_data_util.dart'; +// import 'package:hub/main.dart'; +// import 'package:hub/shared/helpers/storage/base_storage.dart'; +// import 'package:hub/shared/helpers/storage/storage_helper.dart'; +// import 'package:integration_test/integration_test.dart'; -late WidgetTester widget; +// late WidgetTester widget; -void main() { - IntegrationTestWidgetsFlutterBinding.ensureInitialized(); +// void main() { +// IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - group('Initialization', () { - group('Navigation', () { - setUpAll(() async => - await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); - testWidgets('Test Welcome', (WidgetTester tester) async { - widget = tester; - await _testWelcome(); - }); - }); +// group('Initialization', () { +// group('Navigation', () { +// setUpAll(() async => +// await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); +// testWidgets('Test Welcome', (WidgetTester tester) async { +// widget = tester; +// await _testWelcome(); +// }); +// }); - group('Terms of Use', () {}); - }); - group('Authentication', () { - group('Sign in', () { - setUpAll(() async => - await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); - testWidgets('Test Sign In', (WidgetTester tester) async { - widget = tester; - await _testSignIn(); - }); - }); - group('Sign up', () { - setUpAll(() async => - await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); - testWidgets('Test Sign Up', (WidgetTester tester) async { - widget = tester; - await _testSignUp(); - }); - }); - group('Sign Out', () { - // Add tests for Sign Out here - }); - group('Forgot Password', () { - // setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); - // testWidgets('Test Forgot Password', (WidgetTester tester) async { - // widget = tester; - // await _testForgotPassword(); - // }); - }); - }); - group('Localization', () { - // Add tests for Localization here - }); - group('Networking', () { - // Add tests for Networking here - }); - group('Functionality', () { - // Add tests for Functionality here - }); - group('Usability', () { - // Add tests for Usability here - }); - group('Performance', () { - // Add tests for Performance here - }); - group('Security', () { - // Add tests for Security here - }); - group('Accessibility', () { - // Add tests for Accessibility here - }); - group('Compatibility', () { - // Add tests for Compatibility here - }); - group('Internationalization', () { - // Add tests for Internationalization here - }); -} +// group('Terms of Use', () {}); +// }); +// group('Authentication', () { +// group('Sign in', () { +// setUpAll(() async => +// await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); +// testWidgets('Test Sign In', (WidgetTester tester) async { +// widget = tester; +// await _testSignIn(); +// }); +// }); +// group('Sign up', () { +// setUpAll(() async => +// await initializeApp().then((_) async => await StorageHelper().s(SecureStorageKey.isLogged.value, 'false'))); +// testWidgets('Test Sign Up', (WidgetTester tester) async { +// widget = tester; +// await _testSignUp(); +// }); +// }); +// group('Sign Out', () { +// // Add tests for Sign Out here +// }); +// group('Forgot Password', () { +// // setUpAll(() async => await initializeApp().then((_) => StorageUtil().isLogged = false)); +// // testWidgets('Test Forgot Password', (WidgetTester tester) async { +// // widget = tester; +// // await _testForgotPassword(); +// // }); +// }); +// }); +// group('Localization', () { +// // Add tests for Localization here +// }); +// group('Networking', () { +// // Add tests for Networking here +// }); +// group('Functionality', () { +// // Add tests for Functionality here +// }); +// group('Usability', () { +// // Add tests for Usability here +// }); +// group('Performance', () { +// // Add tests for Performance here +// }); +// group('Security', () { +// // Add tests for Security here +// }); +// group('Accessibility', () { +// // Add tests for Accessibility here +// }); +// group('Compatibility', () { +// // Add tests for Compatibility here +// }); +// group('Internationalization', () { +// // Add tests for Internationalization here +// }); +// } -Future _testWelcome() async { - await widget.pumpWidget(const App()); - await widget.pumpAndSettle(); - await _navigateToSignIn(); - await _navigateToSignUp(); - await widget.pumpAndSettle(); - await widget.pumpWidget(const App()); - await widget.pumpAndSettle(); - await _navigateToSignUp(); - await _navigateToSignIn(); - await widget.pumpAndSettle(); -} +// Future _testWelcome() async { +// await widget.pumpWidget(const App()); +// await widget.pumpAndSettle(); +// await _navigateToSignIn(); +// await _navigateToSignUp(); +// await widget.pumpAndSettle(); +// await widget.pumpWidget(const App()); +// await widget.pumpAndSettle(); +// await _navigateToSignUp(); +// await _navigateToSignIn(); +// await widget.pumpAndSettle(); +// } -Future _testSignIn() async { - await widget.pumpWidget(const App()); - await _navigateToSignIn(); - await _auth({'emailTextFormField': 'erro@exemplo.com', 'passwordTextFormField': '12345678'}); - await _auth({'emailTextFormField': 'email_app@exemplo.com', 'passwordTextFormField': '12345678'}); -} +// Future _testSignIn() async { +// await widget.pumpWidget(const App()); +// await _navigateToSignIn(); +// await _auth({'emailTextFormField': 'erro@exemplo.com', 'passwordTextFormField': '12345678'}); +// await _auth({'emailTextFormField': 'email_app@exemplo.com', 'passwordTextFormField': '12345678'}); +// } -Future _testSignUp() async { - await widget.pumpWidget(const App()); - await _navigateToSignUp(); +// Future _testSignUp() async { +// await widget.pumpWidget(const App()); +// await _navigateToSignUp(); - var credentials = { - 'nameTextFormField': 'app', - 'emailTextFormField': 'email_app@exemplo.com', - 'passwordTextFormField': '12345678' - }; - await _auth(credentials); +// var credentials = { +// 'nameTextFormField': 'app', +// 'emailTextFormField': 'email_app@exemplo.com', +// 'passwordTextFormField': '12345678' +// }; +// await _auth(credentials); - var name = randomString(7, 7, true, true, true); - var email = '$name@example.com'; - var password = '12345678'; - credentials = {'nameTextFormField': name, 'emailTextFormField': email, 'passwordTextFormField': password}; - await _navigateToSignUp(); - await _auth(credentials); - credentials = {'emailTextFormField': email, 'passwordTextFormField': password}; - await _auth(credentials); -} +// var name = randomString(7, 7, true, true, true); +// var email = '$name@example.com'; +// var password = '12345678'; +// credentials = {'nameTextFormField': name, 'emailTextFormField': email, 'passwordTextFormField': password}; +// await _navigateToSignUp(); +// await _auth(credentials); +// credentials = {'emailTextFormField': email, 'passwordTextFormField': password}; +// await _auth(credentials); +// } -Future _testForgotPassword() async { - await widget.pumpWidget(const App()); - await _navigateToSignIn(); - await _recoveryPassword(); +// Future _testForgotPassword() async { +// await widget.pumpWidget(const App()); +// await _navigateToSignIn(); +// await _recoveryPassword(); - var addr = randomString(5, 5, true, true, true); - var credentials = {'recoveryTextFormField': '$addr@exemple.com'}; - await _send(credentials); +// var addr = randomString(5, 5, true, true, true); +// var credentials = {'recoveryTextFormField': '$addr@exemple.com'}; +// await _send(credentials); - await Future.delayed(const Duration(seconds: 2)); +// await Future.delayed(const Duration(seconds: 2)); - await _recoveryPassword(); - credentials = {'recoveryTextFormField': 'email_app@exemple.com'}; - await _send(credentials); -} +// await _recoveryPassword(); +// credentials = {'recoveryTextFormField': 'email_app@exemple.com'}; +// await _send(credentials); +// } -Future _recoveryPassword() async { - await widget.pumpAndSettle(); - final Finder forgotPassword = find.byKey(const ValueKey('ForgotPassword')); - if (forgotPassword.evaluate().isNotEmpty) await widget.tap(forgotPassword); - await widget.ensureVisible(forgotPassword); - await widget.pumpAndSettle(); -} +// Future _recoveryPassword() async { +// await widget.pumpAndSettle(); +// final Finder forgotPassword = find.byKey(const ValueKey('ForgotPassword')); +// if (forgotPassword.evaluate().isNotEmpty) await widget.tap(forgotPassword); +// await widget.ensureVisible(forgotPassword); +// await widget.pumpAndSettle(); +// } -Future _navigateBackUsingSystemGesture() async => - IntegrationTestWidgetsFlutterBinding.instance.keyboard.isLogicalKeyPressed(LogicalKeyboardKey.escape); -Future _navigateToSignUp() async { - await widget.pumpAndSettle(); - final Finder navToSignUp = find.byKey(const ValueKey('toggleSignUpPage')); - if (navToSignUp.evaluate().isNotEmpty) { - await widget.tap(navToSignUp); - await widget.pumpAndSettle(); - } -} +// Future _navigateBackUsingSystemGesture() async => +// IntegrationTestWidgetsFlutterBinding.instance.keyboard.isLogicalKeyPressed(LogicalKeyboardKey.escape); +// Future _navigateToSignUp() async { +// await widget.pumpAndSettle(); +// final Finder navToSignUp = find.byKey(const ValueKey('toggleSignUpPage')); +// if (navToSignUp.evaluate().isNotEmpty) { +// await widget.tap(navToSignUp); +// await widget.pumpAndSettle(); +// } +// } -Future _navigateToSignIn() async { - await widget.pumpAndSettle(); - final Finder navToSignIn = find.byKey(const ValueKey('toggleSignInPage')); - expect(navToSignIn, findsOneWidget); - if (navToSignIn.evaluate().isNotEmpty) { - await widget.tap(navToSignIn); - await widget.pumpAndSettle(); - } -} +// Future _navigateToSignIn() async { +// await widget.pumpAndSettle(); +// final Finder navToSignIn = find.byKey(const ValueKey('toggleSignInPage')); +// expect(navToSignIn, findsOneWidget); +// if (navToSignIn.evaluate().isNotEmpty) { +// await widget.tap(navToSignIn); +// await widget.pumpAndSettle(); +// } +// } -Future _auth(Map credentials) async { - await _enterCredentials(credentials); - await _submit('SubmitButtonWidget'); -} +// Future _auth(Map credentials) async { +// await _enterCredentials(credentials); +// await _submit('SubmitButtonWidget'); +// } -Future _send(Map credentials) async { - await _enterCredentials(credentials); - await _submit('SendButtonWidget'); -} +// Future _send(Map credentials) async { +// await _enterCredentials(credentials); +// await _submit('SendButtonWidget'); +// } -Future _enterCredentials(Map credentials) async { - await widget.pumpAndSettle(); - for (var entry in credentials.entries) { - final Finder field = find.byKey(ValueKey(entry.key)); - await widget.pumpAndSettle(); - expect(field, findsOneWidget); - await widget.enterText(field, entry.value); - await widget.pumpAndSettle(); - } - await widget.pumpAndSettle(); -} +// Future _enterCredentials(Map credentials) async { +// await widget.pumpAndSettle(); +// for (var entry in credentials.entries) { +// final Finder field = find.byKey(ValueKey(entry.key)); +// await widget.pumpAndSettle(); +// expect(field, findsOneWidget); +// await widget.enterText(field, entry.value); +// await widget.pumpAndSettle(); +// } +// await widget.pumpAndSettle(); +// } -Future _submit(String key) async { - await widget.pumpAndSettle(); - final Finder submitButton = find.byKey(ValueKey(key)); - await widget.pumpAndSettle(); - if (submitButton.evaluate().isNotEmpty) { - await widget.tap(submitButton); - await widget.pumpAndSettle(); - } +// Future _submit(String key) async { +// await widget.pumpAndSettle(); +// final Finder submitButton = find.byKey(ValueKey(key)); +// await widget.pumpAndSettle(); +// if (submitButton.evaluate().isNotEmpty) { +// await widget.tap(submitButton); +// await widget.pumpAndSettle(); +// } - final Finder throwExceptionWidget = find.byKey(const ValueKey('ThrowExceptionWidget')); - await widget.pumpAndSettle(); - if (throwExceptionWidget.evaluate().isNotEmpty) { - await widget.ensureVisible(throwExceptionWidget); - await widget.tap(throwExceptionWidget); - await widget.pumpAndSettle(); - } else { - await _navigateBackUsingSystemGesture(); - } -} +// final Finder throwExceptionWidget = find.byKey(const ValueKey('ThrowExceptionWidget')); +// await widget.pumpAndSettle(); +// if (throwExceptionWidget.evaluate().isNotEmpty) { +// await widget.ensureVisible(throwExceptionWidget); +// await widget.tap(throwExceptionWidget); +// await widget.pumpAndSettle(); +// } else { +// await _navigateBackUsingSystemGesture(); +// } +// } From d99cfc1873f2482667b45a9da2ba9897ec28f92b Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 27 Nov 2024 15:53:06 -0300 Subject: [PATCH 17/75] WIP --- lib/main.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index ba520190..7b66def1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -42,10 +42,7 @@ Future _foregroundHandlerMessage(RemoteMessage message) async { } if (!Platform.isIOS) { - NotificationService.show( - title: message.notification!.title!, - body: message.notification!.body!, - payload: Map.from(message.data)); + NotificationService.show(title: message.notification!.title!, body: message.notification!.body!, payload: Map.from(message.data)); } } From a6a533efd026722df155610ee79cde603749927d Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 27 Nov 2024 18:02:20 -0300 Subject: [PATCH 18/75] WIP --- .../menu_component/menu_component_bloc.dart | 106 ++++++++++++------ lib/flutter_flow/custom_functions.dart | 19 ++++ .../about_property_screen.dart | 4 +- .../helpers/database/database_helper.dart | 2 +- .../helpers/license/license_helper.dart | 19 +++- .../services/license/license_service.dart | 45 +++++--- .../localization/localization_service.dart | 8 +- 7 files changed, 144 insertions(+), 59 deletions(-) diff --git a/lib/components/organism_components/menu_component/menu_component_bloc.dart b/lib/components/organism_components/menu_component/menu_component_bloc.dart index b5f7876e..d714cf3f 100644 --- a/lib/components/organism_components/menu_component/menu_component_bloc.dart +++ b/lib/components/organism_components/menu_component/menu_component_bloc.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -5,6 +6,7 @@ import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/atomic_components/menu_button_item/menu_button_item_widget.dart'; import 'package:hub/components/atomic_components/menu_card_item/menu_card_item.dart'; import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; +import 'package:hub/flutter_flow/custom_functions.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; @@ -38,44 +40,92 @@ class MenuBloc extends Bloc { emit(state.copyWith(menuEntries: entries)); }); } + Future addMenuEntry(List entries, IconData icon, String text, Function() action) async { + entries.add( + item == MenuItem.button + ? MenuButtonWidget(icon: icon, action: action, title: text) + : item == MenuItem.card + ? MenuCardItem(icon: icon, action: action, title: text) + : item == MenuItem.tile + ? MenuCardItem(icon: icon, action: action, title: text) + : null, + ); + return null; + } Future> generateMenuEntries() async { List entries = []; - Future addMenuEntry(IconData icon, String text, Function() action) async { - entries.add( - item == MenuItem.button - ? MenuButtonWidget(icon: icon, action: action, title: text) - : item == MenuItem.card - ? MenuCardItem(icon: icon, action: action, title: text) - : item == MenuItem.tile - ? MenuCardItem(icon: icon, action: action, title: text) - : null, - ); - return null; + try { + for (var opt in menuOptions) { + String? licenseValue = await LicenseHelper().g(opt.value); + if (licenseValue != null) { + Map licenseMap = await stringToMap(licenseValue); + if (opt == Module.aboutProperty) log('AboutProperty: $licenseMap'); + log('Module: ${opt.value} - License: ${licenseMap['display']}'); + final String display = licenseMap['display'] ?? 'INVISIVEL'; + final String startDate = licenseMap['startDate'] ?? ''; + final String expirationDate = licenseMap['expirationDate'] ?? ''; + final bool isStarted = await processStartDate(startDate, opt); + log('isStarted: $isStarted'); + final bool isExpired = await processExpirationDate(expirationDate, opt); + log('isExpired: $isExpired'); + if (isStarted && !isExpired) { + await processDisplay(display, opt, entries); + } + } + } + } catch (e) { + log('Error generating menu entries: $e'); } + return entries; + } - for (var opt in menuOptions) { - String? v = await LicenseHelper().g(opt.value); - log('Module: ${opt.value} - License: $v'); - switch (v) { + Future processDisplay(String display, Module opt, List entries) async { + try { + switch (display) { case 'VISIVEL': - await addMenuEntry(opt.icon, opt.name, () async { + await addMenuEntry(entries, opt.icon, opt.name, () async { await nav(opt.route); }); - continue; + break; case 'DESABILITADO': - await addMenuEntry(opt.icon, opt.name, () async { + await addMenuEntry(entries, opt.icon, opt.name, () async { await DialogUnavailable.unavailableFeature(key.currentContext!); }); - continue; + break; case 'INVISIVEL': - continue; default: - continue; + break; } + } catch (e) { + log('Error processing display for module ${opt.value}: $e'); } + } - return entries; + Future processStartDate(String startDate, Module opt) async { + try { + if (startDate.isEmpty) return true; + final DateTime? start = DateTime.tryParse(startDate); + if (start != null) { + return DateTime.now().isAfter(start); + } + } catch (e) { + log('Error processing start date for module ${opt.value}: $e'); + } + return false; + } + + Future processExpirationDate(String expirationDate, Module opt) async { + try { + if (expirationDate.isEmpty) return false; + final DateTime? expiration = DateTime.tryParse(expirationDate); + if (expiration != null) { + return DateTime.now().isAfter(expiration); + } + } catch (e) { + log('Error processing expiration date for module ${opt.value}: $e'); + } + return false; } Future nav(String link) async { @@ -88,16 +138,4 @@ class MenuBloc extends Bloc { ), }); } - - Future logout() async { - // Implement logout logic here - } - - Future settings() async { - // Implement settings navigation logic here - } - - Future about() async { - // Implement about navigation logic here - } } diff --git a/lib/flutter_flow/custom_functions.dart b/lib/flutter_flow/custom_functions.dart index ddd01694..642abd6d 100644 --- a/lib/flutter_flow/custom_functions.dart +++ b/lib/flutter_flow/custom_functions.dart @@ -33,6 +33,25 @@ String jsonListToStr(List visitorList) { return result.substring(0, result.length - 1); } +Future> stringToMap(String v) async { + try { + return Future.value(Map.fromEntries( + v.split(',').map((part) { + final keyValue = part.split(':'); + if (keyValue.length < 2) { + throw FormatException('Invalid key-value pair: $part of $v'); + } + final key = keyValue[0].trim(); + final value = keyValue.length > 1 ? keyValue[1].trim() : ''; + return MapEntry(key, value); + }), + )); + } catch (e) { + print('Error parsing string to map: $e'); + return Future.value({}); + } +} + List listStrJsonToJsonList( dynamic jsonList, List strList, diff --git a/lib/pages/about_property_page/about_property_screen.dart b/lib/pages/about_property_page/about_property_screen.dart index f36f7e97..a03227e1 100644 --- a/lib/pages/about_property_page/about_property_screen.dart +++ b/lib/pages/about_property_page/about_property_screen.dart @@ -27,7 +27,7 @@ extension AboutPropertyModulesExtension on AboutPropertyModules { case AboutPropertyModules.residents: return 'FRE-HUB-RESIDENTS'; case AboutPropertyModules.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; + return 'FRE-HUB-PETS'; default: return ''; } @@ -85,7 +85,7 @@ class _AboutPropertyPageState extends State with SingleTicker child: Container( color: FlutterFlowTheme.of(context).primaryBackground, child: MenuComponentWidget(expandable: true, style: MenuView.list_grid, item: MenuItem.button, menuOptions: [ - Module.pets, + Module.petsHistory, Module.residents, Module.openedVisits, Module.vehicles, diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 1a9d1513..15344451 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -32,7 +32,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - await LicenseService().setupLicense(database); + await LicenseService().setupLicense(database, false); isInitialized = true; } diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart index 5a1f7dc7..9ce5c8b8 100644 --- a/lib/shared/helpers/license/license_helper.dart +++ b/lib/shared/helpers/license/license_helper.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:sqflite/sqflite.dart'; enum InactiveModuleKey { @@ -11,6 +12,7 @@ enum InactiveModuleKey { vehicles, openedVisits, petsHistory, + aboutProperty, } extension InactiveModuleKeyExtension on InactiveModuleKey { @@ -24,6 +26,8 @@ extension InactiveModuleKeyExtension on InactiveModuleKey { return 'FRE-HUB-RESIDENTS'; case InactiveModuleKey.petsHistory: return 'FRE-HUB-PETS-HISTORY'; + case InactiveModuleKey.aboutProperty: + return 'FRE-HUB-PROPERTY'; default: return ''; } @@ -39,6 +43,7 @@ extension DisabledModuleKeyExtension on DisabledModuleKey { switch (this) { case DisabledModuleKey.fastPass: return 'FRE-HUB-FASTPASS'; + default: return ''; } @@ -385,6 +390,7 @@ class LicenseHelper { Future setByKey(final List key, final String display) async { for (var element in key) { + log('setByKey($element, $display)'); await s(element, { 'display': display, 'expirationDate': '', @@ -394,12 +400,21 @@ class LicenseHelper { } } + Future isNewVersion() async { + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [KeychainStorageKey.isNewVersion.value], columns: ['display']); + if (response.isEmpty) { + return false; + } + log('isNewVersion(): ${response.first['display']}'); + return response.first['display'] == 'true'; + } + Future g(String key) async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key], columns: ['display']); + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; } - return response.first['display'].toString(); + return response.first.toString(); } Future s(String key, T value) async { diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart index 57ba57f1..b6180934 100644 --- a/lib/shared/services/license/license_service.dart +++ b/lib/shared/services/license/license_service.dart @@ -19,19 +19,42 @@ class LicenseService { Stream> get licenseStream => _licenseSubject.stream; + Future processLicense() async { + if (body['key'] == Module.pets.value && body['display'] == 'VISIVEL') { + await LicenseHelper().s(Module.petsHistory.value, body); + } + final bool isAboutProperty = AboutPropertyModules.values.contains(body['key']); + final bool isVisible = body['display'] == 'VISIVEL'; + log('contains () => ${body['key']} - $isAboutProperty'); + if (isAboutProperty && isVisible) { + await LicenseHelper().s(Module.aboutProperty.value, body); + } + } + Future cleanLicense() async { _licenseSubject.add([]); } - Future setupLicense(Database database) async { + Future setupLicense(Database database, bool isNewVersion) async { + log('(B) => license'); + final List inactiveModuleKey = InactiveModuleKey.values.map((e) => e.value).toList(); final List activeModuleKey = ActiveModuleKey.values.map((e) => e.value).toList(); + final List disabledModuleKey = DisabledModuleKey.values.map((e) => e.value).toList(); + await LicenseHelper().setByKey(inactiveModuleKey, 'INVISIVEL'); await LicenseHelper().setByKey(activeModuleKey, 'VISIVEL'); + if (isNewVersion == true) { + await LicenseHelper().setByKey(disabledModuleKey, 'VISIVEL'); + await LicenseHelper().setByKey([Module.aboutProperty.value], 'VISIVEL'); + } else { + await LicenseHelper().setByKey(disabledModuleKey, 'DESABILITADO'); + } _licenseSubject.add([...activeModuleKey]); } - Future fetchLicenses() async { + Future fetchLicenses(bool isNewVersion) async { + log('(A) => license'); try { log('Obtendo licenças...'); final response = await PhpGroup.getLicense(); @@ -49,7 +72,7 @@ class LicenseService { } if (responseBody == []) { - await setupLicense(DatabaseStorage.database); + await setupLicense(DatabaseStorage.database, isNewVersion); _licenseSubject.add([]); return false; } @@ -63,7 +86,7 @@ class LicenseService { return true; } catch (e) { log('Erro ao obter licenças: $e'); - await setupLicense(DatabaseStorage.database); + await setupLicense(DatabaseStorage.database, isNewVersion); return false; } } @@ -73,16 +96,8 @@ class LicenseService { } static Future _saveModule(final dynamic body) async { - if (body is Map) { - log('Salvando módulo: ${body.toString()}'); - await LicenseHelper().s(body['key'], body); - log('body[key]: ${body['key']}'); - if (body['key'] == Module.pets.value) if (body['display'] == 'VISIVEL') { - await LicenseHelper().s(Module.petsHistory.value, body); - } - if (AboutPropertyModules.values.any((e) => e.value == body['key']) && body['display'] == 'VISIVEL') { - await LicenseHelper().s(Module.aboutProperty.value, body); - } - } + if (body is! Map) return; + log('Salvando módulo: ${body.toString()}'); + await LicenseHelper().s(body['key'], body); } } diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index a53e2ba9..bf485699 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -153,13 +153,11 @@ class LocalizationService { return false; } else { final bool isNewVersion = await _updateStorageUtil(response.jsonBody); + await LicenseService().setupLicense(DatabaseStorage.database, isNewVersion); if (isNewVersion) { - return await LicenseService().fetchLicenses(); - } else { - await LicenseService().setupLicense(DatabaseStorage.database); + log('(A) => isNewVersion: $isNewVersion'); + return await LicenseService().fetchLicenses(isNewVersion); } - log('() => isNewVersion: $isNewVersion'); - return false; } } catch (e, s) { From d72fd6edb271252b6df188d379c6c9b628904b51 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 28 Nov 2024 17:02:15 -0300 Subject: [PATCH 19/75] milestone refactory --- .../modules/data/data_sources/index.dart | 2 + .../license_local_data_source.dart | 121 ++++++++ .../license_remote_data_source.dart | 109 +++++++ .../molecules/modules/data/index.dart | 3 + .../molecules/modules/data/models/index.dart | 2 + .../modules/data/models/license_model.dart | 15 + .../data/models/license_model.freezed.dart | 172 +++++++++++ .../modules/data/models/license_model.g.dart | 19 ++ .../modules/data/models/module_model.dart | 18 ++ .../data/models/module_model.freezed.dart | 252 ++++++++++++++++ .../modules/data/models/module_model.g.dart | 25 ++ .../modules/data/repositories/index.dart | 1 + .../repositories/license_repository_impl.dart | 35 +++ .../modules/domain/entities/index.dart | 2 + .../modules/domain/entities/license.dart | 26 ++ .../modules/domain/entities/module.dart | 37 +++ .../molecules/modules/domain/index.dart | 3 + .../modules/domain/respositories/index.dart | 1 + .../respositories/license_repository.dart | 8 + .../modules/domain/usecases/index.dart | 0 .../modules/enums/active_modules.dart | 60 ++++ .../modules/enums/disabled_modules.dart | 26 ++ .../molecules/modules/enums/enum_modules.dart | 277 ++++++++++++++++++ .../modules/enums/inactive_modules.dart | 38 +++ .../molecules/modules/enums/index.dart | 4 + .../components/molecules/modules/index.dart | 4 + .../modules/presentation/blocs/index.dart | 0 .../molecules/modules/presentation/index.dart | 3 + .../modules/presentation/pages/index.dart | 0 .../modules/presentation/widgets/index.dart | 0 30 files changed, 1263 insertions(+) create mode 100644 lib/shared/components/molecules/modules/data/data_sources/index.dart create mode 100644 lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart create mode 100644 lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart create mode 100644 lib/shared/components/molecules/modules/data/index.dart create mode 100644 lib/shared/components/molecules/modules/data/models/index.dart create mode 100644 lib/shared/components/molecules/modules/data/models/license_model.dart create mode 100644 lib/shared/components/molecules/modules/data/models/license_model.freezed.dart create mode 100644 lib/shared/components/molecules/modules/data/models/license_model.g.dart create mode 100644 lib/shared/components/molecules/modules/data/models/module_model.dart create mode 100644 lib/shared/components/molecules/modules/data/models/module_model.freezed.dart create mode 100644 lib/shared/components/molecules/modules/data/models/module_model.g.dart create mode 100644 lib/shared/components/molecules/modules/data/repositories/index.dart create mode 100644 lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart create mode 100644 lib/shared/components/molecules/modules/domain/entities/index.dart create mode 100644 lib/shared/components/molecules/modules/domain/entities/license.dart create mode 100644 lib/shared/components/molecules/modules/domain/entities/module.dart create mode 100644 lib/shared/components/molecules/modules/domain/index.dart create mode 100644 lib/shared/components/molecules/modules/domain/respositories/index.dart create mode 100644 lib/shared/components/molecules/modules/domain/respositories/license_repository.dart create mode 100644 lib/shared/components/molecules/modules/domain/usecases/index.dart create mode 100644 lib/shared/components/molecules/modules/enums/active_modules.dart create mode 100644 lib/shared/components/molecules/modules/enums/disabled_modules.dart create mode 100644 lib/shared/components/molecules/modules/enums/enum_modules.dart create mode 100644 lib/shared/components/molecules/modules/enums/inactive_modules.dart create mode 100644 lib/shared/components/molecules/modules/enums/index.dart create mode 100644 lib/shared/components/molecules/modules/index.dart create mode 100644 lib/shared/components/molecules/modules/presentation/blocs/index.dart create mode 100644 lib/shared/components/molecules/modules/presentation/index.dart create mode 100644 lib/shared/components/molecules/modules/presentation/pages/index.dart create mode 100644 lib/shared/components/molecules/modules/presentation/widgets/index.dart diff --git a/lib/shared/components/molecules/modules/data/data_sources/index.dart b/lib/shared/components/molecules/modules/data/data_sources/index.dart new file mode 100644 index 00000000..1d1649f7 --- /dev/null +++ b/lib/shared/components/molecules/modules/data/data_sources/index.dart @@ -0,0 +1,2 @@ +export 'license_local_data_source.dart'; +export 'license_remote_data_source.dart'; diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart new file mode 100644 index 00000000..9f4dfdf2 --- /dev/null +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -0,0 +1,121 @@ +import 'dart:developer'; + +import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:sqflite/sqflite.dart'; + +abstract class LicenseLocalDataSource { + Future init(); + Future setByKey(final List key, final String display); + Future isNewVersion(); + Future g(String key); + Future s(String key, T value); + Future d(String key); + Future c(); +} + +class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { + static final LicenseLocalDataSourceImpl _instance = LicenseLocalDataSourceImpl._internal(); + factory LicenseLocalDataSourceImpl() => _instance; + LicenseLocalDataSourceImpl._internal(); + + static const String tableLicense = 'license'; + + static String get createLicenseTable => ''' + CREATE TABLE IF NOT EXISTS $tableLicense ( + key TEXT UNIQUE, + display TEXT, + expirationDate TEXT, + startDate TEXT, + quantity TEXT + ); + '''; + + static String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;'; + + static String get updatePetsHistoryTrigger => ''' + CREATE TRIGGER update_fre_hub_pets_history + AFTER INSERT ON $tableLicense + WHEN NEW.key = 'FRE-HUB-PETS' + BEGIN + INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) + VALUES ('FRE-HUB-PETS-HISTORY', NEW.display, NEW.expirationDate, NEW.startDate, NEW.quantity); + END; + '''; + + static String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;'; + + static String get updateDisplayTrigger => ''' + CREATE TRIGGER update_display_trigger + AFTER UPDATE ON $tableLicense + WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') + BEGIN + UPDATE $tableLicense + SET display = CASE + WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') AND display = 'VISIVEL') > 0 + THEN 'VISIVEL' + ELSE 'INVISIVEL' + END + WHERE key = 'FRE-HUB-ABOUT-PROPERTY'; + END; + '''; + + static String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;'; + + Future init() async { + await DatabaseStorage.instance.init(); + } + + Future setByKey(final List key, final String display) async { + for (var element in key) { + log('setByKey($element, $display)'); + await s(element, { + 'display': display, + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }); + } + } + + Future isNewVersion() async { + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [KeychainStorageKey.isNewVersion.value], columns: ['display']); + if (response.isEmpty) { + return false; + } + log('isNewVersion(): ${response.first['display']}'); + return response.first['display'] == 'true'; + } + + Future g(String key) async { + var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); + if (response.isEmpty) { + return null; + } + return response.first.toString(); + } + + Future s(String key, T value) async { + log('setLicense($key, $value)'); + value as Map; + + await DatabaseStorage.database.insert( + tableLicense, + { + 'key': key, + 'display': value['display'], + 'expirationDate': value['expirationDate'], + 'startDate': value['startDate'], + 'quantity': value['quantity'], + }, + conflictAlgorithm: ConflictAlgorithm.replace); + } + + Future d(String key) async { + await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); + } + + Future c() async { + await DatabaseStorage.database.delete(tableLicense); + } +} diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart new file mode 100644 index 00000000..cc6aa0df --- /dev/null +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -0,0 +1,109 @@ +// ignore_for_file: curly_braces_in_flow_control_structures, prefer_is_empty + +import 'dart:developer'; + +import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; + +import 'package:rxdart/rxdart.dart'; +import 'package:sqflite/sqflite.dart'; + +abstract class LicenseRemoteDataSource { + Future fetchLicenses(bool isNewVersion); + Future cleanLicense(); + Future processLicense(); + Future setupLicense(Database database, bool isNewVersion); +} + +class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { + static final LicenseRemoteDataSourceImpl _instance = LicenseRemoteDataSourceImpl._internal(); + factory LicenseRemoteDataSourceImpl() => _instance; + LicenseRemoteDataSourceImpl._internal(); + + final _licenseSubject = BehaviorSubject>(); + + Stream> get licenseStream => _licenseSubject.stream; + + Future processLicense() async { + // if (body['key'] == Module.pets.value && body['display'] == 'VISIVEL') { + // await LicenseHelper().s(Module.petsHistory.value, body); + // } + // final bool isAboutProperty = AboutPropertyModules.values.contains(body['key']); + // final bool isVisible = body['display'] == 'VISIVEL'; + // log('contains () => ${body['key']} - $isAboutProperty'); + // if (isAboutProperty && isVisible) { + // await LicenseHelper().s(Module.aboutProperty.value, body); + // } + } + + Future cleanLicense() async { + _licenseSubject.add([]); + } + + Future setupLicense(Database database, bool isNewVersion) async { + log('(B) => license'); + + final List inactiveModuleKey = InactiveModuleKey.values.map((e) => e.value).toList(); + final List activeModuleKey = ActiveModuleKey.values.map((e) => e.value).toList(); + final List disabledModuleKey = DisabledModuleKey.values.map((e) => e.value).toList(); + + await LicenseLocalDataSourceImpl().setByKey(inactiveModuleKey, 'INVISIVEL'); + await LicenseLocalDataSourceImpl().setByKey(activeModuleKey, 'VISIVEL'); + if (isNewVersion == true) { + await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'VISIVEL'); + await LicenseLocalDataSourceImpl().setByKey([ModuleEnum.aboutProperty.value], 'VISIVEL'); + } else { + await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'DESABILITADO'); + } + _licenseSubject.add([...activeModuleKey]); + } + + Future fetchLicenses(bool isNewVersion) async { + log('(A) => license'); + try { + log('Obtendo licenças...'); + final response = await PhpGroup.getLicense(); + final dynamic responseBody = response.jsonBody; + log('Licenças obtidas: $responseBody'); + + if (response.jsonBody is! List) { + late final String error; + if (response.jsonBody is Map) + error = response.jsonBody['error_msg']; + else + error = 'Erro desconhecido'; + + throw Exception('Erro ao consultar licenças: $error'); + } + + if (responseBody == []) { + await setupLicense(DatabaseStorage.database, isNewVersion); + _licenseSubject.add([]); + return false; + } + + for (var element in responseBody) { + if (licenseContainsKey(element['key'])) { + _saveModule(element); + } + } + _licenseSubject.add(responseBody); + return true; + } catch (e) { + log('Erro ao obter licenças: $e'); + await setupLicense(DatabaseStorage.database, isNewVersion); + return false; + } + } + + static bool licenseContainsKey(final String key) { + return ModuleEnum.values.map((e) => e.value).toList().contains(key); + } + + static Future _saveModule(final dynamic body) async { + if (body is! Map) return; + log('Salvando módulo: ${body.toString()}'); + await LicenseLocalDataSourceImpl().s(body['key'], body); + } +} diff --git a/lib/shared/components/molecules/modules/data/index.dart b/lib/shared/components/molecules/modules/data/index.dart new file mode 100644 index 00000000..186dfac9 --- /dev/null +++ b/lib/shared/components/molecules/modules/data/index.dart @@ -0,0 +1,3 @@ +export 'data_sources/index.dart'; +export 'repositories/index.dart'; +export 'models/index.dart'; diff --git a/lib/shared/components/molecules/modules/data/models/index.dart b/lib/shared/components/molecules/modules/data/models/index.dart new file mode 100644 index 00000000..2ce303b5 --- /dev/null +++ b/lib/shared/components/molecules/modules/data/models/index.dart @@ -0,0 +1,2 @@ +export 'license_model.dart'; +export 'module_model.dart'; diff --git a/lib/shared/components/molecules/modules/data/models/license_model.dart b/lib/shared/components/molecules/modules/data/models/license_model.dart new file mode 100644 index 00000000..1bbf5d3f --- /dev/null +++ b/lib/shared/components/molecules/modules/data/models/license_model.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'module_model.dart'; + +part 'license_model.freezed.dart'; +part 'license_model.g.dart'; + +@freezed +class LicenseModel with _$LicenseModel { + const factory LicenseModel({ + required List modules, + }) = _LicenseModel; + + factory LicenseModel.fromJson(Map json) => _$LicenseModelFromJson(json); +} diff --git a/lib/shared/components/molecules/modules/data/models/license_model.freezed.dart b/lib/shared/components/molecules/modules/data/models/license_model.freezed.dart new file mode 100644 index 00000000..8481cf6f --- /dev/null +++ b/lib/shared/components/molecules/modules/data/models/license_model.freezed.dart @@ -0,0 +1,172 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'license_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +LicenseModel _$LicenseModelFromJson(Map json) { + return _LicenseModel.fromJson(json); +} + +/// @nodoc +mixin _$LicenseModel { + List get modules => throw _privateConstructorUsedError; + + /// Serializes this LicenseModel to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of LicenseModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $LicenseModelCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LicenseModelCopyWith<$Res> { + factory $LicenseModelCopyWith( + LicenseModel value, $Res Function(LicenseModel) then) = + _$LicenseModelCopyWithImpl<$Res, LicenseModel>; + @useResult + $Res call({List modules}); +} + +/// @nodoc +class _$LicenseModelCopyWithImpl<$Res, $Val extends LicenseModel> + implements $LicenseModelCopyWith<$Res> { + _$LicenseModelCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of LicenseModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? modules = null, + }) { + return _then(_value.copyWith( + modules: null == modules + ? _value.modules + : modules // ignore: cast_nullable_to_non_nullable + as List, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$LicenseModelImplCopyWith<$Res> + implements $LicenseModelCopyWith<$Res> { + factory _$$LicenseModelImplCopyWith( + _$LicenseModelImpl value, $Res Function(_$LicenseModelImpl) then) = + __$$LicenseModelImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({List modules}); +} + +/// @nodoc +class __$$LicenseModelImplCopyWithImpl<$Res> + extends _$LicenseModelCopyWithImpl<$Res, _$LicenseModelImpl> + implements _$$LicenseModelImplCopyWith<$Res> { + __$$LicenseModelImplCopyWithImpl( + _$LicenseModelImpl _value, $Res Function(_$LicenseModelImpl) _then) + : super(_value, _then); + + /// Create a copy of LicenseModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? modules = null, + }) { + return _then(_$LicenseModelImpl( + modules: null == modules + ? _value._modules + : modules // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$LicenseModelImpl implements _LicenseModel { + const _$LicenseModelImpl({required final List modules}) + : _modules = modules; + + factory _$LicenseModelImpl.fromJson(Map json) => + _$$LicenseModelImplFromJson(json); + + final List _modules; + @override + List get modules { + if (_modules is EqualUnmodifiableListView) return _modules; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_modules); + } + + @override + String toString() { + return 'LicenseModel(modules: $modules)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$LicenseModelImpl && + const DeepCollectionEquality().equals(other._modules, _modules)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, const DeepCollectionEquality().hash(_modules)); + + /// Create a copy of LicenseModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$LicenseModelImplCopyWith<_$LicenseModelImpl> get copyWith => + __$$LicenseModelImplCopyWithImpl<_$LicenseModelImpl>(this, _$identity); + + @override + Map toJson() { + return _$$LicenseModelImplToJson( + this, + ); + } +} + +abstract class _LicenseModel implements LicenseModel { + const factory _LicenseModel({required final List modules}) = + _$LicenseModelImpl; + + factory _LicenseModel.fromJson(Map json) = + _$LicenseModelImpl.fromJson; + + @override + List get modules; + + /// Create a copy of LicenseModel + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$LicenseModelImplCopyWith<_$LicenseModelImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/shared/components/molecules/modules/data/models/license_model.g.dart b/lib/shared/components/molecules/modules/data/models/license_model.g.dart new file mode 100644 index 00000000..2689837b --- /dev/null +++ b/lib/shared/components/molecules/modules/data/models/license_model.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'license_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$LicenseModelImpl _$$LicenseModelImplFromJson(Map json) => + _$LicenseModelImpl( + modules: (json['modules'] as List) + .map((e) => ModuleModel.fromJson(e as Map)) + .toList(), + ); + +Map _$$LicenseModelImplToJson(_$LicenseModelImpl instance) => + { + 'modules': instance.modules, + }; diff --git a/lib/shared/components/molecules/modules/data/models/module_model.dart b/lib/shared/components/molecules/modules/data/models/module_model.dart new file mode 100644 index 00000000..c45efffe --- /dev/null +++ b/lib/shared/components/molecules/modules/data/models/module_model.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'module_model.freezed.dart'; +part 'module_model.g.dart'; + +@freezed +class ModuleModel with _$ModuleModel { + const factory ModuleModel({ + required String key, + required String display, + required String expirationDate, + required String startDate, + required int quantity, + }) = _ModuleModel; + + factory ModuleModel.fromJson(Map json) => _$ModuleModelFromJson(json); +} diff --git a/lib/shared/components/molecules/modules/data/models/module_model.freezed.dart b/lib/shared/components/molecules/modules/data/models/module_model.freezed.dart new file mode 100644 index 00000000..5b26bcdb --- /dev/null +++ b/lib/shared/components/molecules/modules/data/models/module_model.freezed.dart @@ -0,0 +1,252 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'module_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +ModuleModel _$ModuleModelFromJson(Map json) { + return _ModuleModel.fromJson(json); +} + +/// @nodoc +mixin _$ModuleModel { + String get key => throw _privateConstructorUsedError; + String get display => throw _privateConstructorUsedError; + String get expirationDate => throw _privateConstructorUsedError; + String get startDate => throw _privateConstructorUsedError; + int get quantity => throw _privateConstructorUsedError; + + /// Serializes this ModuleModel to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of ModuleModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ModuleModelCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ModuleModelCopyWith<$Res> { + factory $ModuleModelCopyWith( + ModuleModel value, $Res Function(ModuleModel) then) = + _$ModuleModelCopyWithImpl<$Res, ModuleModel>; + @useResult + $Res call( + {String key, + String display, + String expirationDate, + String startDate, + int quantity}); +} + +/// @nodoc +class _$ModuleModelCopyWithImpl<$Res, $Val extends ModuleModel> + implements $ModuleModelCopyWith<$Res> { + _$ModuleModelCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ModuleModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? key = null, + Object? display = null, + Object? expirationDate = null, + Object? startDate = null, + Object? quantity = null, + }) { + return _then(_value.copyWith( + key: null == key + ? _value.key + : key // ignore: cast_nullable_to_non_nullable + as String, + display: null == display + ? _value.display + : display // ignore: cast_nullable_to_non_nullable + as String, + expirationDate: null == expirationDate + ? _value.expirationDate + : expirationDate // ignore: cast_nullable_to_non_nullable + as String, + startDate: null == startDate + ? _value.startDate + : startDate // ignore: cast_nullable_to_non_nullable + as String, + quantity: null == quantity + ? _value.quantity + : quantity // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ModuleModelImplCopyWith<$Res> + implements $ModuleModelCopyWith<$Res> { + factory _$$ModuleModelImplCopyWith( + _$ModuleModelImpl value, $Res Function(_$ModuleModelImpl) then) = + __$$ModuleModelImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String key, + String display, + String expirationDate, + String startDate, + int quantity}); +} + +/// @nodoc +class __$$ModuleModelImplCopyWithImpl<$Res> + extends _$ModuleModelCopyWithImpl<$Res, _$ModuleModelImpl> + implements _$$ModuleModelImplCopyWith<$Res> { + __$$ModuleModelImplCopyWithImpl( + _$ModuleModelImpl _value, $Res Function(_$ModuleModelImpl) _then) + : super(_value, _then); + + /// Create a copy of ModuleModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? key = null, + Object? display = null, + Object? expirationDate = null, + Object? startDate = null, + Object? quantity = null, + }) { + return _then(_$ModuleModelImpl( + key: null == key + ? _value.key + : key // ignore: cast_nullable_to_non_nullable + as String, + display: null == display + ? _value.display + : display // ignore: cast_nullable_to_non_nullable + as String, + expirationDate: null == expirationDate + ? _value.expirationDate + : expirationDate // ignore: cast_nullable_to_non_nullable + as String, + startDate: null == startDate + ? _value.startDate + : startDate // ignore: cast_nullable_to_non_nullable + as String, + quantity: null == quantity + ? _value.quantity + : quantity // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ModuleModelImpl implements _ModuleModel { + const _$ModuleModelImpl( + {required this.key, + required this.display, + required this.expirationDate, + required this.startDate, + required this.quantity}); + + factory _$ModuleModelImpl.fromJson(Map json) => + _$$ModuleModelImplFromJson(json); + + @override + final String key; + @override + final String display; + @override + final String expirationDate; + @override + final String startDate; + @override + final int quantity; + + @override + String toString() { + return 'ModuleModel(key: $key, display: $display, expirationDate: $expirationDate, startDate: $startDate, quantity: $quantity)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ModuleModelImpl && + (identical(other.key, key) || other.key == key) && + (identical(other.display, display) || other.display == display) && + (identical(other.expirationDate, expirationDate) || + other.expirationDate == expirationDate) && + (identical(other.startDate, startDate) || + other.startDate == startDate) && + (identical(other.quantity, quantity) || + other.quantity == quantity)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, key, display, expirationDate, startDate, quantity); + + /// Create a copy of ModuleModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ModuleModelImplCopyWith<_$ModuleModelImpl> get copyWith => + __$$ModuleModelImplCopyWithImpl<_$ModuleModelImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ModuleModelImplToJson( + this, + ); + } +} + +abstract class _ModuleModel implements ModuleModel { + const factory _ModuleModel( + {required final String key, + required final String display, + required final String expirationDate, + required final String startDate, + required final int quantity}) = _$ModuleModelImpl; + + factory _ModuleModel.fromJson(Map json) = + _$ModuleModelImpl.fromJson; + + @override + String get key; + @override + String get display; + @override + String get expirationDate; + @override + String get startDate; + @override + int get quantity; + + /// Create a copy of ModuleModel + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ModuleModelImplCopyWith<_$ModuleModelImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/shared/components/molecules/modules/data/models/module_model.g.dart b/lib/shared/components/molecules/modules/data/models/module_model.g.dart new file mode 100644 index 00000000..b2ab688f --- /dev/null +++ b/lib/shared/components/molecules/modules/data/models/module_model.g.dart @@ -0,0 +1,25 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'module_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$ModuleModelImpl _$$ModuleModelImplFromJson(Map json) => + _$ModuleModelImpl( + key: json['key'] as String, + display: json['display'] as String, + expirationDate: json['expirationDate'] as String, + startDate: json['startDate'] as String, + quantity: (json['quantity'] as num).toInt(), + ); + +Map _$$ModuleModelImplToJson(_$ModuleModelImpl instance) => + { + 'key': instance.key, + 'display': instance.display, + 'expirationDate': instance.expirationDate, + 'startDate': instance.startDate, + 'quantity': instance.quantity, + }; diff --git a/lib/shared/components/molecules/modules/data/repositories/index.dart b/lib/shared/components/molecules/modules/data/repositories/index.dart new file mode 100644 index 00000000..8474837b --- /dev/null +++ b/lib/shared/components/molecules/modules/data/repositories/index.dart @@ -0,0 +1 @@ +export 'license_repository_impl.dart'; diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart new file mode 100644 index 00000000..240d8733 --- /dev/null +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -0,0 +1,35 @@ +import 'package:hub/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart'; +import 'package:hub/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart'; +import 'package:hub/shared/components/molecules/modules/domain/respositories/license_repository.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:sqflite/sqflite.dart'; + +class LicenseRepositoryImpl implements LicenseRepository { + final LicenseLocalDataSource localDataSource = LicenseLocalDataSourceImpl(); + final LicenseRemoteDataSource remoteDataSource = LicenseRemoteDataSourceImpl(); + final Database database = DatabaseStorage.database; + + LicenseRepositoryImpl(); + + static get stream => LicenseRemoteDataSourceImpl().licenseStream; + + Future fetchLicense(bool isNewVersion) async { + return await remoteDataSource.fetchLicenses(isNewVersion); + } + + Future setupLicense(bool isNewVersion) async { + return await remoteDataSource.setupLicense(database, isNewVersion); + } + + Future cleanLicense() async { + return await remoteDataSource.cleanLicense(); + } + + Future g(String key) async { + return await localDataSource.g(key); + } + + Future s(String key, T value) async { + return await localDataSource.s(key, value); + } +} diff --git a/lib/shared/components/molecules/modules/domain/entities/index.dart b/lib/shared/components/molecules/modules/domain/entities/index.dart new file mode 100644 index 00000000..ccb3a9d2 --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/entities/index.dart @@ -0,0 +1,2 @@ +export 'license.dart'; +export 'module.dart'; diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart new file mode 100644 index 00000000..743580fa --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -0,0 +1,26 @@ +import 'package:equatable/equatable.dart'; +import 'module.dart'; + +enum ModuleStatus { active, inactive, disabled } + +extension ModuleStatusExtension on ModuleStatus { + String get value { + switch (this) { + case ModuleStatus.active: + return 'VISIVEL'; + case ModuleStatus.inactive: + return 'INVISIVEL'; + case ModuleStatus.disabled: + return 'DESABILITADO'; + } + } +} + +class License extends Equatable { + final List modules; + + const License({required this.modules}); + + @override + List get props => [modules]; +} diff --git a/lib/shared/components/molecules/modules/domain/entities/module.dart b/lib/shared/components/molecules/modules/domain/entities/module.dart new file mode 100644 index 00000000..f2821e54 --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/entities/module.dart @@ -0,0 +1,37 @@ +import 'package:hub/shared/components/molecules/modules/data/models/module_model.dart'; + +class Module { + final String key; + final String display; + final String expirationDate; + final String startDate; + final int quantity; + + Module({ + required this.key, + required this.display, + required this.expirationDate, + required this.startDate, + required this.quantity, + }); + + factory Module.fromModel(ModuleModel model) { + return Module( + key: model.key, + display: model.display, + expirationDate: model.expirationDate, + startDate: model.startDate, + quantity: model.quantity, + ); + } + + ModuleModel toModel() { + return ModuleModel( + key: key, + display: display, + expirationDate: expirationDate, + startDate: startDate, + quantity: quantity, + ); + } +} diff --git a/lib/shared/components/molecules/modules/domain/index.dart b/lib/shared/components/molecules/modules/domain/index.dart new file mode 100644 index 00000000..00b76d59 --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/index.dart @@ -0,0 +1,3 @@ +export 'entities/index.dart'; +export 'respositories/index.dart'; +export 'usecases/index.dart'; diff --git a/lib/shared/components/molecules/modules/domain/respositories/index.dart b/lib/shared/components/molecules/modules/domain/respositories/index.dart new file mode 100644 index 00000000..7f6be535 --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/respositories/index.dart @@ -0,0 +1 @@ +export 'license_repository.dart'; diff --git a/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart new file mode 100644 index 00000000..877ed320 --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart @@ -0,0 +1,8 @@ +abstract class LicenseRepository { + Future fetchLicense(bool isNewVersion); + Future setupLicense(bool isNewVersion); + Future cleanLicense(); + + Future g(String key); + Future s(String key, T value); +} diff --git a/lib/shared/components/molecules/modules/domain/usecases/index.dart b/lib/shared/components/molecules/modules/domain/usecases/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/shared/components/molecules/modules/enums/active_modules.dart b/lib/shared/components/molecules/modules/enums/active_modules.dart new file mode 100644 index 00000000..81c81234 --- /dev/null +++ b/lib/shared/components/molecules/modules/enums/active_modules.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + +enum ActiveModuleKey implements BaseModule { + messages, + liberations, + reservations, + access, + pets, + orders, + completeSchedule, + providerSchedule, + deliverySchedule, + qrCode, + visitors, + peopleOnTheProperty, + settings, + logout; + + @override + IconData get icon => throw UnimplementedError(); + + @override + String get name => throw UnimplementedError(); + + @override + String get route => throw UnimplementedError(); + + @override + String get value { + switch (this) { + case ActiveModuleKey.messages: + return 'FRE-HUB-MESSAGES'; + case ActiveModuleKey.liberations: + return 'FRE-HUB-LIBERATIONS'; + case ActiveModuleKey.reservations: + return 'FRE-HUB-RESERVATIONS'; + case ActiveModuleKey.access: + return 'FRE-HUB-ACCESS'; + case ActiveModuleKey.pets: + return 'FRE-HUB-PETS'; + case ActiveModuleKey.orders: + return 'FRE-HUB-ORDERS'; + case ActiveModuleKey.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case ActiveModuleKey.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case ActiveModuleKey.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case ActiveModuleKey.visitors: + return 'FRE-HUB-VISITORS'; + case ActiveModuleKey.qrCode: + return 'FRE-HUB-QRCODE'; + case ActiveModuleKey.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + default: + return ''; + } + } +} diff --git a/lib/shared/components/molecules/modules/enums/disabled_modules.dart b/lib/shared/components/molecules/modules/enums/disabled_modules.dart new file mode 100644 index 00000000..f773cc4e --- /dev/null +++ b/lib/shared/components/molecules/modules/enums/disabled_modules.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + +enum DisabledModuleKey implements BaseModule { + fastPass; + + @override + IconData get icon => throw UnimplementedError(); + + @override + String get name => throw UnimplementedError(); + + @override + String get route => throw UnimplementedError(); + + @override + String get value { + switch (this) { + case DisabledModuleKey.fastPass: + return 'FRE-HUB-FASTPASS'; + + default: + return ''; + } + } +} diff --git a/lib/shared/components/molecules/modules/enums/enum_modules.dart b/lib/shared/components/molecules/modules/enums/enum_modules.dart new file mode 100644 index 00000000..107a0e98 --- /dev/null +++ b/lib/shared/components/molecules/modules/enums/enum_modules.dart @@ -0,0 +1,277 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; + +abstract class BaseModule { + String get value; + String get name; + IconData get icon; + String get route; +} + +enum ModuleEnum implements BaseModule { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + vehicles, + residents, + openedVisits, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + petsHistory, + peopleOnTheProperty, + settings, + logout; + + @override + String get value { + switch (this) { + case ModuleEnum.messages: + return 'FRE-HUB-MESSAGES'; + case ModuleEnum.liberations: + return 'FRE-HUB-LIBERATIONS'; + case ModuleEnum.reservations: + return 'FRE-HUB-RESERVATIONS'; + case ModuleEnum.access: + return 'FRE-HUB-ACCESS'; + case ModuleEnum.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case ModuleEnum.vehicles: + return 'FRE-HUB-VEHICLES'; + case ModuleEnum.residents: + return 'FRE-HUB-RESIDENTS'; + case ModuleEnum.pets: + return 'FRE-HUB-PETS'; + case ModuleEnum.orders: + return 'FRE-HUB-ORDERS'; + case ModuleEnum.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case ModuleEnum.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case ModuleEnum.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case ModuleEnum.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case ModuleEnum.fastPass: + return 'FRE-HUB-FASTPASS'; + case ModuleEnum.visitors: + return 'FRE-HUB-VISITORS'; + case ModuleEnum.qrCode: + return 'FRE-HUB-QRCODE'; + case ModuleEnum.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + case ModuleEnum.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case ModuleEnum.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case ModuleEnum.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case ModuleEnum.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case ModuleEnum.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case ModuleEnum.openedVisits: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Visitas em Aberto', + enText: 'Opened Visits', + ); + case ModuleEnum.vehicles: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Veículos', + enText: 'Vehicles', + ); + case ModuleEnum.residents: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ); + case ModuleEnum.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case ModuleEnum.petsHistory: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case ModuleEnum.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case ModuleEnum.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case ModuleEnum.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case ModuleEnum.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case ModuleEnum.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case ModuleEnum.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case ModuleEnum.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case ModuleEnum.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case ModuleEnum.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case ModuleEnum.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + case ModuleEnum.logout: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ); + } + } + + @override + IconData get icon { + switch (this) { + case ModuleEnum.messages: + return Icons.chat_outlined; + case ModuleEnum.liberations: + return Icons.how_to_reg_outlined; + case ModuleEnum.reservations: + return Icons.event_available; + case ModuleEnum.access: + return Icons.transfer_within_a_station_outlined; + case ModuleEnum.openedVisits: + return Icons.perm_contact_calendar; + case ModuleEnum.vehicles: + return Icons.directions_car; + case ModuleEnum.residents: + return Icons.groups; + case ModuleEnum.pets: + return Icons.pets; + case ModuleEnum.petsHistory: + return Icons.pets; + case ModuleEnum.peopleOnTheProperty: + return Icons.groups; + case ModuleEnum.orders: + return Icons.inventory_2_outlined; + case ModuleEnum.completeSchedule: + return Icons.event; + case ModuleEnum.providerSchedule: + return Icons.engineering_outlined; + case ModuleEnum.deliverySchedule: + return Icons.sports_motorsports_outlined; + case ModuleEnum.fastPass: + return Icons.attach_email_outlined; + case ModuleEnum.qrCode: + return Icons.qr_code; + case ModuleEnum.visitors: + return Icons.person_add_alt_1_outlined; + case ModuleEnum.aboutProperty: + return Icons.home; + case ModuleEnum.settings: + return Icons.settings; + case ModuleEnum.logout: + return Icons.logout; + } + } + + @override + String get route { + switch (this) { + case ModuleEnum.messages: + return '/messageHistoryPage'; + case ModuleEnum.liberations: + return '/liberationHistory'; + case ModuleEnum.reservations: + return '/reservation'; + case ModuleEnum.access: + return '/acessHistoryPage'; + case ModuleEnum.openedVisits: + return '/visitsOnThePropertyPage'; + case ModuleEnum.vehicles: + return '/vehiclesOnThePropertyPage'; + case ModuleEnum.residents: + return '/residentsOnThePropertyPage'; + case ModuleEnum.pets: + return '/petsPage'; + case ModuleEnum.petsHistory: + return '/petsHistoryPage'; + case ModuleEnum.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case ModuleEnum.orders: + return '/packageOrder'; + case ModuleEnum.completeSchedule: + return '/scheduleCompleteVisitPage'; + case ModuleEnum.providerSchedule: + return '/provisionalSchedule'; + case ModuleEnum.aboutProperty: + return '/aboutProperty'; + case ModuleEnum.deliverySchedule: + return '/deliverySchedule'; + case ModuleEnum.fastPass: + return '/fastPassPage'; + case ModuleEnum.qrCode: + return '/qrCodePage'; + case ModuleEnum.visitors: + return '/registerVisitorPage'; + case ModuleEnum.settings: + return '/preferencesSettings'; + case ModuleEnum.logout: + return '/WelcomePage'; + default: + return ''; + } + } +} diff --git a/lib/shared/components/molecules/modules/enums/inactive_modules.dart b/lib/shared/components/molecules/modules/enums/inactive_modules.dart new file mode 100644 index 00000000..ff2dbaa5 --- /dev/null +++ b/lib/shared/components/molecules/modules/enums/inactive_modules.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/modules/enums/enum_modules.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + +enum InactiveModuleKey implements BaseModule { + residents, + vehicles, + openedVisits, + petsHistory, + aboutProperty; + + @override + IconData get icon => throw UnimplementedError(); + + @override + String get name => throw UnimplementedError(); + + @override + String get route => throw UnimplementedError(); + + @override + String get value { + switch (this) { + case InactiveModuleKey.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case InactiveModuleKey.vehicles: + return 'FRE-HUB-VEHICLES'; + case InactiveModuleKey.residents: + return 'FRE-HUB-RESIDENTS'; + case InactiveModuleKey.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + case InactiveModuleKey.aboutProperty: + return 'FRE-HUB-PROPERTY'; + default: + return ''; + } + } +} diff --git a/lib/shared/components/molecules/modules/enums/index.dart b/lib/shared/components/molecules/modules/enums/index.dart new file mode 100644 index 00000000..77515664 --- /dev/null +++ b/lib/shared/components/molecules/modules/enums/index.dart @@ -0,0 +1,4 @@ +export 'active_modules.dart'; +export 'disabled_modules.dart'; +export 'enum_modules.dart'; +export 'inactive_modules.dart'; diff --git a/lib/shared/components/molecules/modules/index.dart b/lib/shared/components/molecules/modules/index.dart new file mode 100644 index 00000000..d58702fc --- /dev/null +++ b/lib/shared/components/molecules/modules/index.dart @@ -0,0 +1,4 @@ +export 'data/index.dart'; +export 'domain/index.dart'; +export 'presentation/index.dart'; +export 'enums/index.dart'; diff --git a/lib/shared/components/molecules/modules/presentation/blocs/index.dart b/lib/shared/components/molecules/modules/presentation/blocs/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/shared/components/molecules/modules/presentation/index.dart b/lib/shared/components/molecules/modules/presentation/index.dart new file mode 100644 index 00000000..48b6447a --- /dev/null +++ b/lib/shared/components/molecules/modules/presentation/index.dart @@ -0,0 +1,3 @@ +export 'blocs/index.dart'; +export 'pages/index.dart'; +export 'widgets/index.dart'; diff --git a/lib/shared/components/molecules/modules/presentation/pages/index.dart b/lib/shared/components/molecules/modules/presentation/pages/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/shared/components/molecules/modules/presentation/widgets/index.dart b/lib/shared/components/molecules/modules/presentation/widgets/index.dart new file mode 100644 index 00000000..e69de29b From bb6e6e48619e4c2864a692db55eedbaff1070a03 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 28 Nov 2024 17:56:30 -0300 Subject: [PATCH 20/75] mileston: fix pets_history --- .../molecules/modules/enums/enum_modules.dart | 272 ++++++++++++++++++ 1 file changed, 272 insertions(+) diff --git a/lib/shared/components/molecules/modules/enums/enum_modules.dart b/lib/shared/components/molecules/modules/enums/enum_modules.dart index 107a0e98..c46ab43f 100644 --- a/lib/shared/components/molecules/modules/enums/enum_modules.dart +++ b/lib/shared/components/molecules/modules/enums/enum_modules.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; abstract class BaseModule { String get value; @@ -275,3 +276,274 @@ enum ModuleEnum implements BaseModule { } } } + +enum MenuEntries implements BaseEntry { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + vehicles, + residents, + openedVisits, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + petsHistory, + peopleOnTheProperty, + settings, + logout; + + @override + String get value { + switch (this) { + case ModuleEnum.messages: + return 'FRE-HUB-MESSAGES'; + case ModuleEnum.liberations: + return 'FRE-HUB-LIBERATIONS'; + case ModuleEnum.reservations: + return 'FRE-HUB-RESERVATIONS'; + case ModuleEnum.access: + return 'FRE-HUB-ACCESS'; + case ModuleEnum.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case ModuleEnum.vehicles: + return 'FRE-HUB-VEHICLES'; + case ModuleEnum.residents: + return 'FRE-HUB-RESIDENTS'; + case ModuleEnum.pets: + return 'FRE-HUB-PETS'; + case ModuleEnum.orders: + return 'FRE-HUB-ORDERS'; + case ModuleEnum.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case ModuleEnum.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case ModuleEnum.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case ModuleEnum.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case ModuleEnum.fastPass: + return 'FRE-HUB-FASTPASS'; + case ModuleEnum.visitors: + return 'FRE-HUB-VISITORS'; + case ModuleEnum.qrCode: + return 'FRE-HUB-QRCODE'; + case ModuleEnum.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + case ModuleEnum.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case ModuleEnum.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case ModuleEnum.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case ModuleEnum.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case ModuleEnum.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case ModuleEnum.openedVisits: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Visitas em Aberto', + enText: 'Opened Visits', + ); + case ModuleEnum.vehicles: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Veículos', + enText: 'Vehicles', + ); + case ModuleEnum.residents: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ); + case ModuleEnum.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case ModuleEnum.petsHistory: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case ModuleEnum.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case ModuleEnum.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case ModuleEnum.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case ModuleEnum.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case ModuleEnum.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case ModuleEnum.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case ModuleEnum.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case ModuleEnum.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case ModuleEnum.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case ModuleEnum.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + case ModuleEnum.logout: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ); + default: + return ''; + } + } + + @override + IconData get icon { + switch (this) { + case ModuleEnum.messages: + return Icons.chat_outlined; + case ModuleEnum.liberations: + return Icons.how_to_reg_outlined; + case ModuleEnum.reservations: + return Icons.event_available; + case ModuleEnum.access: + return Icons.transfer_within_a_station_outlined; + case ModuleEnum.openedVisits: + return Icons.perm_contact_calendar; + case ModuleEnum.vehicles: + return Icons.directions_car; + case ModuleEnum.residents: + return Icons.groups; + case ModuleEnum.pets: + return Icons.pets; + case ModuleEnum.petsHistory: + return Icons.pets; + case ModuleEnum.peopleOnTheProperty: + return Icons.groups; + case ModuleEnum.orders: + return Icons.inventory_2_outlined; + case ModuleEnum.completeSchedule: + return Icons.event; + case ModuleEnum.providerSchedule: + return Icons.engineering_outlined; + case ModuleEnum.deliverySchedule: + return Icons.sports_motorsports_outlined; + case ModuleEnum.fastPass: + return Icons.attach_email_outlined; + case ModuleEnum.qrCode: + return Icons.qr_code; + case ModuleEnum.visitors: + return Icons.person_add_alt_1_outlined; + case ModuleEnum.aboutProperty: + return Icons.home; + case ModuleEnum.settings: + return Icons.settings; + case ModuleEnum.logout: + return Icons.logout; + default: + return Icons.error; + } + } + + @override + String get route { + switch (this) { + case ModuleEnum.messages: + return '/messageHistoryPage'; + case ModuleEnum.liberations: + return '/liberationHistory'; + case ModuleEnum.reservations: + return '/reservation'; + case ModuleEnum.access: + return '/acessHistoryPage'; + case ModuleEnum.openedVisits: + return '/visitsOnThePropertyPage'; + case ModuleEnum.vehicles: + return '/vehiclesOnThePropertyPage'; + case ModuleEnum.residents: + return '/residentsOnThePropertyPage'; + case ModuleEnum.pets: + return '/petsPage'; + case ModuleEnum.petsHistory: + return '/petsHistoryPage'; + case ModuleEnum.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case ModuleEnum.orders: + return '/packageOrder'; + case ModuleEnum.completeSchedule: + return '/scheduleCompleteVisitPage'; + case ModuleEnum.providerSchedule: + return '/provisionalSchedule'; + case ModuleEnum.aboutProperty: + return '/aboutProperty'; + case ModuleEnum.deliverySchedule: + return '/deliverySchedule'; + case ModuleEnum.fastPass: + return '/fastPassPage'; + case ModuleEnum.qrCode: + return '/qrCodePage'; + case ModuleEnum.visitors: + return '/registerVisitorPage'; + case ModuleEnum.settings: + return '/preferencesSettings'; + case ModuleEnum.logout: + return '/WelcomePage'; + default: + return ''; + } + } +} From 54fcab5c16d70d04e0ce04ad2d5f06bcb41ceddc Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 29 Nov 2024 11:23:55 -0300 Subject: [PATCH 21/75] WIP --- analysis_options.yaml | 1 + lib/backend/schema/enums/enums.dart | 12 - .../menu_item/menu_item.dart | 36 - .../menu_component/menu_component_widget.dart | 81 -- .../menu_list_view_component_model.dart | 11 - .../menu_staggered_view_component_model.dart | 13 - .../menu_staggered_view_component_widget.dart | 193 ----- .../sign_in_template_component_widget.dart | 90 +-- .../sign_up_template_component_widget.dart | 46 +- lib/core/meta/anotations.dart | 7 + .../home/data/data_sources}/index.dart | 0 lib/features/home/data/index.dart | 3 + lib/features/home/data/models/index.dart | 0 .../home/data/repositories/index.dart | 0 lib/features/home/domain/entities/index.dart | 0 lib/features/home/domain/index.dart | 3 + .../home/domain/respositories/index.dart | 0 lib/features/home/domain/usecases/index.dart | 0 lib/features/home/index.dart | 3 + .../home/presentation/blocs}/home_bloc.dart | 0 .../home/presentation/blocs}/home_events.dart | 0 .../home/presentation/blocs}/home_state.dart | 0 .../home/presentation/blocs}/index.dart | 0 lib/features/home/presentation/index.dart | 3 + .../home/presentation/pages}/home_page.dart | 21 +- .../home/presentation/pages/index.dart | 1 + .../home/presentation/widgets/index.dart | 0 .../property/data/data_sources/index.dart | 0 lib/features/property/data/index.dart | 3 + lib/features/property/data/models/index.dart | 0 .../property/data/repositories/index.dart | 0 .../property/domain/entities/index.dart | 0 lib/features/property/domain/index.dart | 3 + .../property/domain/respositories/index.dart | 0 .../property/domain/usecases/index.dart | 0 lib/features/property/index.dart | 3 + .../property/presentation/blocs/index.dart | 0 lib/features/property/presentation/index.dart | 3 + .../pages}/about_property_screen.dart | 51 +- .../property/presentation/pages/index.dart | 1 + .../property/presentation/widgets/index.dart | 0 lib/flutter_flow/nav/nav.dart | 9 +- lib/index.dart | 12 +- lib/initialization.dart | 1 - lib/main.dart | 4 +- .../about_property_model.dart | 23 - .../preferences_settings_model.dart | 4 +- .../reception_page/reception_page_widget.dart | 26 +- .../atoms/image_cropper}/image_cropper.dart | 0 .../{ => term_of_use}/atom_terms_of_use.dart | 5 +- .../molecules/drawer}/drawer_widget.dart | 24 +- .../components/molecules/drawer/index.dart | 1 + .../locals/data/data_sources/index.dart | 2 + .../locals_local_data_source.dart | 3 + .../locals_remote_data_source.dart} | 61 +- .../molecules/locals/data/index.dart | 3 + .../molecules/locals/data/models/index.dart | 0 .../locals/data/repositories/index.dart | 1 + .../repositories/locals_repository_impl.dart | 32 + .../locals/domain/entities/index.dart | 0 .../molecules/locals/domain/index.dart | 3 + .../locals/domain/respositories/index.dart | 1 + .../respositories/locals_repository.dart | 10 + .../locals/domain/usecases/index.dart | 0 .../components/molecules/locals/index.dart | 3 + .../locals/presentation/blocs/index.dart | 1 + .../blocs}/local_profile_bloc.dart | 2 +- .../molecules/locals/presentation/index.dart | 2 + .../locals/presentation/widgets/index.dart | 1 + .../widgets/local_profile_widget.dart} | 15 +- .../menu/data/data_sources/index.dart | 0 .../components/molecules/menu/data/index.dart | 3 + .../menu/data/models/base_entry.dart | 5 + .../molecules/menu/data/models/index.dart | 1 + .../menu/data/repositories/index.dart | 0 .../molecules/menu/domain/entities/index.dart | 0 .../menu/domain/entities/menu_entry.dart | 18 + .../molecules/menu/domain/index.dart | 3 + .../menu/domain/respositories/index.dart | 0 .../molecules/menu/domain/usecases/index.dart | 0 .../components/molecules/menu/index.dart | 3 + .../menu/presentation/blocs/index.dart | 1 + .../menu/presentation/blocs/menu_bloc.dart | 9 + .../presentation/blocs/menu_item_bloc.dart | 9 + .../presentation/blocs/menu_view_bloc.dart} | 41 +- .../molecules/menu/presentation/index.dart | 2 + .../menu/presentation/widgets/index.dart | 4 + .../widgets/menu_entry/drawer_menu_entry.dart | 223 ++++++ .../widgets/menu_entry/home_menu_entry.dart | 213 ++++++ .../widgets/menu_entry/index.dart | 4 + .../menu_entry/menu_entry_factory.dart | 38 + .../menu_entry/property_menu_entry.dart | 67 ++ .../widgets/menu_factory/index.dart | 1 + .../widgets/menu_factory/menu_factory.dart | 25 + .../presentation/widgets/menu_item/index.dart | 4 + .../widgets/menu_item/menu_item.dart | 42 ++ .../widgets/menu_item/menu_item_button.dart} | 14 +- .../widgets/menu_item/menu_item_card.dart} | 11 +- .../widgets/menu_item/menu_item_factory.dart | 24 + .../presentation/widgets/menu_view/index.dart | 3 + .../widgets/menu_view/menu_list_view.dart} | 113 +-- .../menu_view/menu_staggered_view.dart | 206 ++++++ .../widgets/menu_view/menu_view_factory.dart | 87 +++ .../license_local_data_source.dart | 1 + .../license_remote_data_source.dart | 35 +- .../repositories/license_repository_impl.dart | 6 +- .../entities}/active_modules.dart | 9 - .../modules/domain/entities/base_module.dart | 10 + .../entities}/disabled_modules.dart | 0 .../entities}/inactive_modules.dart | 11 +- .../modules/domain/entities/index.dart | 5 + .../modules/domain/entities/modules.dart | 271 +++++++ .../molecules/modules/enums/enum_modules.dart | 549 -------------- .../molecules/modules/enums/index.dart | 4 - .../components/molecules/modules/index.dart | 1 - .../molecules/modules/presentation/index.dart | 1 - lib/shared/enums/enum_menu.dart | 699 ++++++++++++++++++ .../helpers/database/database_helper.dart | 35 +- .../helpers/license/license_helper.dart | 443 ----------- .../helpers/storage/keychain_storage.dart | 3 +- .../services/deeplink/deep_link_service.dart | 4 +- .../services/keychain/keychain_service.dart | 5 - .../services/license/license_service.dart | 103 --- lib/shared/widgets/menu.dart | 56 -- pubspec.lock | 279 ++++++- pubspec.yaml | 5 + 126 files changed, 2668 insertions(+), 1878 deletions(-) delete mode 100644 lib/components/molecular_components/menu_item/menu_item.dart delete mode 100644 lib/components/organism_components/menu_component/menu_component_widget.dart delete mode 100644 lib/components/organism_components/menu_list_view_component/menu_list_view_component_model.dart delete mode 100644 lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart delete mode 100644 lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart create mode 100644 lib/core/meta/anotations.dart rename lib/{shared/components/molecules/modules/presentation/pages => features/home/data/data_sources}/index.dart (100%) create mode 100644 lib/features/home/data/index.dart create mode 100644 lib/features/home/data/models/index.dart create mode 100644 lib/features/home/data/repositories/index.dart create mode 100644 lib/features/home/domain/entities/index.dart create mode 100644 lib/features/home/domain/index.dart create mode 100644 lib/features/home/domain/respositories/index.dart create mode 100644 lib/features/home/domain/usecases/index.dart create mode 100644 lib/features/home/index.dart rename lib/{pages/home_page => features/home/presentation/blocs}/home_bloc.dart (100%) rename lib/{pages/home_page => features/home/presentation/blocs}/home_events.dart (100%) rename lib/{pages/home_page => features/home/presentation/blocs}/home_state.dart (100%) rename lib/{pages/home_page => features/home/presentation/blocs}/index.dart (100%) create mode 100644 lib/features/home/presentation/index.dart rename lib/{pages/home_page => features/home/presentation/pages}/home_page.dart (85%) create mode 100644 lib/features/home/presentation/pages/index.dart create mode 100644 lib/features/home/presentation/widgets/index.dart create mode 100644 lib/features/property/data/data_sources/index.dart create mode 100644 lib/features/property/data/index.dart create mode 100644 lib/features/property/data/models/index.dart create mode 100644 lib/features/property/data/repositories/index.dart create mode 100644 lib/features/property/domain/entities/index.dart create mode 100644 lib/features/property/domain/index.dart create mode 100644 lib/features/property/domain/respositories/index.dart create mode 100644 lib/features/property/domain/usecases/index.dart create mode 100644 lib/features/property/index.dart create mode 100644 lib/features/property/presentation/blocs/index.dart create mode 100644 lib/features/property/presentation/index.dart rename lib/{pages/about_property_page => features/property/presentation/pages}/about_property_screen.dart (63%) create mode 100644 lib/features/property/presentation/pages/index.dart create mode 100644 lib/features/property/presentation/widgets/index.dart delete mode 100644 lib/pages/about_property_page/about_property_model.dart rename lib/shared/{widgets/image_cropper_widget => components/atoms/image_cropper}/image_cropper.dart (100%) rename lib/shared/components/atoms/{ => term_of_use}/atom_terms_of_use.dart (88%) rename lib/shared/{widgets/drawer_widget => components/molecules/drawer}/drawer_widget.dart (89%) create mode 100644 lib/shared/components/molecules/drawer/index.dart create mode 100644 lib/shared/components/molecules/locals/data/data_sources/index.dart create mode 100644 lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart rename lib/shared/{services/localization/localization_service.dart => components/molecules/locals/data/data_sources/locals_remote_data_source.dart} (88%) create mode 100644 lib/shared/components/molecules/locals/data/index.dart create mode 100644 lib/shared/components/molecules/locals/data/models/index.dart create mode 100644 lib/shared/components/molecules/locals/data/repositories/index.dart create mode 100644 lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart create mode 100644 lib/shared/components/molecules/locals/domain/entities/index.dart create mode 100644 lib/shared/components/molecules/locals/domain/index.dart create mode 100644 lib/shared/components/molecules/locals/domain/respositories/index.dart create mode 100644 lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart create mode 100644 lib/shared/components/molecules/locals/domain/usecases/index.dart create mode 100644 lib/shared/components/molecules/locals/index.dart create mode 100644 lib/shared/components/molecules/locals/presentation/blocs/index.dart rename lib/{components/organism_components/local_profile_component => shared/components/molecules/locals/presentation/blocs}/local_profile_bloc.dart (93%) create mode 100644 lib/shared/components/molecules/locals/presentation/index.dart create mode 100644 lib/shared/components/molecules/locals/presentation/widgets/index.dart rename lib/{components/organism_components/local_profile_component/local_profile_component_widget.dart => shared/components/molecules/locals/presentation/widgets/local_profile_widget.dart} (87%) create mode 100644 lib/shared/components/molecules/menu/data/data_sources/index.dart create mode 100644 lib/shared/components/molecules/menu/data/index.dart create mode 100644 lib/shared/components/molecules/menu/data/models/base_entry.dart create mode 100644 lib/shared/components/molecules/menu/data/models/index.dart create mode 100644 lib/shared/components/molecules/menu/data/repositories/index.dart create mode 100644 lib/shared/components/molecules/menu/domain/entities/index.dart create mode 100644 lib/shared/components/molecules/menu/domain/entities/menu_entry.dart create mode 100644 lib/shared/components/molecules/menu/domain/index.dart create mode 100644 lib/shared/components/molecules/menu/domain/respositories/index.dart create mode 100644 lib/shared/components/molecules/menu/domain/usecases/index.dart create mode 100644 lib/shared/components/molecules/menu/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/blocs/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart create mode 100644 lib/shared/components/molecules/menu/presentation/blocs/menu_item_bloc.dart rename lib/{components/organism_components/menu_component/menu_component_bloc.dart => shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart} (73%) create mode 100644 lib/shared/components/molecules/menu/presentation/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item.dart rename lib/{components/atomic_components/menu_button_item/menu_button_item_widget.dart => shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart} (91%) rename lib/{components/atomic_components/menu_card_item/menu_card_item.dart => shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart} (89%) create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart rename lib/{components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart => shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart} (56%) create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart create mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart rename lib/shared/components/molecules/modules/{enums => domain/entities}/active_modules.dart (84%) create mode 100644 lib/shared/components/molecules/modules/domain/entities/base_module.dart rename lib/shared/components/molecules/modules/{enums => domain/entities}/disabled_modules.dart (100%) rename lib/shared/components/molecules/modules/{enums => domain/entities}/inactive_modules.dart (77%) create mode 100644 lib/shared/components/molecules/modules/domain/entities/modules.dart delete mode 100644 lib/shared/components/molecules/modules/enums/enum_modules.dart delete mode 100644 lib/shared/components/molecules/modules/enums/index.dart create mode 100644 lib/shared/enums/enum_menu.dart delete mode 100644 lib/shared/helpers/license/license_helper.dart delete mode 100644 lib/shared/services/keychain/keychain_service.dart delete mode 100644 lib/shared/services/license/license_service.dart delete mode 100644 lib/shared/widgets/menu.dart diff --git a/analysis_options.yaml b/analysis_options.yaml index 4934b3e6..53fc4048 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -32,6 +32,7 @@ analyzer: errors: curly_braces_in_flow_control_structures: ignore use_build_context_synchronously: ignore + invalid_annotation_target: ignore exclude: - lib/custom_code/** - lib/flutter_flow/custom_functions.dart diff --git a/lib/backend/schema/enums/enums.dart b/lib/backend/schema/enums/enums.dart index 3013905b..8f7ed174 100644 --- a/lib/backend/schema/enums/enums.dart +++ b/lib/backend/schema/enums/enums.dart @@ -5,18 +5,6 @@ enum AppHeaderComponent { home, } -enum MenuView { - list_grid, - list, - grid, -} - -enum MenuItem { - button, - card, - tile, -} - extension FFEnumExtensions on T { String serialize() => name; } diff --git a/lib/components/molecular_components/menu_item/menu_item.dart b/lib/components/molecular_components/menu_item/menu_item.dart deleted file mode 100644 index 77734bc1..00000000 --- a/lib/components/molecular_components/menu_item/menu_item.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'package:flutter/material.dart'; - -enum MenuOption { - CompleteSchedule, - DeliverySchedule, - WorkersOnTheProperty, - FastPassSchedule, - QRCodeAccessInProperty, - AccessOnTheProperty, - LiberationsOnTheProperty, - MessagesOnTheProperty, - ReservationsOnTheLocal, - PackagesOnTheProperty, - VehiclesOnTheProperty, - PetsOnTheProperty, - PetsRegister, - VisitorsRegister, - VisitsOnTheProperty, - ResidentsOnTheProperty, - SettingsOnTheApp, - AboutProperty, - LogoutOnTheApp, -} - -abstract class MenuEntry extends StatefulWidget { - const MenuEntry({ - super.key, - required this.action, - required this.title, - required this.icon, - }); - - final Function() action; - final String title; - final IconData icon; -} diff --git a/lib/components/organism_components/menu_component/menu_component_widget.dart b/lib/components/organism_components/menu_component/menu_component_widget.dart deleted file mode 100644 index 6277c62a..00000000 --- a/lib/components/organism_components/menu_component/menu_component_widget.dart +++ /dev/null @@ -1,81 +0,0 @@ -import 'package:hub/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/organism_components/menu_component/menu_component_bloc.dart'; -import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; -import 'package:hub/shared/services/license/license_service.dart'; - -class MenuComponentWidget extends StatelessWidget { - final MenuView style; - final MenuItem item; - final bool expandable; - final List menuOptions; - - const MenuComponentWidget({ - super.key, - required this.style, - required this.item, - required this.expandable, - required this.menuOptions, - }); - - @override - Widget build(BuildContext context) { - return StreamBuilder>( - stream: LicenseService().licenseStream, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: CircularProgressIndicator(), - ); - } else if (snapshot.hasError) { - return Center( - child: Text('Error: ${snapshot.error}'), - ); - } else if (!snapshot.hasData || snapshot.data!.isEmpty) { - return Center( - child: Padding( - padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), - child: CircularProgressIndicator( - backgroundColor: FlutterFlowTheme.of(key.currentContext!).primaryBackground, - color: FlutterFlowTheme.of(key.currentContext!).primary), - ), - ); - } - return BlocProvider( - create: (context) => MenuBloc( - style: style, - item: item, - expandable: expandable, - menuOptions: menuOptions, - )..add(MenuEvent()), - child: BlocBuilder( - builder: (context, state) { - if (style == MenuView.list_grid) { - return MenuStaggeredViewComponentWidget( - options: state.menuEntries, - expandable: expandable, - item: item, - changeMenuStyle: () async {}, - isGrid: state.isGrid, - ); - } else if (style == MenuView.list) { - return MenuListViewComponentWidget( - options: state.menuEntries, - expandable: expandable, - item: item, - changeMenuStyle: () async {}, - ); - } - return const SizedBox(); - }, - ), - ); - }, - ); - } -} diff --git a/lib/components/organism_components/menu_list_view_component/menu_list_view_component_model.dart b/lib/components/organism_components/menu_list_view_component/menu_list_view_component_model.dart deleted file mode 100644 index d15273ee..00000000 --- a/lib/components/organism_components/menu_list_view_component/menu_list_view_component_model.dart +++ /dev/null @@ -1,11 +0,0 @@ -import '/flutter_flow/flutter_flow_util.dart'; -import 'menu_list_view_component_widget.dart' show MenuListViewComponentWidget; -import 'package:flutter/material.dart'; - -class MenuListViewComponentModel extends FlutterFlowModel { - @override - void initState(BuildContext context) {} - - @override - void dispose() {} -} diff --git a/lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart b/lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart deleted file mode 100644 index cb0efe51..00000000 --- a/lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart'; - -import '/flutter_flow/flutter_flow_util.dart'; - -import 'package:flutter/material.dart'; - -class MenuStaggeredViewComponentModel extends FlutterFlowModel { - @override - void initState(BuildContext context) {} - - @override - void dispose() {} -} diff --git a/lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart b/lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart deleted file mode 100644 index 64161e26..00000000 --- a/lib/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_widget.dart +++ /dev/null @@ -1,193 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; -import 'package:hub/components/organism_components/menu_staggered_view_component/menu_staggered_view_component_model.dart'; -import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; - -class MenuStaggeredViewComponentWidget extends StatefulWidget { - const MenuStaggeredViewComponentWidget( - {super.key, - required this.changeMenuStyle, - required this.expandable, - required this.item, - required this.options, - required this.isGrid}); - - final bool expandable; - final MenuItem item; - final bool isGrid; - - final List options; - final Future Function()? changeMenuStyle; - - @override - State createState() => _MenuStaggeredViewComponentWidgetState(); -} - -class _MenuStaggeredViewComponentWidgetState extends State { - late MenuStaggeredViewComponentModel _model; - - @override - void setState(VoidCallback callback) { - super.setState(callback); - _model.onUpdate(); - } - - @override - void initState() { - super.initState(); - _model = createModel(context, () => MenuStaggeredViewComponentModel()); - } - - @override - void dispose() { - _model.maybeDispose(); - - super.dispose(); - } - - @override - Widget build(BuildContext context) { - final textScaler = MediaQuery.textScalerOf(context); - final double scaledFontSize = 14 * textScaler.scale(1); - final int crossAxisCount = scaledFontSize >= 26 - ? 1 - : scaledFontSize >= 18 - ? 2 - : 3; - - return Column( - children: [ - GridView.builder( - physics: const NeverScrollableScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: crossAxisCount, - crossAxisSpacing: 10.0, - mainAxisSpacing: 10.0, - childAspectRatio: 1, - mainAxisExtent: 100, - ), - itemCount: widget.options.length, - padding: const EdgeInsets.symmetric(horizontal: 14), - shrinkWrap: true, - itemBuilder: (context, index) { - return Container( - height: MediaQuery.of(context).size.height, - width: MediaQuery.of(context).size.width, - alignment: Alignment.center, - padding: const EdgeInsets.all(0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(0), - color: Colors.transparent, - boxShadow: const [ - BoxShadow( - color: Colors.transparent, - blurRadius: 4, - offset: Offset(0, 2), - ), - ], - ), - child: Center(child: widget.options[index]), - ); - }, - ), - ].addToStart(const SizedBox(height: 30)).addToEnd(const SizedBox(height: 30)), - ); - } - - Widget collapseExpandMethod(BuildContext context) { - if (widget.isGrid == true) { - return Align( - alignment: const AlignmentDirectional(0.0, 0.0), - child: Container( - decoration: const BoxDecoration( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(0.0), - bottomRight: Radius.circular(0.0), - topLeft: Radius.circular(0.0), - topRight: Radius.circular(0.0), - ), - ), - alignment: const AlignmentDirectional(0.0, 0.0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - Text( - FFLocalizations.of(context).getVariableText( - enText: 'Minimize', - ptText: 'Minimizar', - ), - style: FlutterFlowTheme.of(context).title1.override( - fontFamily: 'Nunito', - color: FlutterFlowTheme.of(context).primaryText, - fontSize: 12.0, - fontWeight: FontWeight.w600, - fontStyle: FontStyle.normal, - ), - ), - Align( - alignment: const AlignmentDirectional(0.0, 0.0), - child: FlutterFlowIconButton( - borderColor: Colors.transparent, - borderRadius: 20.0, - borderWidth: 1.0, - buttonSize: 50.0, - fillColor: const Color(0x00FFFFFF), - icon: Icon( - Icons.keyboard_arrow_up_sharp, - color: FlutterFlowTheme.of(context).primary, - ), - onPressed: () async { - await widget.changeMenuStyle?.call(); - }, - ), - ), - ], - ), - ), - ); - } else { - return Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - FFLocalizations.of(context).getVariableText( - enText: 'Expand', - ptText: 'Expandir', - ), - style: FlutterFlowTheme.of(context).title1.override( - fontFamily: 'Nunito', - color: FlutterFlowTheme.of(context).primaryText, - fontSize: 12.0, - fontWeight: FontWeight.w600, - fontStyle: FontStyle.normal, - ), - ), - Align( - alignment: const AlignmentDirectional(0.0, 0.0), - child: FlutterFlowIconButton( - borderColor: Colors.transparent, - borderRadius: 20.0, - borderWidth: 0.0, - buttonSize: 50.0, - fillColor: const Color(0x00FFFFFF), - icon: Icon( - Icons.keyboard_arrow_down_outlined, - color: FlutterFlowTheme.of(context).primary, - ), - onPressed: () async { - await widget.changeMenuStyle?.call(); - }, - ), - ), - ], - ); - } - } -} diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart index e476c98a..d339f173 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; 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/components/atoms/term_of_use/atom_terms_of_use.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; import 'package:hub/shared/utils/log_util.dart'; @@ -215,8 +215,7 @@ class _SignInTemplateComponentWidgetState extends State EasyDebounce.debounce('_model.passwordTextController', - const Duration(milliseconds: 500), () => setState(() {})), + onChanged: (_) => EasyDebounce.debounce('_model.passwordTextController', const Duration(milliseconds: 500), () => setState(() {})), autofocus: true, autofillHints: const [AutofillHints.password], textInputAction: TextInputAction.send, obscureText: !_model.passwordVisibility, decoration: InputDecoration( isDense: true, - labelText: - FFLocalizations.of(context).getText('2x19ce8k' /* Senha */), + labelText: FFLocalizations.of(context).getText('2x19ce8k' /* Senha */), labelStyle: FlutterFlowTheme.of(context).labelLarge.override( fontFamily: 'Plus Jakarta Sans', color: FlutterFlowTheme.of(context).primaryText, fontSize: limitedInputFontSize, letterSpacing: 0.0, fontWeight: FontWeight.w500, - useGoogleFonts: - GoogleFonts.asMap().containsKey('Plus Jakarta Sans')), + useGoogleFonts: GoogleFonts.asMap().containsKey('Plus Jakarta Sans')), enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).customColor1, width: 0.25), + borderSide: BorderSide(color: FlutterFlowTheme.of(context).customColor1, width: 0.25), borderRadius: BorderRadius.circular(12.0), ), errorStyle: TextStyle( @@ -310,9 +303,7 @@ class _SignInTemplateComponentWidgetState extends State setState( - () => _model.passwordVisibility = !_model.passwordVisibility), + onTap: () => setState(() => _model.passwordVisibility = !_model.passwordVisibility), focusNode: FocusNode(skipTraversal: true), - child: Icon( - _model.passwordVisibility - ? Icons.visibility_outlined - : Icons.visibility_off_outlined, - color: FlutterFlowTheme.of(context).accent1, - size: 24.0), + child: Icon(_model.passwordVisibility ? Icons.visibility_outlined : Icons.visibility_off_outlined, + color: FlutterFlowTheme.of(context).accent1, size: 24.0), ), ), style: FlutterFlowTheme.of(context).bodyLarge.override( @@ -341,8 +327,7 @@ class _SignInTemplateComponentWidgetState extends State('toggleSignUpPage'), onPressed: () async => await widget.toggleSignUpPage?.call(), - text: FFLocalizations.of(context) - .getText('jwvd4ai1' /* Cadastrar */), + text: FFLocalizations.of(context).getText('jwvd4ai1' /* Cadastrar */), options: FFButtonOptions( width: double.infinity, height: 44.0, - padding: - const EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 0.0), - iconPadding: - const EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 0.0), + padding: const EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 0.0), + iconPadding: const EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 0.0), color: FlutterFlowTheme.of(context).customColor1, textStyle: FlutterFlowTheme.of(context).titleSmall.override( fontFamily: 'Plus Jakarta Sans', @@ -513,8 +483,7 @@ class _SignInTemplateComponentWidgetState extends State('passwordVisibilitySuffixIcon'), onTap: () => setState( - () => _model.passwordRegisterFormVisibility = - !_model.passwordRegisterFormVisibility, + () => _model.passwordRegisterFormVisibility = !_model.passwordRegisterFormVisibility, ), focusNode: FocusNode(skipTraversal: true), child: Icon( - _model.passwordRegisterFormVisibility - ? Icons.visibility_outlined - : Icons.visibility_off_outlined, + _model.passwordRegisterFormVisibility ? Icons.visibility_outlined : Icons.visibility_off_outlined, color: FlutterFlowTheme.of(context).accent1, size: 24.0, ), @@ -477,11 +465,9 @@ class _SignUpTemplateComponentWidgetState extends State { color: FlutterFlowTheme.of(context).primaryBackground, child: Padding( padding: const EdgeInsets.only(bottom: 40), - child: MenuComponentWidget( - expandable: true, - style: MenuView.list_grid, - item: MenuItem.button, - menuOptions: Module.values.where((e) => e != Module.logout).toList(), + child: MenuFactory( + menuEntry: MenuEntries.home, + menuItem: MenuItem.button, + menuView: MenuView.list_grid, ), ), ); diff --git a/lib/features/home/presentation/pages/index.dart b/lib/features/home/presentation/pages/index.dart new file mode 100644 index 00000000..e4ff2696 --- /dev/null +++ b/lib/features/home/presentation/pages/index.dart @@ -0,0 +1 @@ +export 'home_page.dart'; diff --git a/lib/features/home/presentation/widgets/index.dart b/lib/features/home/presentation/widgets/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/data/data_sources/index.dart b/lib/features/property/data/data_sources/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/data/index.dart b/lib/features/property/data/index.dart new file mode 100644 index 00000000..186dfac9 --- /dev/null +++ b/lib/features/property/data/index.dart @@ -0,0 +1,3 @@ +export 'data_sources/index.dart'; +export 'repositories/index.dart'; +export 'models/index.dart'; diff --git a/lib/features/property/data/models/index.dart b/lib/features/property/data/models/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/data/repositories/index.dart b/lib/features/property/data/repositories/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/domain/entities/index.dart b/lib/features/property/domain/entities/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/domain/index.dart b/lib/features/property/domain/index.dart new file mode 100644 index 00000000..00b76d59 --- /dev/null +++ b/lib/features/property/domain/index.dart @@ -0,0 +1,3 @@ +export 'entities/index.dart'; +export 'respositories/index.dart'; +export 'usecases/index.dart'; diff --git a/lib/features/property/domain/respositories/index.dart b/lib/features/property/domain/respositories/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/domain/usecases/index.dart b/lib/features/property/domain/usecases/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/index.dart b/lib/features/property/index.dart new file mode 100644 index 00000000..aa560630 --- /dev/null +++ b/lib/features/property/index.dart @@ -0,0 +1,3 @@ +export 'data/index.dart'; +export 'domain/index.dart'; +export 'presentation/index.dart'; diff --git a/lib/features/property/presentation/blocs/index.dart b/lib/features/property/presentation/blocs/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/property/presentation/index.dart b/lib/features/property/presentation/index.dart new file mode 100644 index 00000000..48b6447a --- /dev/null +++ b/lib/features/property/presentation/index.dart @@ -0,0 +1,3 @@ +export 'blocs/index.dart'; +export 'pages/index.dart'; +export 'widgets/index.dart'; diff --git a/lib/pages/about_property_page/about_property_screen.dart b/lib/features/property/presentation/pages/about_property_screen.dart similarity index 63% rename from lib/pages/about_property_page/about_property_screen.dart rename to lib/features/property/presentation/pages/about_property_screen.dart index a03227e1..5b06f018 100644 --- a/lib/pages/about_property_page/about_property_screen.dart +++ b/lib/features/property/presentation/pages/about_property_screen.dart @@ -2,36 +2,29 @@ import 'package:flutter/material.dart'; import 'package:hub/backend/schema/enums/enums.dart'; import 'package:hub/components/atomic_components/shared_components_atoms/appbar.dart'; -import 'package:hub/components/organism_components/menu_component/menu_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/pages/about_property_page/about_property_model.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; -enum AboutPropertyModules { - residents, - vehicles, - openedVisits, - petsHistory, -} +class AboutPropertyModel extends FlutterFlowModel { + dynamic item; -extension AboutPropertyModulesExtension on AboutPropertyModules { - String get value { - switch (this) { - case AboutPropertyModules.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case AboutPropertyModules.vehicles: - return 'FRE-HUB-VEHICLES'; - case AboutPropertyModules.residents: - return 'FRE-HUB-RESIDENTS'; - case AboutPropertyModules.petsHistory: - return 'FRE-HUB-PETS'; - default: - return ''; - } + VoidCallback? safeSetState; + + Future initAsync() async { + safeSetState?.call(); } + + @override + void initState(BuildContext context) { + initAsync(); + } + + @override + void dispose() {} } // ignore: must_be_immutable @@ -84,13 +77,11 @@ class _AboutPropertyPageState extends State with SingleTicker return SingleChildScrollView( child: Container( color: FlutterFlowTheme.of(context).primaryBackground, - child: MenuComponentWidget(expandable: true, style: MenuView.list_grid, item: MenuItem.button, menuOptions: [ - Module.petsHistory, - Module.residents, - Module.openedVisits, - Module.vehicles, - Module.orders, - ]), + child: MenuFactory( + menuEntry: MenuEntries.AboutProperty, + menuItem: MenuItem.button, + menuView: MenuView.list_grid, + ), ), ); } diff --git a/lib/features/property/presentation/pages/index.dart b/lib/features/property/presentation/pages/index.dart new file mode 100644 index 00000000..f997df03 --- /dev/null +++ b/lib/features/property/presentation/pages/index.dart @@ -0,0 +1 @@ +export 'about_property_screen.dart'; diff --git a/lib/features/property/presentation/widgets/index.dart b/lib/features/property/presentation/widgets/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 112dfc6c..1efd1362 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -4,14 +4,14 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:hub/backend/schema/util/schema_util.dart'; +import 'package:hub/features/home/index.dart'; +import 'package:hub/features/property/index.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/pages/about_property_page/about_property_screen.dart'; import 'package:hub/pages/acess_history_page/acess_history_page_widget.dart'; import 'package:hub/pages/delivery_schedule_page/delivery_schedule_widget.dart'; import 'package:hub/pages/fast_pass_page/fast_pass_page_widget.dart'; import 'package:hub/pages/forgot_password_page/forgot_password_screen.dart'; -import 'package:hub/pages/home_page/home_page.dart'; import 'package:hub/pages/liberation_history/liberation_history_widget.dart'; import 'package:hub/pages/message_history_page/message_history_page_widget.dart'; import 'package:hub/pages/package_order_page/package_order_page.dart'; @@ -41,7 +41,7 @@ export 'serialization_util.dart'; const kTransitionInfoKey = '__transition_info__'; -final GlobalKey key = GlobalKey(); +final GlobalKey navigatorKey = GlobalKey(); class AppStateNotifier extends ChangeNotifier { AppStateNotifier._(); @@ -59,7 +59,7 @@ class AppStateNotifier extends ChangeNotifier { GoRouter createRouter(AppStateNotifier appStateNotifier) { return GoRouter( - navigatorKey: key, + navigatorKey: navigatorKey, initialLocation: '/', debugLogDiagnostics: true, redirect: (context, state) { @@ -135,6 +135,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { FFRoute(name: 'preferencesSettings', path: '/preferencesSettings', builder: (context, params) => PreferencesPageWidget()), FFRoute(name: 'aboutProperty', path: '/aboutProperty', builder: (context, params) => AboutPropertyPage()), FFRoute(name: 'residentsOnThePropertyPage', path: '/residentsOnThePropertyPage', builder: (context, params) => ResidentsOnTheProperty()), + FFRoute(name: 'visitsOnThePropertyPage', path: '/visitsOnThePropertyPage', builder: (context, params) => VisitsOnTheProperty()), FFRoute(name: 'peopleOnThePropertyPage', path: '/peopleOnThePropertyPage', builder: (context, params) => PeopleOnThePropertyPage()), FFRoute( name: 'acessHistoryPage', diff --git a/lib/index.dart b/lib/index.dart index bfe5bac8..8b137891 100644 --- a/lib/index.dart +++ b/lib/index.dart @@ -1,11 +1 @@ -export 'pages/acess_history_page/acess_history_page_widget.dart' show AccessHistoryScreen; -export 'pages/home_page/home_page.dart' show HomePageWidget; -export 'pages/liberation_history/liberation_history_widget.dart' show LiberationHistoryWidget; -export 'pages/people_on_the_property_page/people_on_the_property_page_widget.dart' show PeopleOnThePropertyPage; -export 'pages/preferences_settings_page/preferences_settings_widget.dart' show PreferencesPageWidget; -export 'pages/qr_code_page/qr_code_page_widget.dart' show QrCodePageWidget; -export 'pages/register_visitor_page/register_visitor_page_widget.dart' show RegisterVisitorPageWidget; -export 'pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart' show ScheduleCompleteVisitPageWidget; -export 'pages/sign_in_page/sign_in_page_widget.dart' show SignInPageWidget; -export 'pages/sign_up_page/sign_up_page_widget.dart' show SignUpPageWidget; -export 'pages/welcome_page/welcome_page_widget.dart' show WelcomePageWidget; + diff --git a/lib/initialization.dart b/lib/initialization.dart index f5f4b023..564b073f 100644 --- a/lib/initialization.dart +++ b/lib/initialization.dart @@ -12,7 +12,6 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; -import 'package:hub/shared/services/localization/localization_service.dart'; Future initializeApp() async { WidgetsFlutterBinding.ensureInitialized(); diff --git a/lib/main.dart b/lib/main.dart index 7b66def1..0b75747b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,11 +16,11 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; -import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -194,7 +194,7 @@ class _AppState extends State with WidgetsBindingObserver { @override void didChangeAppLifecycleState(AppLifecycleState state) async { if (state == AppLifecycleState.detached) { - await LocalizationService.processLocals(context); + await LocalsRepositoryImpl().processLocals(context); await FirebaseMessagingService().updateDeviceToken(); } } diff --git a/lib/pages/about_property_page/about_property_model.dart b/lib/pages/about_property_page/about_property_model.dart deleted file mode 100644 index aefdc762..00000000 --- a/lib/pages/about_property_page/about_property_model.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; - -import 'package:hub/flutter_flow/flutter_flow_model.dart'; - -import 'package:hub/pages/about_property_page/about_property_screen.dart'; - -class AboutPropertyModel extends FlutterFlowModel { - dynamic item; - - VoidCallback? safeSetState; - - Future initAsync() async { - safeSetState?.call(); - } - - @override - void initState(BuildContext context) { - initAsync(); - } - - @override - void dispose() {} -} diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 2339d95a..d5edb91f 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -5,10 +5,10 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; -import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:share_plus/share_plus.dart'; import '../../shared/utils/snackbar_util.dart'; @@ -262,7 +262,7 @@ class PreferencesPageModel with ChangeNotifier { enText: 'Are you sure you want to unlink your device?', ptText: 'Tem certeza que deseja desvincular seu dispositivo?', ); - onConfirm() async => LocalizationService.unlinkLocal(context); + onConfirm() async => LocalsRepositoryImpl().unlinkLocal(context); showAlertDialog(context, title, content, onConfirm); } diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index dde3e076..2da2e1e8 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -10,9 +10,9 @@ 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/pages/reception_page/reception_page_model.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; -import 'package:hub/shared/services/localization/localization_service.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; import 'package:provider/provider.dart'; @@ -34,7 +34,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB }(); FirebaseMessagingService().updateDeviceToken(); - LocalizationService.checkLocals(context); + LocalsRepositoryImpl().checkLocals(context); } @override @@ -48,7 +48,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB log('() => state: $state'); if (state == AppLifecycleState.resumed) { setState(() { - LocalizationService.checkLocals(context); + LocalsRepositoryImpl().checkLocals(context); }); } } @@ -75,9 +75,8 @@ class _ReceptionPageWidgetState extends State with WidgetsB Padding( padding: const EdgeInsets.fromLTRB(45, 20, 45, 15.0), child: Text( - FFLocalizations.of(context).getVariableText( - ptText: 'Falta pouco para você utilizar o FRE Access Hub...', - enText: 'You are close to using the FRE Access Hub...'), + FFLocalizations.of(context) + .getVariableText(ptText: 'Falta pouco para você utilizar o FRE Access Hub...', enText: 'You are close to using the FRE Access Hub...'), textAlign: TextAlign.center, style: FlutterFlowTheme.of(context).displayLarge.override( fontFamily: 'Plus Jakarta Sans', @@ -94,8 +93,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB padding: const EdgeInsets.fromLTRB(70, 30, 70.0, 40), child: Text( FFLocalizations.of(context).getVariableText( - ptText: - 'Envie seu identificador para seu condomínio para vincularem sua conta aos nossos sistemas.', + ptText: 'Envie seu identificador para seu condomínio para vincularem sua conta aos nossos sistemas.', enText: 'Send your identifier to your condominium to link your account to our systems.'), textAlign: TextAlign.center, style: FlutterFlowTheme.of(context).displaySmall.override( @@ -115,10 +113,8 @@ class _ReceptionPageWidgetState extends State with WidgetsB Padding( padding: const EdgeInsets.fromLTRB(60, 0, 60, 10), child: Tooltip( - message: FFLocalizations.of(context).getVariableText( - ptText: - 'Seu identificador é utilizado para efetuar\no vínculo do seu APP com o condominio.', - enText: 'My Identifier'), + message: FFLocalizations.of(context) + .getVariableText(ptText: 'Seu identificador é utilizado para efetuar\no vínculo do seu APP com o condominio.', enText: 'My Identifier'), textStyle: FlutterFlowTheme.of(context).labelSmall.override( fontFamily: 'Nunito Sans', color: FlutterFlowTheme.of(context).secondaryText, @@ -129,8 +125,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB ), child: FFButtonWidget( onPressed: () => model.getIdenfifier(context), - text: FFLocalizations.of(context) - .getVariableText(ptText: 'Meu Identificador', enText: 'My Identifier'), + text: FFLocalizations.of(context).getVariableText(ptText: 'Meu Identificador', enText: 'My Identifier'), options: FFButtonOptions( width: double.infinity, height: 30, @@ -164,8 +159,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB AuthenticationService.signOut(context); setState(() {}); }, - text: FFLocalizations.of(context) - .getVariableText(ptText: 'Sair da Conta', enText: 'Logout'), + text: FFLocalizations.of(context).getVariableText(ptText: 'Sair da Conta', enText: 'Logout'), options: FFButtonOptions( width: double.infinity, height: 30, diff --git a/lib/shared/widgets/image_cropper_widget/image_cropper.dart b/lib/shared/components/atoms/image_cropper/image_cropper.dart similarity index 100% rename from lib/shared/widgets/image_cropper_widget/image_cropper.dart rename to lib/shared/components/atoms/image_cropper/image_cropper.dart diff --git a/lib/shared/components/atoms/atom_terms_of_use.dart b/lib/shared/components/atoms/term_of_use/atom_terms_of_use.dart similarity index 88% rename from lib/shared/components/atoms/atom_terms_of_use.dart rename to lib/shared/components/atoms/term_of_use/atom_terms_of_use.dart index b9f14a30..470d61f8 100644 --- a/lib/shared/components/atoms/atom_terms_of_use.dart +++ b/lib/shared/components/atoms/term_of_use/atom_terms_of_use.dart @@ -1,10 +1,9 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/utils/limited_text_size.dart'; -import '../../../flutter_flow/flutter_flow_theme.dart'; -import '../../../flutter_flow/flutter_flow_util.dart'; - class AtomTermsOfUse extends StatelessWidget { const AtomTermsOfUse({super.key}); diff --git a/lib/shared/widgets/drawer_widget/drawer_widget.dart b/lib/shared/components/molecules/drawer/drawer_widget.dart similarity index 89% rename from lib/shared/widgets/drawer_widget/drawer_widget.dart rename to lib/shared/components/molecules/drawer/drawer_widget.dart index ddd81a47..13362990 100644 --- a/lib/shared/widgets/drawer_widget/drawer_widget.dart +++ b/lib/shared/components/molecules/drawer/drawer_widget.dart @@ -1,23 +1,20 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/organism_components/menu_component/menu_component_widget.dart'; +import 'package:hub/features/home/index.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_bloc.dart'; -import 'package:hub/pages/home_page/home_state.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; -import 'package:hub/shared/services/license/license_service.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; class CustomDrawer extends StatelessWidget { const CustomDrawer({super.key}); @override Widget build(BuildContext context) { - return StreamBuilder>( - stream: LicenseService().licenseStream, + return StreamBuilder( + stream: LicenseRepositoryImpl.stream, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center( @@ -27,7 +24,7 @@ class CustomDrawer extends StatelessWidget { return Center( child: Text('Error: ${snapshot.error}'), ); - } else if (!snapshot.hasData || snapshot.data!.isEmpty) { + } else if (!snapshot.hasData || snapshot.data! == false) { return Center( child: Padding( padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), @@ -192,11 +189,10 @@ class CustomDrawer extends StatelessWidget { } Widget _buildDrawerBody(BuildContext context) { - return MenuComponentWidget( - style: MenuView.list, - item: MenuItem.tile, - expandable: false, - menuOptions: Module.values.where((e) => e != Module.settings).toList(), + return MenuFactory( + menuEntry: MenuEntries.drawer, + menuItem: MenuItem.tile, + menuView: MenuView.list, ); } } diff --git a/lib/shared/components/molecules/drawer/index.dart b/lib/shared/components/molecules/drawer/index.dart new file mode 100644 index 00000000..bbb9bc10 --- /dev/null +++ b/lib/shared/components/molecules/drawer/index.dart @@ -0,0 +1 @@ +export 'drawer_widget.dart'; diff --git a/lib/shared/components/molecules/locals/data/data_sources/index.dart b/lib/shared/components/molecules/locals/data/data_sources/index.dart new file mode 100644 index 00000000..225b76e9 --- /dev/null +++ b/lib/shared/components/molecules/locals/data/data_sources/index.dart @@ -0,0 +1,2 @@ +export 'locals_local_data_source.dart'; +export 'locals_remote_data_source.dart'; diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart new file mode 100644 index 00000000..47f65ad7 --- /dev/null +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart @@ -0,0 +1,3 @@ +abstract class LocalsLocalDataSource {} + +class LocalsLocalDataSourceImpl {} diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart similarity index 88% rename from lib/shared/services/localization/localization_service.dart rename to lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index bf485699..a07318f0 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -8,19 +8,30 @@ import 'package:hub/components/organism_components/bottom_arrow_linked_locals_co import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; -import 'package:hub/shared/services/license/license_service.dart'; import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/snackbar_util.dart'; -import 'package:hub/shared/extensions/string_extensions.dart'; -class LocalizationService { - static Future checkLocals(BuildContext context) async { +abstract class LocalsRemoteDataSource { + Future checkLocals(BuildContext context) async {} + Future processLocals(BuildContext context) async => false; + Future processData(BuildContext context) async => false; + Future selectLocal(BuildContext context, ApiCallResponse? response) async => false; + Future unlinkLocal(BuildContext context) async {} +} + +class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { + static final LocalsRemoteDataSourceImpl _instance = LocalsRemoteDataSourceImpl._internal(); + factory LocalsRemoteDataSourceImpl() => _instance; + LocalsRemoteDataSourceImpl._internal(); + + @override + Future checkLocals(BuildContext context) async { try { final GetLocalsCall callback = PhpGroup.getLocalsCall; var response = await callback.call(); @@ -57,9 +68,10 @@ class LocalizationService { } } - static Future processLocals(BuildContext context) async { + @override + Future processLocals(BuildContext context) async { try { - await LicenseService().cleanLicense(); + await LicenseRepositoryImpl().cleanLicense(); final GetLocalsCall callback = PhpGroup.getLocalsCall; final ApiCallResponse response = await callback.call(); final bool? isError = response.jsonBody['error']; @@ -130,7 +142,8 @@ class LocalizationService { } } - static Future processData(BuildContext context) async { + @override + Future processData(BuildContext context) async { try { final GetDadosCall callback = PhpGroup.getDadosCall; ApiCallResponse? response = await callback.call(); @@ -153,10 +166,10 @@ class LocalizationService { return false; } else { final bool isNewVersion = await _updateStorageUtil(response.jsonBody); - await LicenseService().setupLicense(DatabaseStorage.database, isNewVersion); + await LicenseRepositoryImpl().setupLicense(isNewVersion); if (isNewVersion) { log('(A) => isNewVersion: $isNewVersion'); - return await LicenseService().fetchLicenses(isNewVersion); + return await LicenseRepositoryImpl().fetchLicense(isNewVersion); } return false; } @@ -172,7 +185,8 @@ class LocalizationService { } } - static Future selectLocal(BuildContext context, ApiCallResponse? response) async { + @override + Future selectLocal(BuildContext context, ApiCallResponse? response) async { return await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, @@ -191,7 +205,8 @@ class LocalizationService { ).then((_) async => await processData(context)); } - static Future unlinkLocal(BuildContext context) async { + @override + Future unlinkLocal(BuildContext context) async { String content; try { content = FFLocalizations.of(context).getVariableText( @@ -235,7 +250,7 @@ class LocalizationService { } } - static void _handleError(BuildContext context, String errorMsg) async { + void _handleError(BuildContext context, String errorMsg) async { final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; @@ -262,7 +277,7 @@ class LocalizationService { await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); } - static Future _handleUnavailable(BuildContext context, List locals) async { + Future _handleUnavailable(BuildContext context, List locals) async { log('() => isUnavailable'); try { await StorageHelper().s(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); @@ -284,7 +299,7 @@ class LocalizationService { return false; } - static Future _handleEnabled(BuildContext context, dynamic local) async { + Future _handleEnabled(BuildContext context, dynamic local) async { log('() => isEnabled'); await StorageHelper().s(KeychainStorageKey.clientUUID.value, local['CLI_ID']); await StorageHelper().s(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); @@ -293,14 +308,14 @@ class LocalizationService { return await processData(context); } - static void _logLocalsStatus(List locals) { + void _logLocalsStatus(List locals) { for (var local in locals) { final String status = local['CLU_STATUS']; log('() => CLU_STATUS: $status'); } } - static Future _updateStorageUtil(Map jsonBody) async { + Future _updateStorageUtil(Map jsonBody) async { await StorageHelper().s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp']); await StorageHelper().s(KeychainStorageKey.provisional.value, jsonBody['provisional'] != null && jsonBody['provisional']); await StorageHelper().s(KeychainStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet']); @@ -318,33 +333,33 @@ class LocalizationService { return isNewVersion; } - static bool _isActive(List locals) { + bool _isActive(List locals) { return locals.where((local) => local['CLU_STATUS'] == 'A').isNotEmpty; } - static Future _isInactived(List locals) async { + Future _isInactived(List locals) async { String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; } - static bool _isPending(List locals) { + bool _isPending(List locals) { return locals.where((local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A').isNotEmpty; } - static Future _isUnselected() async { + Future _isUnselected() async { String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; String ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; } - static Future _isSelected(bool isInactived) async { + Future _isSelected(bool isInactived) async { String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; } - static Future _isAvailable() async { + Future _isAvailable() async { String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; return cliUUID.isNotEmpty && cliName.isNotEmpty; diff --git a/lib/shared/components/molecules/locals/data/index.dart b/lib/shared/components/molecules/locals/data/index.dart new file mode 100644 index 00000000..186dfac9 --- /dev/null +++ b/lib/shared/components/molecules/locals/data/index.dart @@ -0,0 +1,3 @@ +export 'data_sources/index.dart'; +export 'repositories/index.dart'; +export 'models/index.dart'; diff --git a/lib/shared/components/molecules/locals/data/models/index.dart b/lib/shared/components/molecules/locals/data/models/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/shared/components/molecules/locals/data/repositories/index.dart b/lib/shared/components/molecules/locals/data/repositories/index.dart new file mode 100644 index 00000000..80856dae --- /dev/null +++ b/lib/shared/components/molecules/locals/data/repositories/index.dart @@ -0,0 +1 @@ +export 'locals_repository_impl.dart'; diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart new file mode 100644 index 00000000..27873228 --- /dev/null +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -0,0 +1,32 @@ +import 'package:flutter/src/widgets/framework.dart'; +import 'package:hub/backend/api_requests/api_manager.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; + +class LocalsRepositoryImpl implements LocalsRepository { + final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl(); + + @override + Future checkLocals(BuildContext context) async { + return await remoteDataSource.checkLocals(context); + } + + @override + Future processData(BuildContext context) async { + return await remoteDataSource.processData(context); + } + + @override + Future processLocals(BuildContext context) async { + return await remoteDataSource.processLocals(context); + } + + @override + Future selectLocal(BuildContext context, ApiCallResponse? response) async { + return await remoteDataSource.selectLocal(context, response); + } + + @override + Future unlinkLocal(BuildContext context) { + return remoteDataSource.unlinkLocal(context); + } +} diff --git a/lib/shared/components/molecules/locals/domain/entities/index.dart b/lib/shared/components/molecules/locals/domain/entities/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/shared/components/molecules/locals/domain/index.dart b/lib/shared/components/molecules/locals/domain/index.dart new file mode 100644 index 00000000..00b76d59 --- /dev/null +++ b/lib/shared/components/molecules/locals/domain/index.dart @@ -0,0 +1,3 @@ +export 'entities/index.dart'; +export 'respositories/index.dart'; +export 'usecases/index.dart'; diff --git a/lib/shared/components/molecules/locals/domain/respositories/index.dart b/lib/shared/components/molecules/locals/domain/respositories/index.dart new file mode 100644 index 00000000..55f6b77a --- /dev/null +++ b/lib/shared/components/molecules/locals/domain/respositories/index.dart @@ -0,0 +1 @@ +export 'locals_repository.dart'; diff --git a/lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart b/lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart new file mode 100644 index 00000000..39577166 --- /dev/null +++ b/lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; +import 'package:hub/backend/api_requests/api_calls.dart'; + +abstract class LocalsRepository { + Future checkLocals(BuildContext context) async {} + Future processLocals(BuildContext context) async => false; + Future processData(BuildContext context) async => false; + Future selectLocal(BuildContext context, ApiCallResponse? response) async => false; + Future unlinkLocal(BuildContext context) async {} +} diff --git a/lib/shared/components/molecules/locals/domain/usecases/index.dart b/lib/shared/components/molecules/locals/domain/usecases/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/shared/components/molecules/locals/index.dart b/lib/shared/components/molecules/locals/index.dart new file mode 100644 index 00000000..aa560630 --- /dev/null +++ b/lib/shared/components/molecules/locals/index.dart @@ -0,0 +1,3 @@ +export 'data/index.dart'; +export 'domain/index.dart'; +export 'presentation/index.dart'; diff --git a/lib/shared/components/molecules/locals/presentation/blocs/index.dart b/lib/shared/components/molecules/locals/presentation/blocs/index.dart new file mode 100644 index 00000000..488c36aa --- /dev/null +++ b/lib/shared/components/molecules/locals/presentation/blocs/index.dart @@ -0,0 +1 @@ +export 'local_profile_bloc.dart'; diff --git a/lib/components/organism_components/local_profile_component/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart similarity index 93% rename from lib/components/organism_components/local_profile_component/local_profile_bloc.dart rename to lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index 5aacf75e..cd838442 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -1,7 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter/material.dart'; -import 'package:hub/components/organism_components/local_profile_component/local_profile_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; diff --git a/lib/shared/components/molecules/locals/presentation/index.dart b/lib/shared/components/molecules/locals/presentation/index.dart new file mode 100644 index 00000000..688818c6 --- /dev/null +++ b/lib/shared/components/molecules/locals/presentation/index.dart @@ -0,0 +1,2 @@ +export 'blocs/index.dart'; +export 'widgets/index.dart'; diff --git a/lib/shared/components/molecules/locals/presentation/widgets/index.dart b/lib/shared/components/molecules/locals/presentation/widgets/index.dart new file mode 100644 index 00000000..211db207 --- /dev/null +++ b/lib/shared/components/molecules/locals/presentation/widgets/index.dart @@ -0,0 +1 @@ +export 'local_profile_widget.dart'; diff --git a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile_widget.dart similarity index 87% rename from lib/components/organism_components/local_profile_component/local_profile_component_widget.dart rename to lib/shared/components/molecules/locals/presentation/widgets/local_profile_widget.dart index cfbe2109..9cba14c4 100644 --- a/lib/components/organism_components/local_profile_component/local_profile_component_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile_widget.dart @@ -2,13 +2,12 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/components/organism_components/local_profile_component/local_profile_bloc.dart'; import 'package:hub/flutter_flow/custom_functions.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; -import 'package:hub/shared/services/localization/localization_service.dart'; class LocalProfileComponentWidget extends StatefulWidget { const LocalProfileComponentWidget({super.key}); @@ -59,8 +58,7 @@ class _LocalProfileComponentWidgetState extends State context.read().add(LocalProfileEvent())); + await LocalsRepositoryImpl().processLocals(context).whenComplete(() async => context.read().add(LocalProfileEvent())); }, child: ClipRRect( borderRadius: BorderRadius.circular(200.0), @@ -73,9 +71,7 @@ class _LocalProfileComponentWidgetState extends State { + MenuBloc() : super(MenuState()); +} diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_item_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_item_bloc.dart new file mode 100644 index 00000000..608fa51d --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_item_bloc.dart @@ -0,0 +1,9 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; + +class MenuItemEvent {} + +class MenuItemState {} + +class MenuItemBloc extends Bloc { + MenuItemBloc() : super(MenuItemState()); +} diff --git a/lib/components/organism_components/menu_component/menu_component_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart similarity index 73% rename from lib/components/organism_components/menu_component/menu_component_bloc.dart rename to lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart index d714cf3f..6f60ca26 100644 --- a/lib/components/organism_components/menu_component/menu_component_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart @@ -3,43 +3,44 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/atomic_components/menu_button_item/menu_button_item_widget.dart'; -import 'package:hub/components/atomic_components/menu_card_item/menu_card_item.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; + import 'package:hub/flutter_flow/custom_functions.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; -class MenuEvent {} +class MenuViewEvent {} -class MenuState { +class MenuViewState { final List menuEntries; final bool isGrid; - MenuState({this.menuEntries = const [], this.isGrid = false}); + MenuViewState({this.menuEntries = const [], this.isGrid = false}); - MenuState copyWith({List? menuEntries, bool? isGrid}) { - return MenuState( + MenuViewState copyWith({List? menuEntries, bool? isGrid}) { + return MenuViewState( menuEntries: menuEntries ?? this.menuEntries, isGrid: isGrid ?? this.isGrid, ); } } -class MenuBloc extends Bloc { +class MenuViewBloc extends Bloc { final MenuView style; final MenuItem item; final bool expandable; - final List menuOptions; + final List menuOptions; - MenuBloc({required this.style, required this.item, required this.expandable, required this.menuOptions}) : super(MenuState()) { - on((event, emit) async { + MenuViewBloc({required this.style, required this.item, required this.expandable, required this.menuOptions}) : super(MenuViewState()) { + on((event, emit) async { + await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); final entries = await generateMenuEntries(); emit(state.copyWith(menuEntries: entries)); }); } + Future addMenuEntry(List entries, IconData icon, String text, Function() action) async { entries.add( item == MenuItem.button @@ -57,10 +58,10 @@ class MenuBloc extends Bloc { List entries = []; try { for (var opt in menuOptions) { - String? licenseValue = await LicenseHelper().g(opt.value); + String? licenseValue = await LicenseRepositoryImpl().g(opt.value); if (licenseValue != null) { Map licenseMap = await stringToMap(licenseValue); - if (opt == Module.aboutProperty) log('AboutProperty: $licenseMap'); + if (opt.value == Modules.aboutProperty.value) log('AboutProperty: $licenseMap'); log('Module: ${opt.value} - License: ${licenseMap['display']}'); final String display = licenseMap['display'] ?? 'INVISIVEL'; final String startDate = licenseMap['startDate'] ?? ''; @@ -80,7 +81,7 @@ class MenuBloc extends Bloc { return entries; } - Future processDisplay(String display, Module opt, List entries) async { + Future processDisplay(String display, BaseEntry opt, List entries) async { try { switch (display) { case 'VISIVEL': @@ -90,7 +91,7 @@ class MenuBloc extends Bloc { break; case 'DESABILITADO': await addMenuEntry(entries, opt.icon, opt.name, () async { - await DialogUnavailable.unavailableFeature(key.currentContext!); + await DialogUnavailable.unavailableFeature(navigatorKey.currentContext!); }); break; case 'INVISIVEL': @@ -102,7 +103,7 @@ class MenuBloc extends Bloc { } } - Future processStartDate(String startDate, Module opt) async { + Future processStartDate(String startDate, BaseEntry opt) async { try { if (startDate.isEmpty) return true; final DateTime? start = DateTime.tryParse(startDate); @@ -115,7 +116,7 @@ class MenuBloc extends Bloc { return false; } - Future processExpirationDate(String expirationDate, Module opt) async { + Future processExpirationDate(String expirationDate, BaseEntry opt) async { try { if (expirationDate.isEmpty) return false; final DateTime? expiration = DateTime.tryParse(expirationDate); @@ -130,7 +131,7 @@ class MenuBloc extends Bloc { Future nav(String link) async { log('Opening: $link'); - key.currentContext!.push(link, extra: { + navigatorKey.currentContext!.push(link, extra: { kTransitionInfoKey: const TransitionInfo( hasTransition: false, transitionType: PageTransitionType.scale, diff --git a/lib/shared/components/molecules/menu/presentation/index.dart b/lib/shared/components/molecules/menu/presentation/index.dart new file mode 100644 index 00000000..688818c6 --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/index.dart @@ -0,0 +1,2 @@ +export 'blocs/index.dart'; +export 'widgets/index.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/index.dart new file mode 100644 index 00000000..3101060a --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/index.dart @@ -0,0 +1,4 @@ +export 'menu_item/index.dart'; +export 'menu_view/index.dart'; +export 'menu_factory/index.dart'; +export 'menu_entry/index.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart new file mode 100644 index 00000000..c40adeff --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart @@ -0,0 +1,223 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +enum DrawerMenuEntries implements BaseEntry { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + peopleOnTheProperty, + settings, + logout; + + @override + String get value { + switch (this) { + case DrawerMenuEntries.messages: + return 'FRE-HUB-MESSAGES'; + case DrawerMenuEntries.liberations: + return 'FRE-HUB-LIBERATIONS'; + case DrawerMenuEntries.reservations: + return 'FRE-HUB-RESERVATIONS'; + case DrawerMenuEntries.access: + return 'FRE-HUB-ACCESS'; + case DrawerMenuEntries.pets: + return 'FRE-HUB-PETS'; + case DrawerMenuEntries.orders: + return 'FRE-HUB-ORDERS'; + case DrawerMenuEntries.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case DrawerMenuEntries.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case DrawerMenuEntries.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case DrawerMenuEntries.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case DrawerMenuEntries.fastPass: + return 'FRE-HUB-FASTPASS'; + case DrawerMenuEntries.visitors: + return 'FRE-HUB-VISITORS'; + case DrawerMenuEntries.qrCode: + return 'FRE-HUB-QRCODE'; + case DrawerMenuEntries.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case DrawerMenuEntries.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case DrawerMenuEntries.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case DrawerMenuEntries.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case DrawerMenuEntries.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case DrawerMenuEntries.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case DrawerMenuEntries.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case DrawerMenuEntries.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case DrawerMenuEntries.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case DrawerMenuEntries.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case DrawerMenuEntries.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case DrawerMenuEntries.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case DrawerMenuEntries.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case DrawerMenuEntries.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case DrawerMenuEntries.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case DrawerMenuEntries.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + case DrawerMenuEntries.logout: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ); + } + } + + @override + IconData get icon { + switch (this) { + case DrawerMenuEntries.messages: + return Icons.chat_outlined; + case DrawerMenuEntries.liberations: + return Icons.how_to_reg_outlined; + case DrawerMenuEntries.reservations: + return Icons.event_available; + case DrawerMenuEntries.access: + return Icons.transfer_within_a_station_outlined; + case DrawerMenuEntries.pets: + return Icons.pets; + case DrawerMenuEntries.peopleOnTheProperty: + return Icons.groups; + case DrawerMenuEntries.orders: + return Icons.inventory_2_outlined; + case DrawerMenuEntries.completeSchedule: + return Icons.event; + case DrawerMenuEntries.providerSchedule: + return Icons.engineering_outlined; + case DrawerMenuEntries.deliverySchedule: + return Icons.sports_motorsports_outlined; + case DrawerMenuEntries.fastPass: + return Icons.attach_email_outlined; + case DrawerMenuEntries.qrCode: + return Icons.qr_code; + case DrawerMenuEntries.visitors: + return Icons.person_add_alt_1_outlined; + case DrawerMenuEntries.aboutProperty: + return Icons.home; + case DrawerMenuEntries.settings: + return Icons.settings; + case DrawerMenuEntries.logout: + return Icons.exit_to_app; + } + } + + @override + String get route { + switch (this) { + case DrawerMenuEntries.messages: + return '/messageHistoryPage'; + case DrawerMenuEntries.liberations: + return '/liberationHistory'; + case DrawerMenuEntries.reservations: + return '/reservation'; + case DrawerMenuEntries.access: + return '/acessHistoryPage'; + case DrawerMenuEntries.pets: + return '/petsPage'; + case DrawerMenuEntries.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case DrawerMenuEntries.orders: + return '/packageOrder'; + case DrawerMenuEntries.completeSchedule: + return '/scheduleCompleteVisitPage'; + case DrawerMenuEntries.providerSchedule: + return '/provisionalSchedule'; + case DrawerMenuEntries.aboutProperty: + return '/aboutProperty'; + case DrawerMenuEntries.deliverySchedule: + return '/deliverySchedule'; + case DrawerMenuEntries.fastPass: + return '/fastPassPage'; + case DrawerMenuEntries.qrCode: + return '/qrCodePage'; + case DrawerMenuEntries.visitors: + return '/registerVisitorPage'; + case DrawerMenuEntries.settings: + return '/preferencesSettings'; + case DrawerMenuEntries.logout: + return '/WelcomePage'; + default: + return ''; + } + } +} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart new file mode 100644 index 00000000..c72c2cd2 --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart @@ -0,0 +1,213 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +enum HomeMenuEntries implements BaseEntry { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + peopleOnTheProperty, + settings; + + @override + String get value { + switch (this) { + case HomeMenuEntries.messages: + return 'FRE-HUB-MESSAGES'; + case HomeMenuEntries.liberations: + return 'FRE-HUB-LIBERATIONS'; + case HomeMenuEntries.reservations: + return 'FRE-HUB-RESERVATIONS'; + case HomeMenuEntries.access: + return 'FRE-HUB-ACCESS'; + case HomeMenuEntries.pets: + return 'FRE-HUB-PETS'; + case HomeMenuEntries.orders: + return 'FRE-HUB-ORDERS'; + case HomeMenuEntries.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case HomeMenuEntries.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case HomeMenuEntries.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case HomeMenuEntries.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case HomeMenuEntries.fastPass: + return 'FRE-HUB-FASTPASS'; + case HomeMenuEntries.visitors: + return 'FRE-HUB-VISITORS'; + case HomeMenuEntries.qrCode: + return 'FRE-HUB-QRCODE'; + case HomeMenuEntries.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case HomeMenuEntries.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case HomeMenuEntries.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case HomeMenuEntries.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case HomeMenuEntries.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case HomeMenuEntries.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case HomeMenuEntries.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case HomeMenuEntries.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case HomeMenuEntries.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case HomeMenuEntries.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case HomeMenuEntries.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case HomeMenuEntries.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case HomeMenuEntries.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case HomeMenuEntries.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case HomeMenuEntries.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case HomeMenuEntries.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + } + } + + @override + IconData get icon { + switch (this) { + case HomeMenuEntries.messages: + return Icons.chat_outlined; + case HomeMenuEntries.liberations: + return Icons.how_to_reg_outlined; + case HomeMenuEntries.reservations: + return Icons.event_available; + case HomeMenuEntries.access: + return Icons.transfer_within_a_station_outlined; + case HomeMenuEntries.pets: + return Icons.pets; + case HomeMenuEntries.peopleOnTheProperty: + return Icons.groups; + case HomeMenuEntries.orders: + return Icons.inventory_2_outlined; + case HomeMenuEntries.completeSchedule: + return Icons.event; + case HomeMenuEntries.providerSchedule: + return Icons.engineering_outlined; + case HomeMenuEntries.deliverySchedule: + return Icons.sports_motorsports_outlined; + case HomeMenuEntries.fastPass: + return Icons.attach_email_outlined; + case HomeMenuEntries.qrCode: + return Icons.qr_code; + case HomeMenuEntries.visitors: + return Icons.person_add_alt_1_outlined; + case HomeMenuEntries.aboutProperty: + return Icons.home; + case HomeMenuEntries.settings: + return Icons.settings; + } + } + + @override + String get route { + switch (this) { + case HomeMenuEntries.messages: + return '/messageHistoryPage'; + case HomeMenuEntries.liberations: + return '/liberationHistory'; + case HomeMenuEntries.reservations: + return '/reservation'; + case HomeMenuEntries.access: + return '/acessHistoryPage'; + case HomeMenuEntries.pets: + return '/petsPage'; + case HomeMenuEntries.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case HomeMenuEntries.orders: + return '/packageOrder'; + case HomeMenuEntries.completeSchedule: + return '/scheduleCompleteVisitPage'; + case HomeMenuEntries.providerSchedule: + return '/provisionalSchedule'; + case HomeMenuEntries.aboutProperty: + return '/aboutProperty'; + case HomeMenuEntries.deliverySchedule: + return '/deliverySchedule'; + case HomeMenuEntries.fastPass: + return '/fastPassPage'; + case HomeMenuEntries.qrCode: + return '/qrCodePage'; + case HomeMenuEntries.visitors: + return '/registerVisitorPage'; + case HomeMenuEntries.settings: + return '/preferencesSettings'; + default: + return ''; + } + } +} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart new file mode 100644 index 00000000..9b5d30cf --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart @@ -0,0 +1,4 @@ +export 'drawer_menu_entry.dart'; +export 'home_menu_entry.dart'; +export 'property_menu_entry.dart'; +export 'menu_entry_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart new file mode 100644 index 00000000..8c23e8bc --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +enum MenuEntries { + home, + drawer, + AboutProperty; + + List get getValues { + switch (this) { + case MenuEntries.home: + return HomeMenuEntries.values.toList(); + case MenuEntries.drawer: + return DrawerMenuEntries.values.toList(); + case MenuEntries.AboutProperty: + return AboutPropertyMenuEntries.values.toList(); + } + } +} + +class MenuEntryFactory { + static List createMenuEntry(BaseEntry type) { + switch (type) { + case HomeMenuEntries _: + return HomeMenuEntries.values.toList(); + case DrawerMenuEntries _: + return DrawerMenuEntries.values.toList(); + case AboutPropertyMenuEntries _: + return AboutPropertyMenuEntries.values.toList(); + default: + throw ArgumentError('Invalid menu entry type'); + } + } + + List buildMenuEntry(BaseEntry type) { + return createMenuEntry(type); + } +} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart new file mode 100644 index 00000000..0a1cb85e --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart @@ -0,0 +1,67 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +enum AboutPropertyMenuEntries implements BaseEntry { + residents, + vehicles, + openedVisits, + petsHistory; + + @override + String get value { + switch (this) { + case AboutPropertyMenuEntries.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case AboutPropertyMenuEntries.vehicles: + return 'FRE-HUB-VEHICLES'; + case AboutPropertyMenuEntries.residents: + return 'FRE-HUB-RESIDENTS'; + case AboutPropertyMenuEntries.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + default: + return ''; + } + } + + @override + IconData get icon { + switch (this) { + case AboutPropertyMenuEntries.residents: + return Icons.people; + case AboutPropertyMenuEntries.vehicles: + return Icons.directions_car; + case AboutPropertyMenuEntries.openedVisits: + return Icons.open_in_new; + case AboutPropertyMenuEntries.petsHistory: + return Icons.pets; + } + } + + @override + String get name { + switch (this) { + case AboutPropertyMenuEntries.residents: + return 'Residents'; + case AboutPropertyMenuEntries.vehicles: + return 'Vehicles'; + case AboutPropertyMenuEntries.openedVisits: + return 'Opened Visits'; + case AboutPropertyMenuEntries.petsHistory: + return 'Pets History'; + } + } + + @override + String get route { + switch (this) { + case AboutPropertyMenuEntries.residents: + return '/residentsOnThePropertyPage'; + case AboutPropertyMenuEntries.vehicles: + return '/vehiclesOnThePropertyPage'; + case AboutPropertyMenuEntries.openedVisits: + return '/openedVisitsPage'; + case AboutPropertyMenuEntries.petsHistory: + return '/petsOnThePropertyPage'; + } + } +} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart new file mode 100644 index 00000000..aa113121 --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart @@ -0,0 +1 @@ +export 'menu_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart new file mode 100644 index 00000000..b775544c --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +class MenuFactory extends StatelessWidget { + final MenuView menuView; + final MenuEntries menuEntry; + final MenuItem menuItem; + + const MenuFactory({ + super.key, + required this.menuView, + required this.menuEntry, + required this.menuItem, + }); + + @override + Widget build(BuildContext context) { + return MenuViewFactory( + view: menuView, + item: menuItem, + expandable: false, + entry: menuEntry, + ); + } +} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart new file mode 100644 index 00000000..d6f43bae --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart @@ -0,0 +1,4 @@ +export 'menu_item.dart'; +export 'menu_item_button.dart'; +export 'menu_item_card.dart'; +export 'menu_item_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item.dart new file mode 100644 index 00000000..6b2b37ba --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +enum MenuItem { + button, + card, + tile; + + MenuEntry getInstance(final Function() action, final String title, final IconData icon) { + switch (this) { + case MenuItem.button: + return MenuButtonWidget(action: action, title: title, icon: icon); + case MenuItem.card: + return MenuCardItem(action: action, title: title, icon: icon); + case MenuItem.tile: + return MenuCardItem(action: action, title: title, icon: icon); + } + } +} + +abstract class MenuEntry extends StatefulWidget { + const MenuEntry({ + super.key, + required this.action, + required this.title, + required this.icon, + }); + + final Function() action; + final String title; + final IconData icon; + + factory MenuEntry.create( + MenuItem type, { + Key? key, + required Function() action, + required String title, + required IconData icon, + }) { + return type.getInstance(action, title, icon); + } +} diff --git a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart similarity index 91% rename from lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart rename to lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart index d446d4a7..e8a69b01 100644 --- a/lib/components/atomic_components/menu_button_item/menu_button_item_widget.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'menu_item.dart'; + class MenuButtonWidget extends MenuEntry { const MenuButtonWidget({ super.key, @@ -23,7 +24,6 @@ class MenuButtonWidget extends MenuEntry { } class _MenuButtonWidgetState extends State { - get action => action; bool _isProcessing = false; @override @@ -44,7 +44,7 @@ class _MenuButtonWidgetState extends State { setState(() { _isProcessing = true; }); - await widget.action.call(); + widget.action.call(); setState(() { _isProcessing = false; }); @@ -60,10 +60,7 @@ class _MenuButtonWidgetState extends State { BoxShadow( blurRadius: 4.0, color: FlutterFlowTheme.of(context).customColor5, - offset: const Offset( - 0.0, - 2.0, - ), + offset: const Offset(0.0, 2.0), ) ], borderRadius: BorderRadius.circular(24.0), @@ -94,7 +91,7 @@ class _MenuButtonWidgetState extends State { child: Padding( padding: const EdgeInsets.only(left: 10.0), child: Text( - widget.title ?? '', + widget.title, overflow: TextOverflow.ellipsis, maxLines: 2, textAlign: TextAlign.start, @@ -102,7 +99,6 @@ class _MenuButtonWidgetState extends State { fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).primaryText, fontSize: limitedFontSize, - letterSpacing: 0.0, fontWeight: FontWeight.w500, useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), ), diff --git a/lib/components/atomic_components/menu_card_item/menu_card_item.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart similarity index 89% rename from lib/components/atomic_components/menu_card_item/menu_card_item.dart rename to lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart index c4c5cbaf..a0e226ec 100644 --- a/lib/components/atomic_components/menu_card_item/menu_card_item.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'menu_item.dart'; + class MenuCardItem extends MenuEntry { const MenuCardItem({ super.key, @@ -23,7 +24,6 @@ class MenuCardItem extends MenuEntry { } class _MenuCardItemState extends State { - get action => action; bool _isProcessing = false; @override @@ -39,7 +39,7 @@ class _MenuCardItemState extends State { setState(() { _isProcessing = true; }); - await widget.action.call(); + widget.action.call(); setState(() { _isProcessing = false; }); @@ -65,7 +65,6 @@ class _MenuCardItemState extends State { alignment: const AlignmentDirectional(0.0, 0.0), child: Icon( widget.icon, - fill: null, color: FlutterFlowTheme.of(context).accent1, size: 24.0, ), @@ -74,13 +73,11 @@ class _MenuCardItemState extends State { ), Flexible( child: Text( - widget.title ?? '', - // overflow: TextOverflow.ellipsis, + widget.title, style: FlutterFlowTheme.of(context).titleLarge.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).primaryText, fontSize: 14.0, - letterSpacing: 0.0, fontWeight: FontWeight.w500, useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), ), diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart new file mode 100644 index 00000000..aa92814d --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +class MenuItemFactory { + static MenuEntry createMenuItem( + MenuItem type, { + Key? key, + required Function() action, + required String title, + required IconData icon, + }) { + return MenuEntry.create(type, key: key, action: action, title: title, icon: icon); + } + + MenuEntry buildMenuItem( + MenuItem type, { + Key? key, + required Function() action, + required String title, + required IconData icon, + }) { + return createMenuItem(type, key: key, action: action, title: title, icon: icon); + } +} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart new file mode 100644 index 00000000..43bd7226 --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart @@ -0,0 +1,3 @@ +export 'menu_list_view.dart'; +export 'menu_staggered_view.dart'; +export 'menu_view_factory.dart'; diff --git a/lib/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart similarity index 56% rename from lib/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart rename to lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart index 88f6153e..9787f37c 100644 --- a/lib/components/organism_components/menu_list_view_component/menu_list_view_component_widget.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart @@ -1,18 +1,22 @@ import 'package:flutter/material.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/components/molecular_components/menu_item/menu_item.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; import '/flutter_flow/flutter_flow_icon_button.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; -import 'menu_list_view_component_model.dart'; -export 'menu_list_view_component_model.dart'; +enum MenuView { list_grid, list, grid } -/// +class MenuListViewModel extends FlutterFlowModel { + @override + void initState(BuildContext context) {} -class MenuListViewComponentWidget extends StatefulWidget { - const MenuListViewComponentWidget({ + @override + void dispose() {} +} + +class MenuListView extends StatefulWidget { + const MenuListView({ super.key, required this.changeMenuStyle, required this.expandable, @@ -22,16 +26,15 @@ class MenuListViewComponentWidget extends StatefulWidget { final bool expandable; final MenuItem item; - final List options; final Future Function()? changeMenuStyle; @override - State createState() => _MenuListViewComponentWidgetState(); + State createState() => _MenuListViewState(); } -class _MenuListViewComponentWidgetState extends State { - late MenuListViewComponentModel _model; +class _MenuListViewState extends State { + late MenuListViewModel _model; @override void setState(VoidCallback callback) { @@ -42,7 +45,7 @@ class _MenuListViewComponentWidgetState extends State MenuListViewComponentModel()); + _model = createModel(context, () => MenuListViewModel()); } @override @@ -60,52 +63,58 @@ class _MenuListViewComponentWidgetState extends State { + @override + void initState(BuildContext context) {} + + @override + void dispose() {} +} + +class MenuStaggeredView extends StatefulWidget { + const MenuStaggeredView({super.key, required this.changeMenuStyle, required this.expandable, required this.item, required this.options, required this.isGrid}); + + final bool expandable; + final MenuItem item; + final bool isGrid; + final List options; + final Future Function()? changeMenuStyle; + + @override + State createState() => _MenuStaggeredViewState(); +} + +class _MenuStaggeredViewState extends State { + late MenuStaggeredViewModel _model; + + @override + void setState(VoidCallback callback) { + super.setState(callback); + _model.onUpdate(); + } + + @override + void initState() { + super.initState(); + _model = createModel(context, () => MenuStaggeredViewModel()); + } + + @override + void dispose() { + _model.maybeDispose(); + + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final textScaler = MediaQuery.textScalerOf(context); + final double scaledFontSize = 14 * textScaler.scale(1); + final int crossAxisCount = _calculateCrossAxisCount(scaledFontSize); + + return Column( + children: [ + _buildGridView(crossAxisCount), + ].addToStart(const SizedBox(height: 30)).addToEnd(const SizedBox(height: 30)), + ); + } + + int _calculateCrossAxisCount(double scaledFontSize) { + if (scaledFontSize >= 26) return 1; + if (scaledFontSize >= 18) return 2; + return 3; + } + + Widget _buildGridView(int crossAxisCount) { + return GridView.builder( + physics: const NeverScrollableScrollPhysics(), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: crossAxisCount, + crossAxisSpacing: 10.0, + mainAxisSpacing: 10.0, + childAspectRatio: 1, + mainAxisExtent: 100, + ), + itemCount: widget.options.length, + padding: const EdgeInsets.symmetric(horizontal: 14), + shrinkWrap: true, + itemBuilder: (context, index) { + return Container( + height: MediaQuery.of(context).size.height, + width: MediaQuery.of(context).size.width, + alignment: Alignment.center, + padding: const EdgeInsets.all(0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(0), + color: Colors.transparent, + boxShadow: const [ + BoxShadow( + color: Colors.transparent, + blurRadius: 4, + offset: Offset(0, 2), + ), + ], + ), + child: Center(child: widget.options[index]), + ); + }, + ); + } + + Widget collapseExpandMethod(BuildContext context) { + if (widget.isGrid) { + return _buildCollapseButton(context); + } else { + return _buildExpandButton(context); + } + } + + Widget _buildCollapseButton(BuildContext context) { + return Align( + alignment: const AlignmentDirectional(0.0, 0.0), + child: Container( + decoration: const BoxDecoration( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(0.0), + bottomRight: Radius.circular(0.0), + topLeft: Radius.circular(0.0), + topRight: Radius.circular(0.0), + ), + ), + alignment: const AlignmentDirectional(0.0, 0.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + children: [ + Text( + FFLocalizations.of(context).getVariableText( + enText: 'Minimize', + ptText: 'Minimizar', + ), + style: FlutterFlowTheme.of(context).title1.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).primaryText, + fontSize: 12.0, + fontWeight: FontWeight.w600, + fontStyle: FontStyle.normal, + ), + ), + Align( + alignment: const AlignmentDirectional(0.0, 0.0), + child: FlutterFlowIconButton( + borderColor: Colors.transparent, + borderRadius: 20.0, + borderWidth: 1.0, + buttonSize: 50.0, + fillColor: const Color(0x00FFFFFF), + icon: Icon( + Icons.keyboard_arrow_up_sharp, + color: FlutterFlowTheme.of(context).primary, + ), + onPressed: () async { + await widget.changeMenuStyle?.call(); + }, + ), + ), + ], + ), + ), + ); + } + + Widget _buildExpandButton(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + FFLocalizations.of(context).getVariableText( + enText: 'Expand', + ptText: 'Expandir', + ), + style: FlutterFlowTheme.of(context).title1.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).primaryText, + fontSize: 12.0, + fontWeight: FontWeight.w600, + fontStyle: FontStyle.normal, + ), + ), + Align( + alignment: const AlignmentDirectional(0.0, 0.0), + child: FlutterFlowIconButton( + borderColor: Colors.transparent, + borderRadius: 20.0, + borderWidth: 0.0, + buttonSize: 50.0, + fillColor: const Color(0x00FFFFFF), + icon: Icon( + Icons.keyboard_arrow_down_outlined, + color: FlutterFlowTheme.of(context).primary, + ), + onPressed: () async { + await widget.changeMenuStyle?.call(); + }, + ), + ), + ], + ); + } +} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart new file mode 100644 index 00000000..59464013 --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart @@ -0,0 +1,87 @@ +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +class MenuViewFactory extends StatelessWidget { + final MenuView view; + final MenuItem item; + final bool expandable; + final MenuEntries entry; + + const MenuViewFactory({ + super.key, + required this.view, + required this.item, + required this.expandable, + required this.entry, + }); + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: LicenseRepositoryImpl.stream, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } else if (!snapshot.hasData || snapshot.data! == false) { + return _buildLoadingIndicator(context); + } + return _buildMenuBloc(context); + }, + ); + } + + Widget buildMenu(BuildContext context) { + return _buildMenuBloc(context); + } + + Widget _buildLoadingIndicator(BuildContext context) { + return Center( + child: Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), + child: CircularProgressIndicator( + backgroundColor: FlutterFlowTheme.of(navigatorKey.currentContext!).primaryBackground, + color: FlutterFlowTheme.of(navigatorKey.currentContext!).primary, + ), + ), + ); + } + + Widget _buildMenuBloc(BuildContext context) { + return BlocProvider( + create: (context) => MenuViewBloc( + style: view, + item: item, + menuOptions: entry.getValues, + expandable: expandable, + )..add(MenuViewEvent()), + child: BlocBuilder( + builder: (context, state) { + if (view == MenuView.list_grid) { + return MenuStaggeredView( + options: state.menuEntries, + expandable: expandable, + item: item, + changeMenuStyle: () async {}, + isGrid: state.isGrid, + ); + } else if (view == MenuView.list) { + return MenuListView( + options: state.menuEntries, + expandable: expandable, + item: item, + changeMenuStyle: () async {}, + ); + } + return const SizedBox(); + }, + ), + ); + } +} diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 9f4dfdf2..0cd0f092 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -109,6 +109,7 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { 'quantity': value['quantity'], }, conflictAlgorithm: ConflictAlgorithm.replace); + return; } Future d(String key) async { diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index cc6aa0df..69770f10 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -1,5 +1,6 @@ // ignore_for_file: curly_braces_in_flow_control_structures, prefer_is_empty +import 'dart:async'; import 'dart:developer'; import 'package:hub/backend/api_requests/api_calls.dart'; @@ -21,10 +22,9 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { factory LicenseRemoteDataSourceImpl() => _instance; LicenseRemoteDataSourceImpl._internal(); - final _licenseSubject = BehaviorSubject>(); - - Stream> get licenseStream => _licenseSubject.stream; + final Completer _saveCompleter = Completer(); + @override Future processLicense() async { // if (body['key'] == Module.pets.value && body['display'] == 'VISIVEL') { // await LicenseHelper().s(Module.petsHistory.value, body); @@ -36,11 +36,12 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { // await LicenseHelper().s(Module.aboutProperty.value, body); // } } - + @override Future cleanLicense() async { - _licenseSubject.add([]); + LicenseRepositoryImpl.license.add([]); } + @override Future setupLicense(Database database, bool isNewVersion) async { log('(B) => license'); @@ -52,13 +53,16 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { await LicenseLocalDataSourceImpl().setByKey(activeModuleKey, 'VISIVEL'); if (isNewVersion == true) { await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'VISIVEL'); - await LicenseLocalDataSourceImpl().setByKey([ModuleEnum.aboutProperty.value], 'VISIVEL'); + await LicenseLocalDataSourceImpl().setByKey([Modules.aboutProperty.value], 'VISIVEL'); } else { await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'DESABILITADO'); } - _licenseSubject.add([...activeModuleKey]); + + LicenseRepositoryImpl.license.add([...activeModuleKey]); + _saveCompleter.complete(); } + @override Future fetchLicenses(bool isNewVersion) async { log('(A) => license'); try { @@ -79,16 +83,21 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { if (responseBody == []) { await setupLicense(DatabaseStorage.database, isNewVersion); - _licenseSubject.add([]); + LicenseRepositoryImpl.license.add([]); return false; } + List> saveOperations = []; for (var element in responseBody) { if (licenseContainsKey(element['key'])) { - _saveModule(element); + saveOperations.add(_saveModule(element)); } } - _licenseSubject.add(responseBody); + await Future.wait(saveOperations); + + log('() => License stream add'); + LicenseRepositoryImpl.license.add(responseBody); + _saveCompleter.complete(); return true; } catch (e) { log('Erro ao obter licenças: $e'); @@ -97,8 +106,12 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } } + Future waitForSaveCompletion() async { + await _saveCompleter.future; + } + static bool licenseContainsKey(final String key) { - return ModuleEnum.values.map((e) => e.value).toList().contains(key); + return Modules.values.map((e) => e.value).toList().contains(key); } static Future _saveModule(final dynamic body) async { diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index 240d8733..2569d598 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -2,8 +2,11 @@ import 'package:hub/shared/components/molecules/modules/data/data_sources/licens import 'package:hub/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart'; import 'package:hub/shared/components/molecules/modules/domain/respositories/license_repository.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:rxdart/rxdart.dart'; import 'package:sqflite/sqflite.dart'; +typedef TModule = List; + class LicenseRepositoryImpl implements LicenseRepository { final LicenseLocalDataSource localDataSource = LicenseLocalDataSourceImpl(); final LicenseRemoteDataSource remoteDataSource = LicenseRemoteDataSourceImpl(); @@ -11,7 +14,8 @@ class LicenseRepositoryImpl implements LicenseRepository { LicenseRepositoryImpl(); - static get stream => LicenseRemoteDataSourceImpl().licenseStream; + static final license = BehaviorSubject(); + static get stream => license.stream; Future fetchLicense(bool isNewVersion) async { return await remoteDataSource.fetchLicenses(isNewVersion); diff --git a/lib/shared/components/molecules/modules/enums/active_modules.dart b/lib/shared/components/molecules/modules/domain/entities/active_modules.dart similarity index 84% rename from lib/shared/components/molecules/modules/enums/active_modules.dart rename to lib/shared/components/molecules/modules/domain/entities/active_modules.dart index 81c81234..a2ac143f 100644 --- a/lib/shared/components/molecules/modules/enums/active_modules.dart +++ b/lib/shared/components/molecules/modules/domain/entities/active_modules.dart @@ -4,10 +4,7 @@ import 'package:hub/shared/components/molecules/modules/index.dart'; enum ActiveModuleKey implements BaseModule { messages, liberations, - reservations, access, - pets, - orders, completeSchedule, providerSchedule, deliverySchedule, @@ -33,14 +30,8 @@ enum ActiveModuleKey implements BaseModule { return 'FRE-HUB-MESSAGES'; case ActiveModuleKey.liberations: return 'FRE-HUB-LIBERATIONS'; - case ActiveModuleKey.reservations: - return 'FRE-HUB-RESERVATIONS'; case ActiveModuleKey.access: return 'FRE-HUB-ACCESS'; - case ActiveModuleKey.pets: - return 'FRE-HUB-PETS'; - case ActiveModuleKey.orders: - return 'FRE-HUB-ORDERS'; case ActiveModuleKey.completeSchedule: return 'FRE-HUB-COMPLETE-SCHEDULE'; case ActiveModuleKey.providerSchedule: diff --git a/lib/shared/components/molecules/modules/domain/entities/base_module.dart b/lib/shared/components/molecules/modules/domain/entities/base_module.dart new file mode 100644 index 00000000..b67b25a9 --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/entities/base_module.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; + +abstract class BaseModule { + String get value; + String get name; + IconData get icon; + String get route; +} diff --git a/lib/shared/components/molecules/modules/enums/disabled_modules.dart b/lib/shared/components/molecules/modules/domain/entities/disabled_modules.dart similarity index 100% rename from lib/shared/components/molecules/modules/enums/disabled_modules.dart rename to lib/shared/components/molecules/modules/domain/entities/disabled_modules.dart diff --git a/lib/shared/components/molecules/modules/enums/inactive_modules.dart b/lib/shared/components/molecules/modules/domain/entities/inactive_modules.dart similarity index 77% rename from lib/shared/components/molecules/modules/enums/inactive_modules.dart rename to lib/shared/components/molecules/modules/domain/entities/inactive_modules.dart index ff2dbaa5..0be8edae 100644 --- a/lib/shared/components/molecules/modules/enums/inactive_modules.dart +++ b/lib/shared/components/molecules/modules/domain/entities/inactive_modules.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/modules/enums/enum_modules.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; enum InactiveModuleKey implements BaseModule { @@ -7,6 +6,10 @@ enum InactiveModuleKey implements BaseModule { vehicles, openedVisits, petsHistory, + pets, + orders, + fastpass, + reservations, aboutProperty; @override @@ -31,6 +34,12 @@ enum InactiveModuleKey implements BaseModule { return 'FRE-HUB-PETS-HISTORY'; case InactiveModuleKey.aboutProperty: return 'FRE-HUB-PROPERTY'; + case InactiveModuleKey.pets: + return 'FRE-HUB-PETS'; + case InactiveModuleKey.orders: + return 'FRE-HUB-ORDERS'; + case InactiveModuleKey.reservations: + return 'FRE-HUB-RESERVATIONS'; default: return ''; } diff --git a/lib/shared/components/molecules/modules/domain/entities/index.dart b/lib/shared/components/molecules/modules/domain/entities/index.dart index ccb3a9d2..609f59b0 100644 --- a/lib/shared/components/molecules/modules/domain/entities/index.dart +++ b/lib/shared/components/molecules/modules/domain/entities/index.dart @@ -1,2 +1,7 @@ +export 'active_modules.dart'; +export 'base_module.dart'; +export 'disabled_modules.dart'; +export 'inactive_modules.dart'; export 'license.dart'; export 'module.dart'; +export 'modules.dart'; diff --git a/lib/shared/components/molecules/modules/domain/entities/modules.dart b/lib/shared/components/molecules/modules/domain/entities/modules.dart new file mode 100644 index 00000000..0766112a --- /dev/null +++ b/lib/shared/components/molecules/modules/domain/entities/modules.dart @@ -0,0 +1,271 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + +enum Modules implements BaseModule { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + vehicles, + residents, + openedVisits, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + petsHistory, + peopleOnTheProperty, + settings, + logout; + + @override + String get value { + switch (this) { + case Modules.messages: + return 'FRE-HUB-MESSAGES'; + case Modules.liberations: + return 'FRE-HUB-LIBERATIONS'; + case Modules.reservations: + return 'FRE-HUB-RESERVATIONS'; + case Modules.access: + return 'FRE-HUB-ACCESS'; + case Modules.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case Modules.vehicles: + return 'FRE-HUB-VEHICLES'; + case Modules.residents: + return 'FRE-HUB-RESIDENTS'; + case Modules.pets: + return 'FRE-HUB-PETS'; + case Modules.orders: + return 'FRE-HUB-ORDERS'; + case Modules.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case Modules.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case Modules.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case Modules.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case Modules.fastPass: + return 'FRE-HUB-FASTPASS'; + case Modules.visitors: + return 'FRE-HUB-VISITORS'; + case Modules.qrCode: + return 'FRE-HUB-QRCODE'; + case Modules.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + case Modules.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case Modules.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case Modules.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case Modules.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case Modules.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case Modules.openedVisits: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Visitas em Aberto', + enText: 'Opened Visits', + ); + case Modules.vehicles: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Veículos', + enText: 'Vehicles', + ); + case Modules.residents: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ); + case Modules.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case Modules.petsHistory: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case Modules.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case Modules.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case Modules.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case Modules.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case Modules.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case Modules.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case Modules.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case Modules.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case Modules.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case Modules.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + case Modules.logout: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ); + } + } + + @override + IconData get icon { + switch (this) { + case Modules.messages: + return Icons.chat_outlined; + case Modules.liberations: + return Icons.how_to_reg_outlined; + case Modules.reservations: + return Icons.event_available; + case Modules.access: + return Icons.transfer_within_a_station_outlined; + case Modules.openedVisits: + return Icons.perm_contact_calendar; + case Modules.vehicles: + return Icons.directions_car; + case Modules.residents: + return Icons.groups; + case Modules.pets: + return Icons.pets; + case Modules.petsHistory: + return Icons.pets; + case Modules.peopleOnTheProperty: + return Icons.groups; + case Modules.orders: + return Icons.inventory_2_outlined; + case Modules.completeSchedule: + return Icons.event; + case Modules.providerSchedule: + return Icons.engineering_outlined; + case Modules.deliverySchedule: + return Icons.sports_motorsports_outlined; + case Modules.fastPass: + return Icons.attach_email_outlined; + case Modules.qrCode: + return Icons.qr_code; + case Modules.visitors: + return Icons.person_add_alt_1_outlined; + case Modules.aboutProperty: + return Icons.home; + case Modules.settings: + return Icons.settings; + case Modules.logout: + return Icons.logout; + } + } + + @override + String get route { + switch (this) { + case Modules.messages: + return '/messageHistoryPage'; + case Modules.liberations: + return '/liberationHistory'; + case Modules.reservations: + return '/reservation'; + case Modules.access: + return '/acessHistoryPage'; + case Modules.openedVisits: + return '/visitsOnThePropertyPage'; + case Modules.vehicles: + return '/vehiclesOnThePropertyPage'; + case Modules.residents: + return '/residentsOnThePropertyPage'; + case Modules.pets: + return '/petsPage'; + case Modules.petsHistory: + return '/petsHistoryPage'; + case Modules.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case Modules.orders: + return '/packageOrder'; + case Modules.completeSchedule: + return '/scheduleCompleteVisitPage'; + case Modules.providerSchedule: + return '/provisionalSchedule'; + case Modules.aboutProperty: + return '/aboutProperty'; + case Modules.deliverySchedule: + return '/deliverySchedule'; + case Modules.fastPass: + return '/fastPassPage'; + case Modules.qrCode: + return '/qrCodePage'; + case Modules.visitors: + return '/registerVisitorPage'; + case Modules.settings: + return '/preferencesSettings'; + case Modules.logout: + return '/WelcomePage'; + default: + return ''; + } + } +} diff --git a/lib/shared/components/molecules/modules/enums/enum_modules.dart b/lib/shared/components/molecules/modules/enums/enum_modules.dart deleted file mode 100644 index c46ab43f..00000000 --- a/lib/shared/components/molecules/modules/enums/enum_modules.dart +++ /dev/null @@ -1,549 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; - -abstract class BaseModule { - String get value; - String get name; - IconData get icon; - String get route; -} - -enum ModuleEnum implements BaseModule { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - vehicles, - residents, - openedVisits, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - petsHistory, - peopleOnTheProperty, - settings, - logout; - - @override - String get value { - switch (this) { - case ModuleEnum.messages: - return 'FRE-HUB-MESSAGES'; - case ModuleEnum.liberations: - return 'FRE-HUB-LIBERATIONS'; - case ModuleEnum.reservations: - return 'FRE-HUB-RESERVATIONS'; - case ModuleEnum.access: - return 'FRE-HUB-ACCESS'; - case ModuleEnum.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case ModuleEnum.vehicles: - return 'FRE-HUB-VEHICLES'; - case ModuleEnum.residents: - return 'FRE-HUB-RESIDENTS'; - case ModuleEnum.pets: - return 'FRE-HUB-PETS'; - case ModuleEnum.orders: - return 'FRE-HUB-ORDERS'; - case ModuleEnum.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case ModuleEnum.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case ModuleEnum.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ModuleEnum.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case ModuleEnum.fastPass: - return 'FRE-HUB-FASTPASS'; - case ModuleEnum.visitors: - return 'FRE-HUB-VISITORS'; - case ModuleEnum.qrCode: - return 'FRE-HUB-QRCODE'; - case ModuleEnum.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - case ModuleEnum.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case ModuleEnum.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case ModuleEnum.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case ModuleEnum.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case ModuleEnum.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case ModuleEnum.openedVisits: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Visitas em Aberto', - enText: 'Opened Visits', - ); - case ModuleEnum.vehicles: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Veículos', - enText: 'Vehicles', - ); - case ModuleEnum.residents: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Moradores', - enText: 'Residents', - ); - case ModuleEnum.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case ModuleEnum.petsHistory: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case ModuleEnum.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case ModuleEnum.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case ModuleEnum.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case ModuleEnum.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case ModuleEnum.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case ModuleEnum.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case ModuleEnum.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case ModuleEnum.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case ModuleEnum.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case ModuleEnum.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - case ModuleEnum.logout: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - } - } - - @override - IconData get icon { - switch (this) { - case ModuleEnum.messages: - return Icons.chat_outlined; - case ModuleEnum.liberations: - return Icons.how_to_reg_outlined; - case ModuleEnum.reservations: - return Icons.event_available; - case ModuleEnum.access: - return Icons.transfer_within_a_station_outlined; - case ModuleEnum.openedVisits: - return Icons.perm_contact_calendar; - case ModuleEnum.vehicles: - return Icons.directions_car; - case ModuleEnum.residents: - return Icons.groups; - case ModuleEnum.pets: - return Icons.pets; - case ModuleEnum.petsHistory: - return Icons.pets; - case ModuleEnum.peopleOnTheProperty: - return Icons.groups; - case ModuleEnum.orders: - return Icons.inventory_2_outlined; - case ModuleEnum.completeSchedule: - return Icons.event; - case ModuleEnum.providerSchedule: - return Icons.engineering_outlined; - case ModuleEnum.deliverySchedule: - return Icons.sports_motorsports_outlined; - case ModuleEnum.fastPass: - return Icons.attach_email_outlined; - case ModuleEnum.qrCode: - return Icons.qr_code; - case ModuleEnum.visitors: - return Icons.person_add_alt_1_outlined; - case ModuleEnum.aboutProperty: - return Icons.home; - case ModuleEnum.settings: - return Icons.settings; - case ModuleEnum.logout: - return Icons.logout; - } - } - - @override - String get route { - switch (this) { - case ModuleEnum.messages: - return '/messageHistoryPage'; - case ModuleEnum.liberations: - return '/liberationHistory'; - case ModuleEnum.reservations: - return '/reservation'; - case ModuleEnum.access: - return '/acessHistoryPage'; - case ModuleEnum.openedVisits: - return '/visitsOnThePropertyPage'; - case ModuleEnum.vehicles: - return '/vehiclesOnThePropertyPage'; - case ModuleEnum.residents: - return '/residentsOnThePropertyPage'; - case ModuleEnum.pets: - return '/petsPage'; - case ModuleEnum.petsHistory: - return '/petsHistoryPage'; - case ModuleEnum.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case ModuleEnum.orders: - return '/packageOrder'; - case ModuleEnum.completeSchedule: - return '/scheduleCompleteVisitPage'; - case ModuleEnum.providerSchedule: - return '/provisionalSchedule'; - case ModuleEnum.aboutProperty: - return '/aboutProperty'; - case ModuleEnum.deliverySchedule: - return '/deliverySchedule'; - case ModuleEnum.fastPass: - return '/fastPassPage'; - case ModuleEnum.qrCode: - return '/qrCodePage'; - case ModuleEnum.visitors: - return '/registerVisitorPage'; - case ModuleEnum.settings: - return '/preferencesSettings'; - case ModuleEnum.logout: - return '/WelcomePage'; - default: - return ''; - } - } -} - -enum MenuEntries implements BaseEntry { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - vehicles, - residents, - openedVisits, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - petsHistory, - peopleOnTheProperty, - settings, - logout; - - @override - String get value { - switch (this) { - case ModuleEnum.messages: - return 'FRE-HUB-MESSAGES'; - case ModuleEnum.liberations: - return 'FRE-HUB-LIBERATIONS'; - case ModuleEnum.reservations: - return 'FRE-HUB-RESERVATIONS'; - case ModuleEnum.access: - return 'FRE-HUB-ACCESS'; - case ModuleEnum.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case ModuleEnum.vehicles: - return 'FRE-HUB-VEHICLES'; - case ModuleEnum.residents: - return 'FRE-HUB-RESIDENTS'; - case ModuleEnum.pets: - return 'FRE-HUB-PETS'; - case ModuleEnum.orders: - return 'FRE-HUB-ORDERS'; - case ModuleEnum.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case ModuleEnum.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case ModuleEnum.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ModuleEnum.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case ModuleEnum.fastPass: - return 'FRE-HUB-FASTPASS'; - case ModuleEnum.visitors: - return 'FRE-HUB-VISITORS'; - case ModuleEnum.qrCode: - return 'FRE-HUB-QRCODE'; - case ModuleEnum.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - case ModuleEnum.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case ModuleEnum.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case ModuleEnum.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case ModuleEnum.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case ModuleEnum.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case ModuleEnum.openedVisits: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Visitas em Aberto', - enText: 'Opened Visits', - ); - case ModuleEnum.vehicles: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Veículos', - enText: 'Vehicles', - ); - case ModuleEnum.residents: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Moradores', - enText: 'Residents', - ); - case ModuleEnum.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case ModuleEnum.petsHistory: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case ModuleEnum.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case ModuleEnum.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case ModuleEnum.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case ModuleEnum.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case ModuleEnum.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case ModuleEnum.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case ModuleEnum.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case ModuleEnum.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case ModuleEnum.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case ModuleEnum.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - case ModuleEnum.logout: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - default: - return ''; - } - } - - @override - IconData get icon { - switch (this) { - case ModuleEnum.messages: - return Icons.chat_outlined; - case ModuleEnum.liberations: - return Icons.how_to_reg_outlined; - case ModuleEnum.reservations: - return Icons.event_available; - case ModuleEnum.access: - return Icons.transfer_within_a_station_outlined; - case ModuleEnum.openedVisits: - return Icons.perm_contact_calendar; - case ModuleEnum.vehicles: - return Icons.directions_car; - case ModuleEnum.residents: - return Icons.groups; - case ModuleEnum.pets: - return Icons.pets; - case ModuleEnum.petsHistory: - return Icons.pets; - case ModuleEnum.peopleOnTheProperty: - return Icons.groups; - case ModuleEnum.orders: - return Icons.inventory_2_outlined; - case ModuleEnum.completeSchedule: - return Icons.event; - case ModuleEnum.providerSchedule: - return Icons.engineering_outlined; - case ModuleEnum.deliverySchedule: - return Icons.sports_motorsports_outlined; - case ModuleEnum.fastPass: - return Icons.attach_email_outlined; - case ModuleEnum.qrCode: - return Icons.qr_code; - case ModuleEnum.visitors: - return Icons.person_add_alt_1_outlined; - case ModuleEnum.aboutProperty: - return Icons.home; - case ModuleEnum.settings: - return Icons.settings; - case ModuleEnum.logout: - return Icons.logout; - default: - return Icons.error; - } - } - - @override - String get route { - switch (this) { - case ModuleEnum.messages: - return '/messageHistoryPage'; - case ModuleEnum.liberations: - return '/liberationHistory'; - case ModuleEnum.reservations: - return '/reservation'; - case ModuleEnum.access: - return '/acessHistoryPage'; - case ModuleEnum.openedVisits: - return '/visitsOnThePropertyPage'; - case ModuleEnum.vehicles: - return '/vehiclesOnThePropertyPage'; - case ModuleEnum.residents: - return '/residentsOnThePropertyPage'; - case ModuleEnum.pets: - return '/petsPage'; - case ModuleEnum.petsHistory: - return '/petsHistoryPage'; - case ModuleEnum.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case ModuleEnum.orders: - return '/packageOrder'; - case ModuleEnum.completeSchedule: - return '/scheduleCompleteVisitPage'; - case ModuleEnum.providerSchedule: - return '/provisionalSchedule'; - case ModuleEnum.aboutProperty: - return '/aboutProperty'; - case ModuleEnum.deliverySchedule: - return '/deliverySchedule'; - case ModuleEnum.fastPass: - return '/fastPassPage'; - case ModuleEnum.qrCode: - return '/qrCodePage'; - case ModuleEnum.visitors: - return '/registerVisitorPage'; - case ModuleEnum.settings: - return '/preferencesSettings'; - case ModuleEnum.logout: - return '/WelcomePage'; - default: - return ''; - } - } -} diff --git a/lib/shared/components/molecules/modules/enums/index.dart b/lib/shared/components/molecules/modules/enums/index.dart deleted file mode 100644 index 77515664..00000000 --- a/lib/shared/components/molecules/modules/enums/index.dart +++ /dev/null @@ -1,4 +0,0 @@ -export 'active_modules.dart'; -export 'disabled_modules.dart'; -export 'enum_modules.dart'; -export 'inactive_modules.dart'; diff --git a/lib/shared/components/molecules/modules/index.dart b/lib/shared/components/molecules/modules/index.dart index d58702fc..aa560630 100644 --- a/lib/shared/components/molecules/modules/index.dart +++ b/lib/shared/components/molecules/modules/index.dart @@ -1,4 +1,3 @@ export 'data/index.dart'; export 'domain/index.dart'; export 'presentation/index.dart'; -export 'enums/index.dart'; diff --git a/lib/shared/components/molecules/modules/presentation/index.dart b/lib/shared/components/molecules/modules/presentation/index.dart index 48b6447a..688818c6 100644 --- a/lib/shared/components/molecules/modules/presentation/index.dart +++ b/lib/shared/components/molecules/modules/presentation/index.dart @@ -1,3 +1,2 @@ export 'blocs/index.dart'; -export 'pages/index.dart'; export 'widgets/index.dart'; diff --git a/lib/shared/enums/enum_menu.dart b/lib/shared/enums/enum_menu.dart new file mode 100644 index 00000000..fd0af8ca --- /dev/null +++ b/lib/shared/enums/enum_menu.dart @@ -0,0 +1,699 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + +enum Module implements BaseModule { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + vehicles, + residents, + openedVisits, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + petsHistory, + peopleOnTheProperty, + settings, + logout; + + @override + String get value { + switch (this) { + case Module.messages: + return 'FRE-HUB-MESSAGES'; + case Module.liberations: + return 'FRE-HUB-LIBERATIONS'; + case Module.reservations: + return 'FRE-HUB-RESERVATIONS'; + case Module.access: + return 'FRE-HUB-ACCESS'; + case Module.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case Module.vehicles: + return 'FRE-HUB-VEHICLES'; + case Module.residents: + return 'FRE-HUB-RESIDENTS'; + case Module.pets: + return 'FRE-HUB-PETS'; + case Module.orders: + return 'FRE-HUB-ORDERS'; + case Module.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case Module.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case Module.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case Module.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case Module.fastPass: + return 'FRE-HUB-FASTPASS'; + case Module.visitors: + return 'FRE-HUB-VISITORS'; + case Module.qrCode: + return 'FRE-HUB-QRCODE'; + case Module.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + case Module.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case Module.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case Module.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case Module.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case Module.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case Module.openedVisits: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Visitas em Aberto', + enText: 'Opened Visits', + ); + case Module.vehicles: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Veículos', + enText: 'Vehicles', + ); + case Module.residents: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ); + case Module.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case Module.petsHistory: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case Module.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case Module.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case Module.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case Module.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case Module.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case Module.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case Module.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case Module.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case Module.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case Module.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + case Module.logout: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ); + } + } + + @override + IconData get icon { + switch (this) { + case Module.messages: + return Icons.chat_outlined; + case Module.liberations: + return Icons.how_to_reg_outlined; + case Module.reservations: + return Icons.event_available; + case Module.access: + return Icons.transfer_within_a_station_outlined; + case Module.openedVisits: + return Icons.perm_contact_calendar; + case Module.vehicles: + return Icons.directions_car; + case Module.residents: + return Icons.groups; + case Module.pets: + return Icons.pets; + case Module.petsHistory: + return Icons.pets; + case Module.peopleOnTheProperty: + return Icons.groups; + case Module.orders: + return Icons.inventory_2_outlined; + case Module.completeSchedule: + return Icons.event; + case Module.providerSchedule: + return Icons.engineering_outlined; + case Module.deliverySchedule: + return Icons.sports_motorsports_outlined; + case Module.fastPass: + return Icons.attach_email_outlined; + case Module.qrCode: + return Icons.qr_code; + case Module.visitors: + return Icons.person_add_alt_1_outlined; + case Module.aboutProperty: + return Icons.home; + case Module.settings: + return Icons.settings; + case Module.logout: + return Icons.logout; + } + } + + @override + String get route { + switch (this) { + case Module.messages: + return '/messageHistoryPage'; + case Module.liberations: + return '/liberationHistory'; + case Module.reservations: + return '/reservation'; + case Module.access: + return '/acessHistoryPage'; + case Module.openedVisits: + return '/visitsOnThePropertyPage'; + case Module.vehicles: + return '/vehiclesOnThePropertyPage'; + case Module.residents: + return '/residentsOnThePropertyPage'; + case Module.pets: + return '/petsPage'; + case Module.petsHistory: + return '/petsHistoryPage'; + case Module.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case Module.orders: + return '/packageOrder'; + case Module.completeSchedule: + return '/scheduleCompleteVisitPage'; + case Module.providerSchedule: + return '/provisionalSchedule'; + case Module.aboutProperty: + return '/aboutProperty'; + case Module.deliverySchedule: + return '/deliverySchedule'; + case Module.fastPass: + return '/fastPassPage'; + case Module.qrCode: + return '/qrCodePage'; + case Module.visitors: + return '/registerVisitorPage'; + case Module.settings: + return '/preferencesSettings'; + case Module.logout: + return '/WelcomePage'; + default: + return ''; + } + } +} + +enum HomeMenuEntries implements BaseModule { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + peopleOnTheProperty, + settings; + + @override + String get value { + switch (this) { + case HomeMenuEntries.messages: + return 'FRE-HUB-MESSAGES'; + case HomeMenuEntries.liberations: + return 'FRE-HUB-LIBERATIONS'; + case HomeMenuEntries.reservations: + return 'FRE-HUB-RESERVATIONS'; + case HomeMenuEntries.access: + return 'FRE-HUB-ACCESS'; + case HomeMenuEntries.pets: + return 'FRE-HUB-PETS'; + case HomeMenuEntries.orders: + return 'FRE-HUB-ORDERS'; + case HomeMenuEntries.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case HomeMenuEntries.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case HomeMenuEntries.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case HomeMenuEntries.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case HomeMenuEntries.fastPass: + return 'FRE-HUB-FASTPASS'; + case HomeMenuEntries.visitors: + return 'FRE-HUB-VISITORS'; + case HomeMenuEntries.qrCode: + return 'FRE-HUB-QRCODE'; + case HomeMenuEntries.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case HomeMenuEntries.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case HomeMenuEntries.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case HomeMenuEntries.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case HomeMenuEntries.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case HomeMenuEntries.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case HomeMenuEntries.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case HomeMenuEntries.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case HomeMenuEntries.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case HomeMenuEntries.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case HomeMenuEntries.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case HomeMenuEntries.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case HomeMenuEntries.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case HomeMenuEntries.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case HomeMenuEntries.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case HomeMenuEntries.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + } + } + + @override + IconData get icon { + switch (this) { + case HomeMenuEntries.messages: + return Icons.chat_outlined; + case HomeMenuEntries.liberations: + return Icons.how_to_reg_outlined; + case HomeMenuEntries.reservations: + return Icons.event_available; + case HomeMenuEntries.access: + return Icons.transfer_within_a_station_outlined; + case HomeMenuEntries.pets: + return Icons.pets; + case HomeMenuEntries.peopleOnTheProperty: + return Icons.groups; + case HomeMenuEntries.orders: + return Icons.inventory_2_outlined; + case HomeMenuEntries.completeSchedule: + return Icons.event; + case HomeMenuEntries.providerSchedule: + return Icons.engineering_outlined; + case HomeMenuEntries.deliverySchedule: + return Icons.sports_motorsports_outlined; + case HomeMenuEntries.fastPass: + return Icons.attach_email_outlined; + case HomeMenuEntries.qrCode: + return Icons.qr_code; + case HomeMenuEntries.visitors: + return Icons.person_add_alt_1_outlined; + case HomeMenuEntries.aboutProperty: + return Icons.home; + case HomeMenuEntries.settings: + return Icons.settings; + } + } + + @override + String get route { + switch (this) { + case HomeMenuEntries.messages: + return '/messageHistoryPage'; + case HomeMenuEntries.liberations: + return '/liberationHistory'; + case HomeMenuEntries.reservations: + return '/reservation'; + case HomeMenuEntries.access: + return '/acessHistoryPage'; + case HomeMenuEntries.pets: + return '/petsPage'; + case HomeMenuEntries.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case HomeMenuEntries.orders: + return '/packageOrder'; + case HomeMenuEntries.completeSchedule: + return '/scheduleCompleteVisitPage'; + case HomeMenuEntries.providerSchedule: + return '/provisionalSchedule'; + case HomeMenuEntries.aboutProperty: + return '/aboutProperty'; + case HomeMenuEntries.deliverySchedule: + return '/deliverySchedule'; + case HomeMenuEntries.fastPass: + return '/fastPassPage'; + case HomeMenuEntries.qrCode: + return '/qrCodePage'; + case HomeMenuEntries.visitors: + return '/registerVisitorPage'; + case HomeMenuEntries.settings: + return '/preferencesSettings'; + default: + return ''; + } + } +} + +enum DrawerMenuEntries implements BaseModule { + providerSchedule, + deliverySchedule, + fastPass, + completeSchedule, + orders, + reservations, + visitors, + qrCode, + pets, + access, + liberations, + messages, + aboutProperty, + peopleOnTheProperty, + settings, + logout; + + @override + String get value { + switch (this) { + case DrawerMenuEntries.messages: + return 'FRE-HUB-MESSAGES'; + case DrawerMenuEntries.liberations: + return 'FRE-HUB-LIBERATIONS'; + case DrawerMenuEntries.reservations: + return 'FRE-HUB-RESERVATIONS'; + case DrawerMenuEntries.access: + return 'FRE-HUB-ACCESS'; + case DrawerMenuEntries.pets: + return 'FRE-HUB-PETS'; + case DrawerMenuEntries.orders: + return 'FRE-HUB-ORDERS'; + case DrawerMenuEntries.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case DrawerMenuEntries.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case DrawerMenuEntries.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case DrawerMenuEntries.aboutProperty: + return 'FRE-HUB-PROPERTY'; + case DrawerMenuEntries.fastPass: + return 'FRE-HUB-FASTPASS'; + case DrawerMenuEntries.visitors: + return 'FRE-HUB-VISITORS'; + case DrawerMenuEntries.qrCode: + return 'FRE-HUB-QRCODE'; + case DrawerMenuEntries.peopleOnTheProperty: + return 'FRE-HUB-PEOPLE'; + default: + return ''; + } + } + + @override + String get name { + switch (this) { + case DrawerMenuEntries.messages: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ); + case DrawerMenuEntries.liberations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ); + case DrawerMenuEntries.reservations: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ); + case DrawerMenuEntries.access: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ); + case DrawerMenuEntries.pets: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ); + case DrawerMenuEntries.peopleOnTheProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ); + case DrawerMenuEntries.orders: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ); + case DrawerMenuEntries.completeSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ); + case DrawerMenuEntries.providerSchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ); + case DrawerMenuEntries.deliverySchedule: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ); + case DrawerMenuEntries.fastPass: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ); + case DrawerMenuEntries.qrCode: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ); + case DrawerMenuEntries.visitors: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ); + case DrawerMenuEntries.aboutProperty: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ); + case DrawerMenuEntries.settings: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ); + case DrawerMenuEntries.logout: + return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ); + } + } + + @override + IconData get icon { + switch (this) { + case DrawerMenuEntries.messages: + return Icons.chat_outlined; + case DrawerMenuEntries.liberations: + return Icons.how_to_reg_outlined; + case DrawerMenuEntries.reservations: + return Icons.event_available; + case DrawerMenuEntries.access: + return Icons.transfer_within_a_station_outlined; + case DrawerMenuEntries.pets: + return Icons.pets; + case DrawerMenuEntries.peopleOnTheProperty: + return Icons.groups; + case DrawerMenuEntries.orders: + return Icons.inventory_2_outlined; + case DrawerMenuEntries.completeSchedule: + return Icons.event; + case DrawerMenuEntries.providerSchedule: + return Icons.engineering_outlined; + case DrawerMenuEntries.deliverySchedule: + return Icons.sports_motorsports_outlined; + case DrawerMenuEntries.fastPass: + return Icons.attach_email_outlined; + case DrawerMenuEntries.qrCode: + return Icons.qr_code; + case DrawerMenuEntries.visitors: + return Icons.person_add_alt_1_outlined; + case DrawerMenuEntries.aboutProperty: + return Icons.home; + case DrawerMenuEntries.settings: + return Icons.settings; + case DrawerMenuEntries.logout: + return Icons.exit_to_app; + } + } + + @override + String get route { + switch (this) { + case DrawerMenuEntries.messages: + return '/messageHistoryPage'; + case DrawerMenuEntries.liberations: + return '/liberationHistory'; + case DrawerMenuEntries.reservations: + return '/reservation'; + case DrawerMenuEntries.access: + return '/acessHistoryPage'; + case DrawerMenuEntries.pets: + return '/petsPage'; + case DrawerMenuEntries.peopleOnTheProperty: + return '/peopleOnThePropertyPage'; + case DrawerMenuEntries.orders: + return '/packageOrder'; + case DrawerMenuEntries.completeSchedule: + return '/scheduleCompleteVisitPage'; + case DrawerMenuEntries.providerSchedule: + return '/provisionalSchedule'; + case DrawerMenuEntries.aboutProperty: + return '/aboutProperty'; + case DrawerMenuEntries.deliverySchedule: + return '/deliverySchedule'; + case DrawerMenuEntries.fastPass: + return '/fastPassPage'; + case DrawerMenuEntries.qrCode: + return '/qrCodePage'; + case DrawerMenuEntries.visitors: + return '/registerVisitorPage'; + case DrawerMenuEntries.settings: + return '/preferencesSettings'; + case DrawerMenuEntries.logout: + return '/WelcomePage'; + default: + return ''; + } + } +} diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 15344451..1311fbdc 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -1,13 +1,13 @@ -import 'package:hub/shared/helpers/license/license_helper.dart'; +import 'package:hub/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart'; +import 'package:hub/shared/components/molecules/modules/data/repositories/license_repository_impl.dart'; import 'package:hub/shared/helpers/storage/keychain_storage.dart'; -import 'package:hub/shared/services/license/license_service.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart'; import 'dart:developer'; class DatabaseStorage { static final String _dbName = 'database.db'; - static final int _dbVersion = 2; + static final int _dbVersion = 3; static final DatabaseStorage instance = DatabaseStorage._internal(); factory DatabaseStorage() => instance; @@ -32,22 +32,39 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - await LicenseService().setupLicense(database, false); + await LicenseRepositoryImpl().setupLicense(false); isInitialized = true; } Future _onCreate(Database database, int version) async { log('Creating database...'); - await database.execute(KeychainHelper.createTableQuery); - await database.execute(LicenseHelper.createTableQuery); + await database.execute(KeychainHelper.createKeychainTable); + await database.execute(LicenseLocalDataSourceImpl.createLicenseTable); + if (version >= 2) { + await database.execute(LicenseLocalDataSourceImpl.updatePetsHistoryTrigger); + } + if (version >= 3) { + await database.execute(LicenseLocalDataSourceImpl.updateDisplayTrigger); + } } Future _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); - if (oldVersion < 2) { - await database.execute(LicenseHelper.createTableQuery); + if (oldVersion < 2 && newVersion >= 2) { + await database.execute(LicenseLocalDataSourceImpl.updatePetsHistoryTrigger); + } + if (oldVersion < 3 && newVersion >= 3) { + await database.execute(LicenseLocalDataSourceImpl.updateDisplayTrigger); } } - Future _onDowngrade(Database database, int oldVersion, int newVersion) async {} + Future _onDowngrade(Database database, int oldVersion, int newVersion) async { + log('Downgrading database from version $oldVersion to $newVersion...'); + if (oldVersion >= 3 && newVersion < 3) { + await database.execute(LicenseLocalDataSourceImpl.dropDisplayTrigger); + } + if (oldVersion >= 2 && newVersion < 2) { + await database.execute(LicenseLocalDataSourceImpl.dropPetsHistoryTrigger); + } + } } diff --git a/lib/shared/helpers/license/license_helper.dart b/lib/shared/helpers/license/license_helper.dart deleted file mode 100644 index 9ce5c8b8..00000000 --- a/lib/shared/helpers/license/license_helper.dart +++ /dev/null @@ -1,443 +0,0 @@ -import 'dart:developer'; - -import 'package:flutter/material.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/database/database_helper.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:sqflite/sqflite.dart'; - -enum InactiveModuleKey { - residents, - vehicles, - openedVisits, - petsHistory, - aboutProperty, -} - -extension InactiveModuleKeyExtension on InactiveModuleKey { - String get value { - switch (this) { - case InactiveModuleKey.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case InactiveModuleKey.vehicles: - return 'FRE-HUB-VEHICLES'; - case InactiveModuleKey.residents: - return 'FRE-HUB-RESIDENTS'; - case InactiveModuleKey.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - case InactiveModuleKey.aboutProperty: - return 'FRE-HUB-PROPERTY'; - default: - return ''; - } - } -} - -enum DisabledModuleKey { - fastPass, -} - -extension DisabledModuleKeyExtension on DisabledModuleKey { - String get value { - switch (this) { - case DisabledModuleKey.fastPass: - return 'FRE-HUB-FASTPASS'; - - default: - return ''; - } - } -} - -enum ActiveModuleKey { - messages, - liberations, - reservations, - access, - pets, - orders, - completeSchedule, - providerSchedule, - deliverySchedule, - qrCode, - visitors, - peopleOnTheProperty, - settings, - logout, -} - -extension ActiveModuleKeyExtension on ActiveModuleKey { - String get value { - switch (this) { - case ActiveModuleKey.messages: - return 'FRE-HUB-MESSAGES'; - case ActiveModuleKey.liberations: - return 'FRE-HUB-LIBERATIONS'; - case ActiveModuleKey.reservations: - return 'FRE-HUB-RESERVATIONS'; - case ActiveModuleKey.access: - return 'FRE-HUB-ACCESS'; - case ActiveModuleKey.pets: - return 'FRE-HUB-PETS'; - case ActiveModuleKey.orders: - return 'FRE-HUB-ORDERS'; - case ActiveModuleKey.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case ActiveModuleKey.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case ActiveModuleKey.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ActiveModuleKey.visitors: - return 'FRE-HUB-VISITORS'; - case ActiveModuleKey.qrCode: - return 'FRE-HUB-QRCODE'; - case ActiveModuleKey.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - default: - return ''; - } - } -} - -enum Module { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - vehicles, - residents, - openedVisits, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - petsHistory, - peopleOnTheProperty, - settings, - logout, -} - -extension LicenseKeyExtension on Module { - String get value { - switch (this) { - case Module.messages: - return 'FRE-HUB-MESSAGES'; - case Module.liberations: - return 'FRE-HUB-LIBERATIONS'; - case Module.reservations: - return 'FRE-HUB-RESERVATIONS'; - case Module.access: - return 'FRE-HUB-ACCESS'; - case Module.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case Module.vehicles: - return 'FRE-HUB-VEHICLES'; - case Module.residents: - return 'FRE-HUB-RESIDENTS'; - case Module.pets: - return 'FRE-HUB-PETS'; - case Module.orders: - return 'FRE-HUB-ORDERS'; - case Module.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case Module.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case Module.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case Module.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case Module.fastPass: - return 'FRE-HUB-FASTPASS'; - case Module.visitors: - return 'FRE-HUB-VISITORS'; - case Module.qrCode: - return 'FRE-HUB-QRCODE'; - case Module.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - case Module.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - default: - return ''; - } - } - - String get name { - switch (this) { - case Module.messages: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case Module.liberations: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case Module.reservations: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case Module.access: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case Module.openedVisits: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Visitas em Aberto', - enText: 'Opened Visits', - ); - case Module.vehicles: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Veículos', - enText: 'Vehicles', - ); - case Module.residents: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Moradores', - enText: 'Residents', - ); - case Module.pets: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case Module.petsHistory: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case Module.peopleOnTheProperty: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case Module.orders: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case Module.completeSchedule: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case Module.providerSchedule: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case Module.deliverySchedule: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case Module.fastPass: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case Module.qrCode: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case Module.visitors: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case Module.aboutProperty: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case Module.settings: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - case Module.logout: - return FFLocalizations.of(key.currentContext!).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - } - } - - IconData get icon { - switch (this) { - case Module.messages: - return Icons.chat_outlined; - case Module.liberations: - return Icons.how_to_reg_outlined; - case Module.reservations: - return Icons.event_available; - case Module.access: - return Icons.transfer_within_a_station_outlined; - case Module.openedVisits: - return Icons.perm_contact_calendar; - case Module.vehicles: - return Icons.directions_car; - case Module.residents: - return Icons.groups; - case Module.pets: - return Icons.pets; - case Module.petsHistory: - return Icons.pets; - case Module.peopleOnTheProperty: - return Icons.groups; - case Module.orders: - return Icons.inventory_2_outlined; - case Module.completeSchedule: - return Icons.event; - case Module.providerSchedule: - return Icons.engineering_outlined; - case Module.deliverySchedule: - return Icons.sports_motorsports_outlined; - case Module.fastPass: - return Icons.attach_email_outlined; - case Module.qrCode: - return Icons.qr_code; - case Module.visitors: - return Icons.person_add_alt_1_outlined; - case Module.aboutProperty: - return Icons.home; - case Module.settings: - return Icons.settings; - case Module.logout: - return Icons.logout; - } - } - - String get route { - switch (this) { - case Module.messages: - return '/messageHistoryPage'; - case Module.liberations: - return '/liberationHistory'; - case Module.reservations: - return '/reservation'; - case Module.access: - return '/acessHistoryPage'; - case Module.openedVisits: - return '/visitsOnThePropertyPage'; - case Module.vehicles: - return '/vehiclesOnThePropertyPage'; - case Module.residents: - return '/residentsOnThePropertyPage'; - case Module.pets: - return '/petsPage'; - case Module.petsHistory: - return '/petsHistoryPage'; - case Module.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case Module.orders: - return '/packageOrder'; - case Module.completeSchedule: - return '/scheduleCompleteVisitPage'; - case Module.providerSchedule: - return '/provisionalSchedule'; - case Module.aboutProperty: - return '/aboutProperty'; - case Module.deliverySchedule: - return '/deliverySchedule'; - case Module.fastPass: - return '/fastPassPage'; - case Module.qrCode: - return '/qrCodePage'; - case Module.visitors: - return '/registerVisitorPage'; - case Module.settings: - return '/preferencesSettings'; - case Module.logout: - return '/WelcomePage'; - default: - return ''; - } - } -} - -class LicenseHelper { - static final LicenseHelper _instance = LicenseHelper._internal(); - - factory LicenseHelper() => _instance; - - LicenseHelper._internal(); - - static const String tableLicense = 'license'; - - static String get createTableQuery => ''' - CREATE TABLE $tableLicense ( - key TEXT UNIQUE, - display TEXT, - expirationDate TEXT, - startDate TEXT, - quantity TEXT - ); - '''; - - Future init() async { - await DatabaseStorage.instance.init(); - } - - Future setByKey(final List key, final String display) async { - for (var element in key) { - log('setByKey($element, $display)'); - await s(element, { - 'display': display, - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }); - } - } - - Future isNewVersion() async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [KeychainStorageKey.isNewVersion.value], columns: ['display']); - if (response.isEmpty) { - return false; - } - log('isNewVersion(): ${response.first['display']}'); - return response.first['display'] == 'true'; - } - - Future g(String key) async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); - if (response.isEmpty) { - return null; - } - return response.first.toString(); - } - - Future s(String key, T value) async { - log('setLicense($key, $value)'); - value as Map; - - await DatabaseStorage.database.insert( - tableLicense, - { - 'key': key, - 'display': value['display'], - 'expirationDate': value['expirationDate'], - 'startDate': value['startDate'], - 'quantity': value['quantity'], - }, - conflictAlgorithm: ConflictAlgorithm.replace); - } - - Future d(String key) async { - await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); - } - - Future c() async { - await DatabaseStorage.database.delete(tableLicense); - } -} diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index 4ddd3587..d41cd1e4 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -12,7 +12,7 @@ class KeychainHelper implements BaseStorage { static const String tableKeychain = 'keychain'; bool _isInitialized = false; - static String get createTableQuery => ''' + static String get createKeychainTable => ''' CREATE TABLE $tableKeychain ( key TEXT UNIQUE, value TEXT, @@ -22,6 +22,7 @@ class KeychainHelper implements BaseStorage { createdAt TEXT ); '''; + static String get deleteKeychainTable => 'DROP TABLE IF EXISTS $tableKeychain;'; @override Future init() async { diff --git a/lib/shared/services/deeplink/deep_link_service.dart b/lib/shared/services/deeplink/deep_link_service.dart index f24c6093..3bc1b4c4 100644 --- a/lib/shared/services/deeplink/deep_link_service.dart +++ b/lib/shared/services/deeplink/deep_link_service.dart @@ -57,13 +57,13 @@ class DeepLinkService { try { WidgetsBinding.instance.addPostFrameCallback((_) async { await showModalBottomSheet( - context: key.currentContext!, + context: navigatorKey.currentContext!, builder: (context) => Padding( padding: MediaQuery.viewInsetsOf(context), child: ForgotPasswordScreen(email: email, token: token), ), isScrollControlled: true, - backgroundColor: FlutterFlowTheme.of(key.currentContext!).primaryBackground, + backgroundColor: FlutterFlowTheme.of(navigatorKey.currentContext!).primaryBackground, showDragHandle: true, useSafeArea: true, enableDrag: true, diff --git a/lib/shared/services/keychain/keychain_service.dart b/lib/shared/services/keychain/keychain_service.dart deleted file mode 100644 index a5497f9d..00000000 --- a/lib/shared/services/keychain/keychain_service.dart +++ /dev/null @@ -1,5 +0,0 @@ -class KeychainService { - static final KeychainService _instance = KeychainService._internal(); - factory KeychainService() => _instance; - KeychainService._internal(); -} diff --git a/lib/shared/services/license/license_service.dart b/lib/shared/services/license/license_service.dart deleted file mode 100644 index b6180934..00000000 --- a/lib/shared/services/license/license_service.dart +++ /dev/null @@ -1,103 +0,0 @@ -// ignore_for_file: curly_braces_in_flow_control_structures, prefer_is_empty - -import 'dart:developer'; - -import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/pages/about_property_page/about_property_model.dart'; -import 'package:hub/pages/about_property_page/about_property_screen.dart'; -import 'package:hub/shared/helpers/database/database_helper.dart'; -import 'package:hub/shared/helpers/license/license_helper.dart'; -import 'package:rxdart/rxdart.dart'; -import 'package:sqflite/sqflite.dart'; - -class LicenseService { - static final LicenseService _instance = LicenseService._internal(); - factory LicenseService() => _instance; - LicenseService._internal(); - - final _licenseSubject = BehaviorSubject>(); - - Stream> get licenseStream => _licenseSubject.stream; - - Future processLicense() async { - if (body['key'] == Module.pets.value && body['display'] == 'VISIVEL') { - await LicenseHelper().s(Module.petsHistory.value, body); - } - final bool isAboutProperty = AboutPropertyModules.values.contains(body['key']); - final bool isVisible = body['display'] == 'VISIVEL'; - log('contains () => ${body['key']} - $isAboutProperty'); - if (isAboutProperty && isVisible) { - await LicenseHelper().s(Module.aboutProperty.value, body); - } - } - - Future cleanLicense() async { - _licenseSubject.add([]); - } - - Future setupLicense(Database database, bool isNewVersion) async { - log('(B) => license'); - - final List inactiveModuleKey = InactiveModuleKey.values.map((e) => e.value).toList(); - final List activeModuleKey = ActiveModuleKey.values.map((e) => e.value).toList(); - final List disabledModuleKey = DisabledModuleKey.values.map((e) => e.value).toList(); - - await LicenseHelper().setByKey(inactiveModuleKey, 'INVISIVEL'); - await LicenseHelper().setByKey(activeModuleKey, 'VISIVEL'); - if (isNewVersion == true) { - await LicenseHelper().setByKey(disabledModuleKey, 'VISIVEL'); - await LicenseHelper().setByKey([Module.aboutProperty.value], 'VISIVEL'); - } else { - await LicenseHelper().setByKey(disabledModuleKey, 'DESABILITADO'); - } - _licenseSubject.add([...activeModuleKey]); - } - - Future fetchLicenses(bool isNewVersion) async { - log('(A) => license'); - try { - log('Obtendo licenças...'); - final response = await PhpGroup.getLicense(); - final dynamic responseBody = response.jsonBody; - log('Licenças obtidas: $responseBody'); - - if (response.jsonBody is! List) { - late final String error; - if (response.jsonBody is Map) - error = response.jsonBody['error_msg']; - else - error = 'Erro desconhecido'; - - throw Exception('Erro ao consultar licenças: $error'); - } - - if (responseBody == []) { - await setupLicense(DatabaseStorage.database, isNewVersion); - _licenseSubject.add([]); - return false; - } - - for (var element in responseBody) { - if (licenseContainsKey(element['key'])) { - _saveModule(element); - } - } - _licenseSubject.add(responseBody); - return true; - } catch (e) { - log('Erro ao obter licenças: $e'); - await setupLicense(DatabaseStorage.database, isNewVersion); - return false; - } - } - - static bool licenseContainsKey(final String key) { - return Module.values.map((e) => e.value).toList().contains(key); - } - - static Future _saveModule(final dynamic body) async { - if (body is! Map) return; - log('Salvando módulo: ${body.toString()}'); - await LicenseHelper().s(body['key'], body); - } -} diff --git a/lib/shared/widgets/menu.dart b/lib/shared/widgets/menu.dart deleted file mode 100644 index 7624f6e3..00000000 --- a/lib/shared/widgets/menu.dart +++ /dev/null @@ -1,56 +0,0 @@ -// // LinkedHashMap menu = LinkedHashMap.from({ -// "Schedule": -// [{ -// "title": "Schedule\nVisit", -// "icon": Icons.settings, -// "route": "/Schedule", -// }, -// { -// "title": "Complete\Schedule", -// "icon": Icons.calendar_today, -// "route": "/Complete", -// }, -// { -// "title": "Provisional\Schedule", -// "icon": Icons.calendar_today, -// "route": "/Provisional", -// }, -// { -// "title": "Fast\Schedule", -// "icon": Icons.calendar_today, -// "route": "/Fast", -// }], -// "Consult": -// [{ -// "title": "Consult", -// "icon": Icons.search, -// "route": "/consult", -// }, -// { -// "title": "Liberation\nConsult", -// "icon": Icons.search, -// "route": "/Liberation", -// }, -// { -// "title": "Access\nConsult", -// "icon": Icons.search, -// "route": "/Access", -// }, -// { -// "title": "Poeple\nConsult", -// "icon": Icons.search, -// "route": "/Poeple", -// }, -// { -// "title": "QR Code\nConsult", -// "icon": Icons.search, -// "route": "/qrcode", -// }], -// "Preferences": -// [{ -// "title": "Preferences", -// "icon": Icons.settings, -// "route": "/preferences", -// }], - -// }); diff --git a/pubspec.lock b/pubspec.lock index b0e34950..64d4e4b8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834 + url: "https://pub.dev" + source: hosted + version: "72.0.0" _flutterfire_internals: dependency: transitive description: @@ -9,6 +17,19 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.41" + _macros: + dependency: transitive + description: dart + source: sdk + version: "0.3.2" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139 + url: "https://pub.dev" + source: hosted + version: "6.7.0" app_links: dependency: "direct main" description: @@ -121,6 +142,70 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + build_config: + dependency: transitive + description: + name: build_config + sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 + url: "https://pub.dev" + source: hosted + version: "1.1.1" + build_daemon: + dependency: transitive + description: + name: build_daemon + sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + build_resolvers: + dependency: transitive + description: + name: build_resolvers + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" + url: "https://pub.dev" + source: hosted + version: "2.4.2" + build_runner: + dependency: "direct dev" + description: + name: build_runner + sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d" + url: "https://pub.dev" + source: hosted + version: "2.4.13" + build_runner_core: + dependency: transitive + description: + name: build_runner_core + sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0 + url: "https://pub.dev" + source: hosted + version: "7.3.2" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb + url: "https://pub.dev" + source: hosted + version: "8.9.2" cached_network_image: dependency: "direct main" description: @@ -217,6 +302,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + code_builder: + dependency: transitive + description: + name: code_builder + sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e" + url: "https://pub.dev" + source: hosted + version: "4.10.1" collection: dependency: "direct main" description: @@ -241,6 +334,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" crop_your_image: dependency: "direct main" description: @@ -281,6 +382,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab" + url: "https://pub.dev" + source: hosted + version: "2.3.7" dbus: dependency: transitive description: @@ -741,6 +850,22 @@ packages: url: "https://pub.dev" source: hosted version: "10.8.0" + freezed: + dependency: "direct dev" + description: + name: freezed + sha256: "44c19278dd9d89292cf46e97dc0c1e52ce03275f40a97c5a348e802a924bf40e" + url: "https://pub.dev" + source: hosted + version: "2.5.7" + freezed_annotation: + dependency: "direct main" + description: + name: freezed_annotation + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + url: "https://pub.dev" + source: hosted + version: "2.4.4" from_css_color: dependency: "direct main" description: @@ -749,6 +874,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + url: "https://pub.dev" + source: hosted + version: "4.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" go_router: dependency: "direct main" description: @@ -781,6 +922,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.12.0" + graphs: + dependency: transitive + description: + name: graphs + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" + url: "https://pub.dev" + source: hosted + version: "2.3.2" gtk: dependency: transitive description: @@ -797,6 +946,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" + url: "https://pub.dev" + source: hosted + version: "3.2.1" http_parser: dependency: transitive description: @@ -885,6 +1042,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" + io: + dependency: transitive + description: + name: io + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" iregexp: dependency: transitive description: @@ -902,7 +1067,7 @@ packages: source: hosted version: "0.6.7" json_annotation: - dependency: transitive + dependency: "direct main" description: name: json_annotation sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" @@ -917,6 +1082,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.4" + json_serializable: + dependency: "direct dev" + description: + name: json_serializable + sha256: c2fcb3920cf2b6ae6845954186420fca40bc0a8abcc84903b7801f17d7050d7c + url: "https://pub.dev" + source: hosted + version: "6.9.0" leak_tracker: dependency: transitive description: @@ -997,6 +1170,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" + url: "https://pub.dev" + source: hosted + version: "0.1.2-main.4" matcher: dependency: transitive description: @@ -1077,6 +1258,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" page_transition: dependency: "direct main" description: @@ -1237,6 +1426,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.8" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" provider: dependency: "direct main" description: @@ -1245,6 +1442,22 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.2" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + pubspec_parse: + dependency: transitive + description: + name: pubspec_parse + sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8 + url: "https://pub.dev" + source: hosted + version: "1.3.0" qr: dependency: transitive description: @@ -1365,11 +1578,43 @@ packages: url: "https://pub.dev" source: hosted version: "2.4.1" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67 + url: "https://pub.dev" + source: hosted + version: "2.0.1" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" + url: "https://pub.dev" + source: hosted + version: "1.5.0" + source_helper: + dependency: transitive + description: + name: source_helper + sha256: "6adebc0006c37dd63fe05bca0a929b99f06402fc95aa35bf36d67f5c06de01fd" + url: "https://pub.dev" + source: hosted + version: "1.3.4" source_span: dependency: transitive description: @@ -1498,6 +1743,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.7.0" + timing: + dependency: transitive + description: + name: timing + sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" + url: "https://pub.dev" + source: hosted + version: "1.0.1" typed_data: dependency: transitive description: @@ -1618,6 +1871,14 @@ packages: url: "https://pub.dev" source: hosted version: "14.2.5" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" web: dependency: transitive description: @@ -1626,6 +1887,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" + url: "https://pub.dev" + source: hosted + version: "0.1.6" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" + url: "https://pub.dev" + source: hosted + version: "3.0.1" webview_flutter: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 37258a93..0f320ee2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -101,6 +101,8 @@ dependencies: app_tracking_transparency: ^2.0.6 dio: ^5.7.0 crypto: ^3.0.5 + freezed_annotation: ^2.4.4 + json_annotation: ^4.9.0 dependency_overrides: http: 1.2.1 @@ -119,6 +121,9 @@ dev_dependencies: flutter_test: sdk: flutter + build_runner: ^2.4.13 + freezed: ^2.5.7 + json_serializable: ^6.9.0 flutter_launcher_icons: android: "launcher_icon" From a709c2fde4fd32fdba67eed93e9f18188ddea208 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 29 Nov 2024 18:00:12 -0300 Subject: [PATCH 22/75] WIP --- .../home/presentation/pages/home_page.dart | 2 +- .../pages/about_property_screen.dart | 2 +- lib/main.dart | 7 - .../molecules/drawer/drawer_widget.dart | 4 +- .../locals/presentation/widgets/index.dart | 2 +- .../widgets/local_profile/index.dart | 1 + .../local_profile_widget.dart | 0 .../menu/data/models/base_entry.dart | 5 - .../molecules/menu/data/models/index.dart | 1 - .../molecules/menu/domain/entities/index.dart | 3 + .../menu/domain/entities/menu_entry.dart | 30 +- .../entities}/menu_item.dart | 19 +- .../menu/domain/entities/menu_view.dart | 0 .../presentation/blocs/menu_view_bloc.dart | 41 +- .../widgets/menu_entry/drawer_menu_entry.dart | 3 +- .../widgets/menu_entry/home_menu_entry.dart | 4 +- .../menu_entry/menu_entry_factory.dart | 6 +- .../menu_entry/property_menu_entry.dart | 4 +- .../widgets/menu_factory/menu_factory.dart | 2 +- .../presentation/widgets/menu_item/index.dart | 1 - .../widgets/menu_item/menu_item_button.dart | 4 +- .../widgets/menu_item/menu_item_card.dart | 4 +- .../widgets/menu_item/menu_item_factory.dart | 10 +- .../widgets/menu_view/menu_list_view.dart | 10 +- .../menu_view/menu_staggered_view.dart | 4 +- .../widgets/menu_view/menu_view_factory.dart | 4 +- .../license_local_data_source.dart | 19 +- .../license_remote_data_source.dart | 58 +- .../repositories/license_repository_impl.dart | 4 +- .../domain/entities/active_modules.dart | 51 -- .../domain/entities/disabled_modules.dart | 26 - .../domain/entities/inactive_modules.dart | 47 -- .../modules/domain/entities/index.dart | 5 +- .../modules/domain/entities/license.dart | 771 +++++++++++++++++- .../modules/domain/entities/module.dart | 21 + .../modules/domain/entities/modules.dart | 271 ------ lib/shared/enums/enum_menu.dart | 699 ---------------- 37 files changed, 912 insertions(+), 1233 deletions(-) create mode 100644 lib/shared/components/molecules/locals/presentation/widgets/local_profile/index.dart rename lib/shared/components/molecules/locals/presentation/widgets/{ => local_profile}/local_profile_widget.dart (100%) delete mode 100644 lib/shared/components/molecules/menu/data/models/base_entry.dart rename lib/shared/components/molecules/menu/{presentation/widgets/menu_item => domain/entities}/menu_item.dart (68%) create mode 100644 lib/shared/components/molecules/menu/domain/entities/menu_view.dart delete mode 100644 lib/shared/components/molecules/modules/domain/entities/active_modules.dart delete mode 100644 lib/shared/components/molecules/modules/domain/entities/disabled_modules.dart delete mode 100644 lib/shared/components/molecules/modules/domain/entities/inactive_modules.dart delete mode 100644 lib/shared/components/molecules/modules/domain/entities/modules.dart delete mode 100644 lib/shared/enums/enum_menu.dart diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 6ff3bd82..cecc978c 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -122,7 +122,7 @@ class _HomePageWidgetState extends State { padding: const EdgeInsets.only(bottom: 40), child: MenuFactory( menuEntry: MenuEntries.home, - menuItem: MenuItem.button, + menuItem: EnumMenuItem.button, menuView: MenuView.list_grid, ), ), diff --git a/lib/features/property/presentation/pages/about_property_screen.dart b/lib/features/property/presentation/pages/about_property_screen.dart index 5b06f018..de4bc014 100644 --- a/lib/features/property/presentation/pages/about_property_screen.dart +++ b/lib/features/property/presentation/pages/about_property_screen.dart @@ -79,7 +79,7 @@ class _AboutPropertyPageState extends State with SingleTicker color: FlutterFlowTheme.of(context).primaryBackground, child: MenuFactory( menuEntry: MenuEntries.AboutProperty, - menuItem: MenuItem.button, + menuItem: EnumMenuItem.button, menuView: MenuView.list_grid, ), ), diff --git a/lib/main.dart b/lib/main.dart index 0b75747b..1053f9bd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,22 +2,15 @@ import 'dart:async'; import 'dart:developer'; import 'dart:io'; -import 'package:app_tracking_transparency/app_tracking_transparency.dart'; -import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:flutter_web_plugins/url_strategy.dart'; import 'package:hub/backend/notifications/notification_service.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; -import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; diff --git a/lib/shared/components/molecules/drawer/drawer_widget.dart b/lib/shared/components/molecules/drawer/drawer_widget.dart index 13362990..c913dcb5 100644 --- a/lib/shared/components/molecules/drawer/drawer_widget.dart +++ b/lib/shared/components/molecules/drawer/drawer_widget.dart @@ -13,7 +13,7 @@ class CustomDrawer extends StatelessWidget { @override Widget build(BuildContext context) { - return StreamBuilder( + return StreamBuilder( stream: LicenseRepositoryImpl.stream, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { @@ -191,7 +191,7 @@ class CustomDrawer extends StatelessWidget { Widget _buildDrawerBody(BuildContext context) { return MenuFactory( menuEntry: MenuEntries.drawer, - menuItem: MenuItem.tile, + menuItem: EnumMenuItem.tile, menuView: MenuView.list, ); } diff --git a/lib/shared/components/molecules/locals/presentation/widgets/index.dart b/lib/shared/components/molecules/locals/presentation/widgets/index.dart index 211db207..e0361f45 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/index.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/index.dart @@ -1 +1 @@ -export 'local_profile_widget.dart'; +export 'local_profile/index.dart'; \ No newline at end of file diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/index.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/index.dart new file mode 100644 index 00000000..211db207 --- /dev/null +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/index.dart @@ -0,0 +1 @@ +export 'local_profile_widget.dart'; diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart similarity index 100% rename from lib/shared/components/molecules/locals/presentation/widgets/local_profile_widget.dart rename to lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart diff --git a/lib/shared/components/molecules/menu/data/models/base_entry.dart b/lib/shared/components/molecules/menu/data/models/base_entry.dart deleted file mode 100644 index 9ee9029e..00000000 --- a/lib/shared/components/molecules/menu/data/models/base_entry.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - -abstract class BaseEntry implements BaseModule {} diff --git a/lib/shared/components/molecules/menu/data/models/index.dart b/lib/shared/components/molecules/menu/data/models/index.dart index 7e916547..e69de29b 100644 --- a/lib/shared/components/molecules/menu/data/models/index.dart +++ b/lib/shared/components/molecules/menu/data/models/index.dart @@ -1 +0,0 @@ -export 'base_entry.dart'; diff --git a/lib/shared/components/molecules/menu/domain/entities/index.dart b/lib/shared/components/molecules/menu/domain/entities/index.dart index e69de29b..ab4ce12a 100644 --- a/lib/shared/components/molecules/menu/domain/entities/index.dart +++ b/lib/shared/components/molecules/menu/domain/entities/index.dart @@ -0,0 +1,3 @@ +export 'menu_entry.dart'; +export 'menu_item.dart'; +export 'menu_view.dart'; diff --git a/lib/shared/components/molecules/menu/domain/entities/menu_entry.dart b/lib/shared/components/molecules/menu/domain/entities/menu_entry.dart index b46274fa..6a7bb9e7 100644 --- a/lib/shared/components/molecules/menu/domain/entities/menu_entry.dart +++ b/lib/shared/components/molecules/menu/domain/entities/menu_entry.dart @@ -1,18 +1,20 @@ + import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/modules/domain/entities/license.dart'; +import 'package:hub/shared/components/molecules/modules/domain/entities/base_module.dart'; -class MenuEntry { - final String value; - final String name; - final IconData icon; - final String route; - final ModuleStatus status; - MenuEntry({ - required this.value, - required this.name, - required this.icon, - required this.route, - required this.status, - }); +class MenuEntry implements BaseModule { + @override + IconData get icon => throw UnimplementedError(); + + @override + String get name => throw UnimplementedError(); + + @override + String get route => throw UnimplementedError(); + + @override + String get value => throw UnimplementedError(); } + + diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item.dart b/lib/shared/components/molecules/menu/domain/entities/menu_item.dart similarity index 68% rename from lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item.dart rename to lib/shared/components/molecules/menu/domain/entities/menu_item.dart index 6b2b37ba..479ce679 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item.dart +++ b/lib/shared/components/molecules/menu/domain/entities/menu_item.dart @@ -1,25 +1,25 @@ import 'package:flutter/material.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; -enum MenuItem { +enum EnumMenuItem { button, card, tile; - MenuEntry getInstance(final Function() action, final String title, final IconData icon) { + MenuItem getInstance(final Function() action, final String title, final IconData icon) { switch (this) { - case MenuItem.button: + case EnumMenuItem.button: return MenuButtonWidget(action: action, title: title, icon: icon); - case MenuItem.card: + case EnumMenuItem.card: return MenuCardItem(action: action, title: title, icon: icon); - case MenuItem.tile: + case EnumMenuItem.tile: return MenuCardItem(action: action, title: title, icon: icon); } } } -abstract class MenuEntry extends StatefulWidget { - const MenuEntry({ +abstract class MenuItem extends StatefulWidget { + const MenuItem({ super.key, required this.action, required this.title, @@ -29,9 +29,10 @@ abstract class MenuEntry extends StatefulWidget { final Function() action; final String title; final IconData icon; + - factory MenuEntry.create( - MenuItem type, { + factory MenuItem.create( + EnumMenuItem type, { Key? key, required Function() action, required String title, diff --git a/lib/shared/components/molecules/menu/domain/entities/menu_view.dart b/lib/shared/components/molecules/menu/domain/entities/menu_view.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart index 6f60ca26..914c31d2 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'dart:developer'; import 'package:flutter/material.dart'; @@ -14,12 +15,12 @@ import 'package:hub/shared/extensions/dialog_extensions.dart'; class MenuViewEvent {} class MenuViewState { - final List menuEntries; + final List menuEntries; final bool isGrid; MenuViewState({this.menuEntries = const [], this.isGrid = false}); - MenuViewState copyWith({List? menuEntries, bool? isGrid}) { + MenuViewState copyWith({List? menuEntries, bool? isGrid}) { return MenuViewState( menuEntries: menuEntries ?? this.menuEntries, isGrid: isGrid ?? this.isGrid, @@ -29,9 +30,11 @@ class MenuViewState { class MenuViewBloc extends Bloc { final MenuView style; - final MenuItem item; + final EnumMenuItem item; final bool expandable; - final List menuOptions; + final List menuOptions; + late StreamSubscription _completer; + MenuViewBloc({required this.style, required this.item, required this.expandable, required this.menuOptions}) : super(MenuViewState()) { on((event, emit) async { @@ -39,29 +42,39 @@ class MenuViewBloc extends Bloc { final entries = await generateMenuEntries(); emit(state.copyWith(menuEntries: entries)); }); + + _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { + add(MenuViewEvent()); + }); } - Future addMenuEntry(List entries, IconData icon, String text, Function() action) async { + @override + Future close() { + _completer.cancel(); + return super.close(); + } + + Future addMenuEntry(List entries, IconData icon, String text, Function() action) async { entries.add( - item == MenuItem.button + item == EnumMenuItem.button ? MenuButtonWidget(icon: icon, action: action, title: text) - : item == MenuItem.card + : item == EnumMenuItem.card ? MenuCardItem(icon: icon, action: action, title: text) - : item == MenuItem.tile + : item == EnumMenuItem.tile ? MenuCardItem(icon: icon, action: action, title: text) : null, ); return null; } - Future> generateMenuEntries() async { - List entries = []; + Future> generateMenuEntries() async { + List entries = []; try { for (var opt in menuOptions) { String? licenseValue = await LicenseRepositoryImpl().g(opt.value); if (licenseValue != null) { Map licenseMap = await stringToMap(licenseValue); - if (opt.value == Modules.aboutProperty.value) log('AboutProperty: $licenseMap'); + if (opt.value == 'FRE-HUB-PROPERTY') log('AboutProperty: $licenseMap'); log('Module: ${opt.value} - License: ${licenseMap['display']}'); final String display = licenseMap['display'] ?? 'INVISIVEL'; final String startDate = licenseMap['startDate'] ?? ''; @@ -81,7 +94,7 @@ class MenuViewBloc extends Bloc { return entries; } - Future processDisplay(String display, BaseEntry opt, List entries) async { + Future processDisplay(String display, MenuEntry opt, List entries) async { try { switch (display) { case 'VISIVEL': @@ -103,7 +116,7 @@ class MenuViewBloc extends Bloc { } } - Future processStartDate(String startDate, BaseEntry opt) async { + Future processStartDate(String startDate, MenuEntry opt) async { try { if (startDate.isEmpty) return true; final DateTime? start = DateTime.tryParse(startDate); @@ -116,7 +129,7 @@ class MenuViewBloc extends Bloc { return false; } - Future processExpirationDate(String expirationDate, BaseEntry opt) async { + Future processExpirationDate(String expirationDate, MenuEntry opt) async { try { if (expirationDate.isEmpty) return false; final DateTime? expiration = DateTime.tryParse(expirationDate); diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart index c40adeff..373b9b4a 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart @@ -3,7 +3,7 @@ import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; -enum DrawerMenuEntries implements BaseEntry { +enum DrawerMenuEntries implements MenuEntry { providerSchedule, deliverySchedule, fastPass, @@ -220,4 +220,5 @@ enum DrawerMenuEntries implements BaseEntry { return ''; } } + } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart index c72c2cd2..8ab3a975 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart @@ -3,7 +3,7 @@ import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; -enum HomeMenuEntries implements BaseEntry { +enum HomeMenuEntries implements MenuEntry { providerSchedule, deliverySchedule, fastPass, @@ -210,4 +210,6 @@ enum HomeMenuEntries implements BaseEntry { return ''; } } + + } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart index 8c23e8bc..88d11129 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart @@ -6,7 +6,7 @@ enum MenuEntries { drawer, AboutProperty; - List get getValues { + List get getValues { switch (this) { case MenuEntries.home: return HomeMenuEntries.values.toList(); @@ -19,7 +19,7 @@ enum MenuEntries { } class MenuEntryFactory { - static List createMenuEntry(BaseEntry type) { + static List createMenuEntry(MenuEntry type) { switch (type) { case HomeMenuEntries _: return HomeMenuEntries.values.toList(); @@ -32,7 +32,7 @@ class MenuEntryFactory { } } - List buildMenuEntry(BaseEntry type) { + List buildMenuEntry(MenuEntry type) { return createMenuEntry(type); } } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart index 0a1cb85e..b5d5caa4 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; -enum AboutPropertyMenuEntries implements BaseEntry { +enum AboutPropertyMenuEntries implements MenuEntry { residents, vehicles, openedVisits, @@ -64,4 +64,6 @@ enum AboutPropertyMenuEntries implements BaseEntry { return '/petsOnThePropertyPage'; } } + + } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart index b775544c..d5fd0458 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart @@ -4,7 +4,7 @@ import 'package:hub/shared/components/molecules/menu/index.dart'; class MenuFactory extends StatelessWidget { final MenuView menuView; final MenuEntries menuEntry; - final MenuItem menuItem; + final EnumMenuItem menuItem; const MenuFactory({ super.key, diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart index d6f43bae..375b35a2 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart @@ -1,4 +1,3 @@ -export 'menu_item.dart'; export 'menu_item_button.dart'; export 'menu_item_card.dart'; export 'menu_item_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart index e8a69b01..d95720e6 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; -import 'menu_item.dart'; -class MenuButtonWidget extends MenuEntry { +class MenuButtonWidget extends MenuItem { const MenuButtonWidget({ super.key, required this.action, diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart index a0e226ec..b8031eac 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; -import 'menu_item.dart'; -class MenuCardItem extends MenuEntry { +class MenuCardItem extends MenuItem { const MenuCardItem({ super.key, required this.action, diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart index aa92814d..dfebce2b 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart @@ -2,18 +2,18 @@ import 'package:flutter/material.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; class MenuItemFactory { - static MenuEntry createMenuItem( - MenuItem type, { + static MenuItem createMenuItem( + EnumMenuItem type, { Key? key, required Function() action, required String title, required IconData icon, }) { - return MenuEntry.create(type, key: key, action: action, title: title, icon: icon); + return MenuItem.create(type, key: key, action: action, title: title, icon: icon); } - MenuEntry buildMenuItem( - MenuItem type, { + MenuItem buildMenuItem( + EnumMenuItem type, { Key? key, required Function() action, required String title, diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart index 9787f37c..c8c836db 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart @@ -25,8 +25,8 @@ class MenuListView extends StatefulWidget { }); final bool expandable; - final MenuItem item; - final List options; + final EnumMenuItem item; + final List options; final Future Function()? changeMenuStyle; @override @@ -62,11 +62,11 @@ class _MenuListViewState extends State { Widget buildMenuItem(BuildContext context) { switch (widget.item) { - case MenuItem.button: + case EnumMenuItem.button: return _buildButtonListView(); - case MenuItem.card: + case EnumMenuItem.card: return _buildCardListView(); - case MenuItem.tile: + case EnumMenuItem.tile: return buildMenuList(context); } } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart index a0a0ad30..1d279b70 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart @@ -16,9 +16,9 @@ class MenuStaggeredView extends StatefulWidget { const MenuStaggeredView({super.key, required this.changeMenuStyle, required this.expandable, required this.item, required this.options, required this.isGrid}); final bool expandable; - final MenuItem item; + final EnumMenuItem item; final bool isGrid; - final List options; + final List options; final Future Function()? changeMenuStyle; @override diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart index 59464013..62634c64 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart @@ -8,7 +8,7 @@ import 'package:hub/shared/components/molecules/menu/index.dart'; class MenuViewFactory extends StatelessWidget { final MenuView view; - final MenuItem item; + final EnumMenuItem item; final bool expandable; final MenuEntries entry; @@ -22,7 +22,7 @@ class MenuViewFactory extends StatelessWidget { @override Widget build(BuildContext context) { - return StreamBuilder( + return StreamBuilder( stream: LicenseRepositoryImpl.stream, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 0cd0f092..e9fb7a32 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -66,15 +66,18 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { await DatabaseStorage.instance.init(); } - Future setByKey(final List key, final String display) async { + Future setByKey(final List key, final String display) async { + if (key.isEmpty) return; for (var element in key) { - log('setByKey($element, $display)'); - await s(element, { - 'display': display, - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }); + if (element != null) { + log('setByKey($element, $display)'); + await s(element, { + 'display': display, + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }); + } } } diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 69770f10..d258fbcb 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -22,44 +22,49 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { factory LicenseRemoteDataSourceImpl() => _instance; LicenseRemoteDataSourceImpl._internal(); - final Completer _saveCompleter = Completer(); + + final StreamController _completerController = StreamController.broadcast(); + Stream get streamCompleterController => _completerController.stream; + @override - Future processLicense() async { - // if (body['key'] == Module.pets.value && body['display'] == 'VISIVEL') { - // await LicenseHelper().s(Module.petsHistory.value, body); - // } - // final bool isAboutProperty = AboutPropertyModules.values.contains(body['key']); - // final bool isVisible = body['display'] == 'VISIVEL'; - // log('contains () => ${body['key']} - $isAboutProperty'); - // if (isAboutProperty && isVisible) { - // await LicenseHelper().s(Module.aboutProperty.value, body); - // } - } + Future processLicense() async {} + @override Future cleanLicense() async { - LicenseRepositoryImpl.license.add([]); + LicenseRepositoryImpl.license.add(false); + } - @override + @override Future setupLicense(Database database, bool isNewVersion) async { - log('(B) => license'); + final License license = License.getLicense(isNewVersion); - final List inactiveModuleKey = InactiveModuleKey.values.map((e) => e.value).toList(); - final List activeModuleKey = ActiveModuleKey.values.map((e) => e.value).toList(); - final List disabledModuleKey = DisabledModuleKey.values.map((e) => e.value).toList(); + final List inactiveModuleKey = license.modules + .where((module) => module.display == ModuleStatus.inactive.key) + .map((module) => module.key) + .toList(); + + final List activeModuleKey = license.modules + .where((module) => module.display == ModuleStatus.active.key) + .map((module) => module.key) + .toList(); + + final List disabledModuleKey = license.modules + .where((module) => module.display == ModuleStatus.disabled.key) + .map((module) => module.key) + .toList(); await LicenseLocalDataSourceImpl().setByKey(inactiveModuleKey, 'INVISIVEL'); await LicenseLocalDataSourceImpl().setByKey(activeModuleKey, 'VISIVEL'); if (isNewVersion == true) { await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'VISIVEL'); - await LicenseLocalDataSourceImpl().setByKey([Modules.aboutProperty.value], 'VISIVEL'); + await LicenseLocalDataSourceImpl().setByKey(['FRE-HUB-PROPERTY'], 'VISIVEL'); } else { await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'DESABILITADO'); } - LicenseRepositoryImpl.license.add([...activeModuleKey]); - _saveCompleter.complete(); + LicenseRepositoryImpl.license.add(true); } @override @@ -83,7 +88,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { if (responseBody == []) { await setupLicense(DatabaseStorage.database, isNewVersion); - LicenseRepositoryImpl.license.add([]); + LicenseRepositoryImpl.license.add(false); return false; } @@ -96,8 +101,9 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { await Future.wait(saveOperations); log('() => License stream add'); - LicenseRepositoryImpl.license.add(responseBody); - _saveCompleter.complete(); + LicenseRepositoryImpl.license.add(true); + _completerController.add(null); + return true; } catch (e) { log('Erro ao obter licenças: $e'); @@ -107,11 +113,11 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } Future waitForSaveCompletion() async { - await _saveCompleter.future; + await LicenseRepositoryImpl.stream; } static bool licenseContainsKey(final String key) { - return Modules.values.map((e) => e.value).toList().contains(key); + return License.mods.contains(key); } static Future _saveModule(final dynamic body) async { diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index 2569d598..dcd97a3e 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -5,7 +5,7 @@ import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:rxdart/rxdart.dart'; import 'package:sqflite/sqflite.dart'; -typedef TModule = List; +typedef LicenseStatus = bool; class LicenseRepositoryImpl implements LicenseRepository { final LicenseLocalDataSource localDataSource = LicenseLocalDataSourceImpl(); @@ -14,7 +14,7 @@ class LicenseRepositoryImpl implements LicenseRepository { LicenseRepositoryImpl(); - static final license = BehaviorSubject(); + static final license = BehaviorSubject(); static get stream => license.stream; Future fetchLicense(bool isNewVersion) async { diff --git a/lib/shared/components/molecules/modules/domain/entities/active_modules.dart b/lib/shared/components/molecules/modules/domain/entities/active_modules.dart deleted file mode 100644 index a2ac143f..00000000 --- a/lib/shared/components/molecules/modules/domain/entities/active_modules.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - -enum ActiveModuleKey implements BaseModule { - messages, - liberations, - access, - completeSchedule, - providerSchedule, - deliverySchedule, - qrCode, - visitors, - peopleOnTheProperty, - settings, - logout; - - @override - IconData get icon => throw UnimplementedError(); - - @override - String get name => throw UnimplementedError(); - - @override - String get route => throw UnimplementedError(); - - @override - String get value { - switch (this) { - case ActiveModuleKey.messages: - return 'FRE-HUB-MESSAGES'; - case ActiveModuleKey.liberations: - return 'FRE-HUB-LIBERATIONS'; - case ActiveModuleKey.access: - return 'FRE-HUB-ACCESS'; - case ActiveModuleKey.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case ActiveModuleKey.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case ActiveModuleKey.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case ActiveModuleKey.visitors: - return 'FRE-HUB-VISITORS'; - case ActiveModuleKey.qrCode: - return 'FRE-HUB-QRCODE'; - case ActiveModuleKey.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - default: - return ''; - } - } -} diff --git a/lib/shared/components/molecules/modules/domain/entities/disabled_modules.dart b/lib/shared/components/molecules/modules/domain/entities/disabled_modules.dart deleted file mode 100644 index f773cc4e..00000000 --- a/lib/shared/components/molecules/modules/domain/entities/disabled_modules.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - -enum DisabledModuleKey implements BaseModule { - fastPass; - - @override - IconData get icon => throw UnimplementedError(); - - @override - String get name => throw UnimplementedError(); - - @override - String get route => throw UnimplementedError(); - - @override - String get value { - switch (this) { - case DisabledModuleKey.fastPass: - return 'FRE-HUB-FASTPASS'; - - default: - return ''; - } - } -} diff --git a/lib/shared/components/molecules/modules/domain/entities/inactive_modules.dart b/lib/shared/components/molecules/modules/domain/entities/inactive_modules.dart deleted file mode 100644 index 0be8edae..00000000 --- a/lib/shared/components/molecules/modules/domain/entities/inactive_modules.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - -enum InactiveModuleKey implements BaseModule { - residents, - vehicles, - openedVisits, - petsHistory, - pets, - orders, - fastpass, - reservations, - aboutProperty; - - @override - IconData get icon => throw UnimplementedError(); - - @override - String get name => throw UnimplementedError(); - - @override - String get route => throw UnimplementedError(); - - @override - String get value { - switch (this) { - case InactiveModuleKey.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case InactiveModuleKey.vehicles: - return 'FRE-HUB-VEHICLES'; - case InactiveModuleKey.residents: - return 'FRE-HUB-RESIDENTS'; - case InactiveModuleKey.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - case InactiveModuleKey.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case InactiveModuleKey.pets: - return 'FRE-HUB-PETS'; - case InactiveModuleKey.orders: - return 'FRE-HUB-ORDERS'; - case InactiveModuleKey.reservations: - return 'FRE-HUB-RESERVATIONS'; - default: - return ''; - } - } -} diff --git a/lib/shared/components/molecules/modules/domain/entities/index.dart b/lib/shared/components/molecules/modules/domain/entities/index.dart index 609f59b0..957da76e 100644 --- a/lib/shared/components/molecules/modules/domain/entities/index.dart +++ b/lib/shared/components/molecules/modules/domain/entities/index.dart @@ -1,7 +1,4 @@ -export 'active_modules.dart'; export 'base_module.dart'; -export 'disabled_modules.dart'; -export 'inactive_modules.dart'; + export 'license.dart'; export 'module.dart'; -export 'modules.dart'; diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 743580fa..98aa8797 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -1,26 +1,761 @@ -import 'package:equatable/equatable.dart'; + + +import 'package:hub/shared/extensions/string_extensions.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + import 'module.dart'; -enum ModuleStatus { active, inactive, disabled } +class License { + final List modules; -extension ModuleStatusExtension on ModuleStatus { - String get value { - switch (this) { - case ModuleStatus.active: - return 'VISIVEL'; - case ModuleStatus.inactive: - return 'INVISIVEL'; - case ModuleStatus.disabled: - return 'DESABILITADO'; - } + const License( + this.modules, + ); + + static List mods = [ + 'FRE-HUB-MESSAGES', + 'FRE-HUB-LIBERATIONS', + 'FRE-HUB-RESERVATIONS', + 'FRE-HUB-ACCESS', + 'FRE-HUB-OPENED-VISITS', + 'FRE-HUB-VEHICLES', + 'FRE-HUB-RESIDENTS', + 'FRE-HUB-PETS', + 'FRE-HUB-ORDERS', + 'FRE-HUB-COMPLETE-SCHEDULE', + 'FRE-HUB-AGE-PROV-PRESTADOR', + 'FRE-HUB-AGE-PROV-DELIVERY', + 'FRE-HUB-PROPERTY', + 'FRE-HUB-FASTPASS', + 'FRE-HUB-VISITORS', + 'FRE-HUB-QRCODE', + 'FRE-HUB-PEOPLE', + 'FRE-HUB-PETS-HISTORY' + ]; + + void processOldVersion() async { + final bool whatsapp = await StorageHelper().g(KeychainStorageKey.whatsapp as String).then((v) => v.toBoolean()); + final bool provisional = await StorageHelper().g(KeychainStorageKey.provisional as String).then((v) => v.toBoolean()); + final bool pets = await StorageHelper().g(KeychainStorageKey.pets as String).then((v) => v.toBoolean()); + } + + factory License.getLicense(bool isNewVersion) { + return License([ + Module( + key: 'FRE-HUB-MESSAGES', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-LIBERATIONS', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-RESERVATIONS', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-ACCESS', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-OPENED-VISITS', + display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-VEHICLES', + display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-RESIDENTS', + display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-PETS', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-ORDERS', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-COMPLETE-SCHEDULE', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-AGE-PROV-PRESTADOR', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-AGE-PROV-DELIVERY', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-FASTPASS', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-QRCODE', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-VISITORS', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-PROPERTY', + display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-PEOPLE', + display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: 'FRE-HUB-PETS-HISTORY', + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + ] + ); } } -class License extends Equatable { - final List modules; +// import 'package:equatable/equatable.dart'; +// import 'module.dart'; - const License({required this.modules}); +// import 'package:flutter/material.dart'; +// import 'package:hub/flutter_flow/internationalization.dart'; +// import 'package:hub/flutter_flow/nav/nav.dart'; +// import 'package:hub/shared/components/molecules/modules/index.dart'; - @override - List get props => [modules]; -} +// enum ModuleStatus { active, inactive, disabled } + +// extension ModuleStatusExtension on ModuleStatus { +// String get value { +// switch (this) { +// case ModuleStatus.active: +// return 'VISIVEL'; +// case ModuleStatus.inactive: +// return 'INVISIVEL'; +// case ModuleStatus.disabled: +// return 'DESABILITADO'; +// } +// } +// } + +// class ModuleExt { +// final String value; +// final String name; +// final IconData icon; +// final String route; +// final (ModuleStatus inOldVersion, ModuleStatus inNewVersion) status; + +// const ModuleExt({ +// required this.value, +// required this.name, +// required this.icon, +// required this.route, +// required this.status, +// }); + +// static List get license => [ +// ModuleExt( +// value: 'FRE-HUB-MESSAGES', +// name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Consultar Mensagens', +// enText: 'Messages History', +// ), +// icon: Icons.chat_outlined, +// route: '/messageHistoryPage', +// status: (ModuleStatus.active, ModuleStatus.disabled), +// ), +// ]; +// } + +// enum EModule implements BaseModule { +// providerSchedule, +// deliverySchedule, +// fastPass, +// completeSchedule, +// orders, +// reservations, +// visitors, +// vehicles, +// residents, +// openedVisits, +// qrCode, +// pets, +// access, +// liberations, +// messages, +// aboutProperty, +// petsHistory, +// peopleOnTheProperty, +// settings, +// logout; + +// @override +// String get value { +// switch (this) { +// case Module.messages: +// return 'FRE-HUB-MESSAGES'; +// case Module.liberations: +// return 'FRE-HUB-LIBERATIONS'; +// case Module.reservations: +// return 'FRE-HUB-RESERVATIONS'; +// case Module.access: +// return 'FRE-HUB-ACCESS'; +// case Module.openedVisits: +// return 'FRE-HUB-OPENED-VISITS'; +// case Module.vehicles: +// return 'FRE-HUB-VEHICLES'; +// case Module.residents: +// return 'FRE-HUB-RESIDENTS'; +// case Module.pets: +// return 'FRE-HUB-PETS'; +// case Module.orders: +// return 'FRE-HUB-ORDERS'; +// case Module.completeSchedule: +// return 'FRE-HUB-COMPLETE-SCHEDULE'; +// case Module.providerSchedule: +// return 'FRE-HUB-AGE-PROV-PRESTADOR'; +// case Module.deliverySchedule: +// return 'FRE-HUB-AGE-PROV-DELIVERY'; +// case Module.aboutProperty: +// return 'FRE-HUB-PROPERTY'; +// case Module.fastPass: +// return 'FRE-HUB-FASTPASS'; +// case Module.visitors: +// return 'FRE-HUB-VISITORS'; +// case Module.qrCode: +// return 'FRE-HUB-QRCODE'; +// case Module.peopleOnTheProperty: +// return 'FRE-HUB-PEOPLE'; +// case Module.petsHistory: +// return 'FRE-HUB-PETS-HISTORY'; +// default: +// return ''; +// } +// } + +// @override +// String get name { +// switch (this) { +// case Module.messages: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Consultar Mensagens', +// enText: 'Messages History', +// ); +// case Module.liberations: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Consultar Liberações', +// enText: 'Liberations History', +// ); +// case Module.reservations: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Reservas', +// enText: 'Reservations', +// ); +// case Module.access: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Consultar Acessos', +// enText: 'Access History', +// ); +// case Module.openedVisits: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Visitas em Aberto', +// enText: 'Opened Visits', +// ); +// case Module.vehicles: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Veículos', +// enText: 'Vehicles', +// ); +// case Module.residents: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Moradores', +// enText: 'Residents', +// ); +// case Module.pets: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Pets', +// enText: 'Pets', +// ); +// case Module.petsHistory: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Pets', +// enText: 'Pets', +// ); +// case Module.peopleOnTheProperty: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Pessoas na Propriedade', +// enText: 'People on the Property', +// ); +// case Module.orders: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Minhas Encomendas', +// enText: 'My Orders', +// ); +// case Module.completeSchedule: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Agenda Completa', +// enText: 'Complete Schedule', +// ); +// case Module.providerSchedule: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Agendar Prestadores', +// enText: 'Schedule Providers', +// ); +// case Module.deliverySchedule: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Agendar Delivery', +// enText: 'Schedule Delivery', +// ); +// case Module.fastPass: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Fast Pass', +// enText: 'Fast Pass', +// ); +// case Module.qrCode: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'QRCode de Acesso', +// enText: 'Access QRCode', +// ); +// case Module.visitors: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Cadastrar Visitantes', +// enText: 'Register Visitors', +// ); +// case Module.aboutProperty: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Sobre a Propriedade', +// enText: 'About the Property', +// ); +// case Module.settings: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Configurações', +// enText: 'Settings', +// ); +// case Module.logout: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Sair', +// enText: 'Logout', +// ); +// } +// } + +// @override +// IconData get icon { +// switch (this) { +// case Module.messages: +// return Icons.chat_outlined; +// case Module.liberations: +// return Icons.how_to_reg_outlined; +// case Module.reservations: +// return Icons.event_available; +// case Module.access: +// return Icons.transfer_within_a_station_outlined; +// case Module.openedVisits: +// return Icons.perm_contact_calendar; +// case Module.vehicles: +// return Icons.directions_car; +// case Module.residents: +// return Icons.groups; +// case Module.pets: +// return Icons.pets; +// case Module.petsHistory: +// return Icons.pets; +// case Module.peopleOnTheProperty: +// return Icons.groups; +// case Module.orders: +// return Icons.inventory_2_outlined; +// case Module.completeSchedule: +// return Icons.event; +// case Module.providerSchedule: +// return Icons.engineering_outlined; +// case Module.deliverySchedule: +// return Icons.sports_motorsports_outlined; +// case Module.fastPass: +// return Icons.attach_email_outlined; +// case Module.qrCode: +// return Icons.qr_code; +// case Module.visitors: +// return Icons.person_add_alt_1_outlined; +// case Module.aboutProperty: +// return Icons.home; +// case Module.settings: +// return Icons.settings; +// case Module.logout: +// return Icons.logout; +// } +// } + +// @override +// String get route { +// switch (this) { +// case Module.messages: +// return '/messageHistoryPage'; +// case Module.liberations: +// return '/liberationHistory'; +// case Module.reservations: +// return '/reservation'; +// case Module.access: +// return '/acessHistoryPage'; +// case Module.openedVisits: +// return '/visitsOnThePropertyPage'; +// case Module.vehicles: +// return '/vehiclesOnThePropertyPage'; +// case Module.residents: +// return '/residentsOnThePropertyPage'; +// case Module.pets: +// return '/petsPage'; +// case Module.petsHistory: +// return '/petsHistoryPage'; +// case Module.peopleOnTheProperty: +// return '/peopleOnThePropertyPage'; +// case Module.orders: +// return '/packageOrder'; +// case Module.completeSchedule: +// return '/scheduleCompleteVisitPage'; +// case Module.providerSchedule: +// return '/provisionalSchedule'; +// case Module.aboutProperty: +// return '/aboutProperty'; +// case Module.deliverySchedule: +// return '/deliverySchedule'; +// case Module.fastPass: +// return '/fastPassPage'; +// case Module.qrCode: +// return '/qrCodePage'; +// case Module.visitors: +// return '/registerVisitorPage'; +// case Module.settings: +// return '/preferencesSettings'; +// case Module.logout: +// return '/WelcomePage'; +// default: +// return ''; +// } +// } +// } + +// enum ELicense implements BaseModule { +// providerSchedule, +// deliverySchedule, +// fastPass, +// completeSchedule, +// orders, +// reservations, +// visitors, +// vehicles, +// residents, +// openedVisits, +// qrCode, +// pets, +// access, +// liberations, +// messages, +// aboutProperty, +// petsHistory, +// peopleOnTheProperty, +// settings, +// logout; + +// @override +// String get value { +// switch (this) { +// case License.messages: +// return 'FRE-HUB-MESSAGES'; +// case License.liberations: +// return 'FRE-HUB-LIBERATIONS'; +// case License.reservations: +// return 'FRE-HUB-RESERVATIONS'; +// case License.access: +// return 'FRE-HUB-ACCESS'; +// case License.openedVisits: +// return 'FRE-HUB-OPENED-VISITS'; +// case License.vehicles: +// return 'FRE-HUB-VEHICLES'; +// case License.residents: +// return 'FRE-HUB-RESIDENTS'; +// case License.pets: +// return 'FRE-HUB-PETS'; +// case License.orders: +// return 'FRE-HUB-ORDERS'; +// case License.completeSchedule: +// return 'FRE-HUB-COMPLETE-SCHEDULE'; +// case License.providerSchedule: +// return 'FRE-HUB-AGE-PROV-PRESTADOR'; +// case License.deliverySchedule: +// return 'FRE-HUB-AGE-PROV-DELIVERY'; +// case License.aboutProperty: +// return 'FRE-HUB-PROPERTY'; +// case License.fastPass: +// return 'FRE-HUB-FASTPASS'; +// case License.visitors: +// return 'FRE-HUB-VISITORS'; +// case License.qrCode: +// return 'FRE-HUB-QRCODE'; +// case License.peopleOnTheProperty: +// return 'FRE-HUB-PEOPLE'; +// case License.petsHistory: +// return 'FRE-HUB-PETS-HISTORY'; +// default: +// return ''; +// } +// } + +// @override +// String get name { +// switch (this) { +// case License.messages: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Consultar Mensagens', +// enText: 'Messages History', +// ); +// case License.liberations: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Consultar Liberações', +// enText: 'Liberations History', +// ); +// case License.reservations: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Reservas', +// enText: 'Reservations', +// ); +// case License.access: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Consultar Acessos', +// enText: 'Access History', +// ); +// case License.openedVisits: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Visitas em Aberto', +// enText: 'Opened Visits', +// ); +// case License.vehicles: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Veículos', +// enText: 'Vehicles', +// ); +// case License.residents: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Moradores', +// enText: 'Residents', +// ); +// case License.pets: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Pets', +// enText: 'Pets', +// ); +// case License.petsHistory: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Pets', +// enText: 'Pets', +// ); +// case License.peopleOnTheProperty: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Pessoas na Propriedade', +// enText: 'People on the Property', +// ); +// case License.orders: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Minhas Encomendas', +// enText: 'My Orders', +// ); +// case License.completeSchedule: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Agenda Completa', +// enText: 'Complete Schedule', +// ); +// case License.providerSchedule: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Agendar Prestadores', +// enText: 'Schedule Providers', +// ); +// case License.deliverySchedule: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Agendar Delivery', +// enText: 'Schedule Delivery', +// ); +// case License.fastPass: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Fast Pass', +// enText: 'Fast Pass', +// ); +// case License.qrCode: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'QRCode de Acesso', +// enText: 'Access QRCode', +// ); +// case License.visitors: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Cadastrar Visitantes', +// enText: 'Register Visitors', +// ); +// case License.aboutProperty: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Sobre a Propriedade', +// enText: 'About the Property', +// ); +// case License.settings: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Configurações', +// enText: 'Settings', +// ); +// case License.logout: +// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( +// ptText: 'Sair', +// enText: 'Logout', +// ); +// } +// } + +// @override +// IconData get icon { +// switch (this) { +// case License.messages: +// return Icons.chat_outlined; +// case License.liberations: +// return Icons.how_to_reg_outlined; +// case License.reservations: +// return Icons.event_available; +// case License.access: +// return Icons.transfer_within_a_station_outlined; +// case License.openedVisits: +// return Icons.perm_contact_calendar; +// case License.vehicles: +// return Icons.directions_car; +// case License.residents: +// return Icons.groups; +// case License.pets: +// return Icons.pets; +// case License.petsHistory: +// return Icons.pets; +// case License.peopleOnTheProperty: +// return Icons.groups; +// case License.orders: +// return Icons.inventory_2_outlined; +// case License.completeSchedule: +// return Icons.event; +// case License.providerSchedule: +// return Icons.engineering_outlined; +// case License.deliverySchedule: +// return Icons.sports_motorsports_outlined; +// case License.fastPass: +// return Icons.attach_email_outlined; +// case License.qrCode: +// return Icons.qr_code; +// case License.visitors: +// return Icons.person_add_alt_1_outlined; +// case License.aboutProperty: +// return Icons.home; +// case License.settings: +// return Icons.settings; +// case License.logout: +// return Icons.logout; +// } +// } + +// @override +// String get route { +// switch (this) { +// case License.messages: +// return '/messageHistoryPage'; +// case License.liberations: +// return '/liberationHistory'; +// case License.reservations: +// return '/reservation'; +// case License.access: +// return '/acessHistoryPage'; +// case License.openedVisits: +// return '/visitsOnThePropertyPage'; +// case License.vehicles: +// return '/vehiclesOnThePropertyPage'; +// case License.residents: +// return '/residentsOnThePropertyPage'; +// case License.pets: +// return '/petsPage'; +// case License.petsHistory: +// return '/petsHistoryPage'; +// case License.peopleOnTheProperty: +// return '/peopleOnThePropertyPage'; +// case License.orders: +// return '/packageOrder'; +// case License.completeSchedule: +// return '/scheduleCompleteVisitPage'; +// case License.providerSchedule: +// return '/provisionalSchedule'; +// case License.aboutProperty: +// return '/aboutProperty'; +// case License.deliverySchedule: +// return '/deliverySchedule'; +// case License.fastPass: +// return '/fastPassPage'; +// case License.qrCode: +// return '/qrCodePage'; +// case License.visitors: +// return '/registerVisitorPage'; +// case License.settings: +// return '/preferencesSettings'; +// case License.logout: +// return '/WelcomePage'; +// default: +// return ''; +// } +// } +// } diff --git a/lib/shared/components/molecules/modules/domain/entities/module.dart b/lib/shared/components/molecules/modules/domain/entities/module.dart index f2821e54..060586aa 100644 --- a/lib/shared/components/molecules/modules/domain/entities/module.dart +++ b/lib/shared/components/molecules/modules/domain/entities/module.dart @@ -1,5 +1,22 @@ import 'package:hub/shared/components/molecules/modules/data/models/module_model.dart'; + +enum ModuleStatus { active, inactive, disabled } + +extension ModuleStatusExtension on ModuleStatus { + String get key { + switch (this) { + case ModuleStatus.active: + return 'VISIVEL'; + case ModuleStatus.inactive: + return 'INVISIVEL'; + case ModuleStatus.disabled: + return 'DESABILITADO'; + } + } +} + + class Module { final String key; final String display; @@ -7,12 +24,14 @@ class Module { final String startDate; final int quantity; + Module({ required this.key, required this.display, required this.expirationDate, required this.startDate, required this.quantity, + }); factory Module.fromModel(ModuleModel model) { @@ -34,4 +53,6 @@ class Module { quantity: quantity, ); } + + } diff --git a/lib/shared/components/molecules/modules/domain/entities/modules.dart b/lib/shared/components/molecules/modules/domain/entities/modules.dart deleted file mode 100644 index 0766112a..00000000 --- a/lib/shared/components/molecules/modules/domain/entities/modules.dart +++ /dev/null @@ -1,271 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - -enum Modules implements BaseModule { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - vehicles, - residents, - openedVisits, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - petsHistory, - peopleOnTheProperty, - settings, - logout; - - @override - String get value { - switch (this) { - case Modules.messages: - return 'FRE-HUB-MESSAGES'; - case Modules.liberations: - return 'FRE-HUB-LIBERATIONS'; - case Modules.reservations: - return 'FRE-HUB-RESERVATIONS'; - case Modules.access: - return 'FRE-HUB-ACCESS'; - case Modules.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case Modules.vehicles: - return 'FRE-HUB-VEHICLES'; - case Modules.residents: - return 'FRE-HUB-RESIDENTS'; - case Modules.pets: - return 'FRE-HUB-PETS'; - case Modules.orders: - return 'FRE-HUB-ORDERS'; - case Modules.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case Modules.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case Modules.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case Modules.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case Modules.fastPass: - return 'FRE-HUB-FASTPASS'; - case Modules.visitors: - return 'FRE-HUB-VISITORS'; - case Modules.qrCode: - return 'FRE-HUB-QRCODE'; - case Modules.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - case Modules.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case Modules.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case Modules.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case Modules.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case Modules.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case Modules.openedVisits: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Visitas em Aberto', - enText: 'Opened Visits', - ); - case Modules.vehicles: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Veículos', - enText: 'Vehicles', - ); - case Modules.residents: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Moradores', - enText: 'Residents', - ); - case Modules.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case Modules.petsHistory: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case Modules.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case Modules.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case Modules.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case Modules.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case Modules.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case Modules.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case Modules.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case Modules.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case Modules.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case Modules.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - case Modules.logout: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - } - } - - @override - IconData get icon { - switch (this) { - case Modules.messages: - return Icons.chat_outlined; - case Modules.liberations: - return Icons.how_to_reg_outlined; - case Modules.reservations: - return Icons.event_available; - case Modules.access: - return Icons.transfer_within_a_station_outlined; - case Modules.openedVisits: - return Icons.perm_contact_calendar; - case Modules.vehicles: - return Icons.directions_car; - case Modules.residents: - return Icons.groups; - case Modules.pets: - return Icons.pets; - case Modules.petsHistory: - return Icons.pets; - case Modules.peopleOnTheProperty: - return Icons.groups; - case Modules.orders: - return Icons.inventory_2_outlined; - case Modules.completeSchedule: - return Icons.event; - case Modules.providerSchedule: - return Icons.engineering_outlined; - case Modules.deliverySchedule: - return Icons.sports_motorsports_outlined; - case Modules.fastPass: - return Icons.attach_email_outlined; - case Modules.qrCode: - return Icons.qr_code; - case Modules.visitors: - return Icons.person_add_alt_1_outlined; - case Modules.aboutProperty: - return Icons.home; - case Modules.settings: - return Icons.settings; - case Modules.logout: - return Icons.logout; - } - } - - @override - String get route { - switch (this) { - case Modules.messages: - return '/messageHistoryPage'; - case Modules.liberations: - return '/liberationHistory'; - case Modules.reservations: - return '/reservation'; - case Modules.access: - return '/acessHistoryPage'; - case Modules.openedVisits: - return '/visitsOnThePropertyPage'; - case Modules.vehicles: - return '/vehiclesOnThePropertyPage'; - case Modules.residents: - return '/residentsOnThePropertyPage'; - case Modules.pets: - return '/petsPage'; - case Modules.petsHistory: - return '/petsHistoryPage'; - case Modules.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case Modules.orders: - return '/packageOrder'; - case Modules.completeSchedule: - return '/scheduleCompleteVisitPage'; - case Modules.providerSchedule: - return '/provisionalSchedule'; - case Modules.aboutProperty: - return '/aboutProperty'; - case Modules.deliverySchedule: - return '/deliverySchedule'; - case Modules.fastPass: - return '/fastPassPage'; - case Modules.qrCode: - return '/qrCodePage'; - case Modules.visitors: - return '/registerVisitorPage'; - case Modules.settings: - return '/preferencesSettings'; - case Modules.logout: - return '/WelcomePage'; - default: - return ''; - } - } -} diff --git a/lib/shared/enums/enum_menu.dart b/lib/shared/enums/enum_menu.dart deleted file mode 100644 index fd0af8ca..00000000 --- a/lib/shared/enums/enum_menu.dart +++ /dev/null @@ -1,699 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - -enum Module implements BaseModule { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - vehicles, - residents, - openedVisits, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - petsHistory, - peopleOnTheProperty, - settings, - logout; - - @override - String get value { - switch (this) { - case Module.messages: - return 'FRE-HUB-MESSAGES'; - case Module.liberations: - return 'FRE-HUB-LIBERATIONS'; - case Module.reservations: - return 'FRE-HUB-RESERVATIONS'; - case Module.access: - return 'FRE-HUB-ACCESS'; - case Module.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case Module.vehicles: - return 'FRE-HUB-VEHICLES'; - case Module.residents: - return 'FRE-HUB-RESIDENTS'; - case Module.pets: - return 'FRE-HUB-PETS'; - case Module.orders: - return 'FRE-HUB-ORDERS'; - case Module.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case Module.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case Module.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case Module.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case Module.fastPass: - return 'FRE-HUB-FASTPASS'; - case Module.visitors: - return 'FRE-HUB-VISITORS'; - case Module.qrCode: - return 'FRE-HUB-QRCODE'; - case Module.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - case Module.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case Module.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case Module.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case Module.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case Module.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case Module.openedVisits: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Visitas em Aberto', - enText: 'Opened Visits', - ); - case Module.vehicles: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Veículos', - enText: 'Vehicles', - ); - case Module.residents: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Moradores', - enText: 'Residents', - ); - case Module.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case Module.petsHistory: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case Module.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case Module.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case Module.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case Module.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case Module.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case Module.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case Module.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case Module.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case Module.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case Module.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - case Module.logout: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - } - } - - @override - IconData get icon { - switch (this) { - case Module.messages: - return Icons.chat_outlined; - case Module.liberations: - return Icons.how_to_reg_outlined; - case Module.reservations: - return Icons.event_available; - case Module.access: - return Icons.transfer_within_a_station_outlined; - case Module.openedVisits: - return Icons.perm_contact_calendar; - case Module.vehicles: - return Icons.directions_car; - case Module.residents: - return Icons.groups; - case Module.pets: - return Icons.pets; - case Module.petsHistory: - return Icons.pets; - case Module.peopleOnTheProperty: - return Icons.groups; - case Module.orders: - return Icons.inventory_2_outlined; - case Module.completeSchedule: - return Icons.event; - case Module.providerSchedule: - return Icons.engineering_outlined; - case Module.deliverySchedule: - return Icons.sports_motorsports_outlined; - case Module.fastPass: - return Icons.attach_email_outlined; - case Module.qrCode: - return Icons.qr_code; - case Module.visitors: - return Icons.person_add_alt_1_outlined; - case Module.aboutProperty: - return Icons.home; - case Module.settings: - return Icons.settings; - case Module.logout: - return Icons.logout; - } - } - - @override - String get route { - switch (this) { - case Module.messages: - return '/messageHistoryPage'; - case Module.liberations: - return '/liberationHistory'; - case Module.reservations: - return '/reservation'; - case Module.access: - return '/acessHistoryPage'; - case Module.openedVisits: - return '/visitsOnThePropertyPage'; - case Module.vehicles: - return '/vehiclesOnThePropertyPage'; - case Module.residents: - return '/residentsOnThePropertyPage'; - case Module.pets: - return '/petsPage'; - case Module.petsHistory: - return '/petsHistoryPage'; - case Module.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case Module.orders: - return '/packageOrder'; - case Module.completeSchedule: - return '/scheduleCompleteVisitPage'; - case Module.providerSchedule: - return '/provisionalSchedule'; - case Module.aboutProperty: - return '/aboutProperty'; - case Module.deliverySchedule: - return '/deliverySchedule'; - case Module.fastPass: - return '/fastPassPage'; - case Module.qrCode: - return '/qrCodePage'; - case Module.visitors: - return '/registerVisitorPage'; - case Module.settings: - return '/preferencesSettings'; - case Module.logout: - return '/WelcomePage'; - default: - return ''; - } - } -} - -enum HomeMenuEntries implements BaseModule { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - peopleOnTheProperty, - settings; - - @override - String get value { - switch (this) { - case HomeMenuEntries.messages: - return 'FRE-HUB-MESSAGES'; - case HomeMenuEntries.liberations: - return 'FRE-HUB-LIBERATIONS'; - case HomeMenuEntries.reservations: - return 'FRE-HUB-RESERVATIONS'; - case HomeMenuEntries.access: - return 'FRE-HUB-ACCESS'; - case HomeMenuEntries.pets: - return 'FRE-HUB-PETS'; - case HomeMenuEntries.orders: - return 'FRE-HUB-ORDERS'; - case HomeMenuEntries.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case HomeMenuEntries.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case HomeMenuEntries.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case HomeMenuEntries.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case HomeMenuEntries.fastPass: - return 'FRE-HUB-FASTPASS'; - case HomeMenuEntries.visitors: - return 'FRE-HUB-VISITORS'; - case HomeMenuEntries.qrCode: - return 'FRE-HUB-QRCODE'; - case HomeMenuEntries.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case HomeMenuEntries.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case HomeMenuEntries.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case HomeMenuEntries.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case HomeMenuEntries.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case HomeMenuEntries.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case HomeMenuEntries.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case HomeMenuEntries.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case HomeMenuEntries.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case HomeMenuEntries.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case HomeMenuEntries.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case HomeMenuEntries.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case HomeMenuEntries.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case HomeMenuEntries.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case HomeMenuEntries.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case HomeMenuEntries.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - } - } - - @override - IconData get icon { - switch (this) { - case HomeMenuEntries.messages: - return Icons.chat_outlined; - case HomeMenuEntries.liberations: - return Icons.how_to_reg_outlined; - case HomeMenuEntries.reservations: - return Icons.event_available; - case HomeMenuEntries.access: - return Icons.transfer_within_a_station_outlined; - case HomeMenuEntries.pets: - return Icons.pets; - case HomeMenuEntries.peopleOnTheProperty: - return Icons.groups; - case HomeMenuEntries.orders: - return Icons.inventory_2_outlined; - case HomeMenuEntries.completeSchedule: - return Icons.event; - case HomeMenuEntries.providerSchedule: - return Icons.engineering_outlined; - case HomeMenuEntries.deliverySchedule: - return Icons.sports_motorsports_outlined; - case HomeMenuEntries.fastPass: - return Icons.attach_email_outlined; - case HomeMenuEntries.qrCode: - return Icons.qr_code; - case HomeMenuEntries.visitors: - return Icons.person_add_alt_1_outlined; - case HomeMenuEntries.aboutProperty: - return Icons.home; - case HomeMenuEntries.settings: - return Icons.settings; - } - } - - @override - String get route { - switch (this) { - case HomeMenuEntries.messages: - return '/messageHistoryPage'; - case HomeMenuEntries.liberations: - return '/liberationHistory'; - case HomeMenuEntries.reservations: - return '/reservation'; - case HomeMenuEntries.access: - return '/acessHistoryPage'; - case HomeMenuEntries.pets: - return '/petsPage'; - case HomeMenuEntries.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case HomeMenuEntries.orders: - return '/packageOrder'; - case HomeMenuEntries.completeSchedule: - return '/scheduleCompleteVisitPage'; - case HomeMenuEntries.providerSchedule: - return '/provisionalSchedule'; - case HomeMenuEntries.aboutProperty: - return '/aboutProperty'; - case HomeMenuEntries.deliverySchedule: - return '/deliverySchedule'; - case HomeMenuEntries.fastPass: - return '/fastPassPage'; - case HomeMenuEntries.qrCode: - return '/qrCodePage'; - case HomeMenuEntries.visitors: - return '/registerVisitorPage'; - case HomeMenuEntries.settings: - return '/preferencesSettings'; - default: - return ''; - } - } -} - -enum DrawerMenuEntries implements BaseModule { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - peopleOnTheProperty, - settings, - logout; - - @override - String get value { - switch (this) { - case DrawerMenuEntries.messages: - return 'FRE-HUB-MESSAGES'; - case DrawerMenuEntries.liberations: - return 'FRE-HUB-LIBERATIONS'; - case DrawerMenuEntries.reservations: - return 'FRE-HUB-RESERVATIONS'; - case DrawerMenuEntries.access: - return 'FRE-HUB-ACCESS'; - case DrawerMenuEntries.pets: - return 'FRE-HUB-PETS'; - case DrawerMenuEntries.orders: - return 'FRE-HUB-ORDERS'; - case DrawerMenuEntries.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case DrawerMenuEntries.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case DrawerMenuEntries.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case DrawerMenuEntries.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case DrawerMenuEntries.fastPass: - return 'FRE-HUB-FASTPASS'; - case DrawerMenuEntries.visitors: - return 'FRE-HUB-VISITORS'; - case DrawerMenuEntries.qrCode: - return 'FRE-HUB-QRCODE'; - case DrawerMenuEntries.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case DrawerMenuEntries.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case DrawerMenuEntries.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case DrawerMenuEntries.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case DrawerMenuEntries.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case DrawerMenuEntries.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case DrawerMenuEntries.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case DrawerMenuEntries.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case DrawerMenuEntries.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case DrawerMenuEntries.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case DrawerMenuEntries.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case DrawerMenuEntries.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case DrawerMenuEntries.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case DrawerMenuEntries.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case DrawerMenuEntries.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case DrawerMenuEntries.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - case DrawerMenuEntries.logout: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - } - } - - @override - IconData get icon { - switch (this) { - case DrawerMenuEntries.messages: - return Icons.chat_outlined; - case DrawerMenuEntries.liberations: - return Icons.how_to_reg_outlined; - case DrawerMenuEntries.reservations: - return Icons.event_available; - case DrawerMenuEntries.access: - return Icons.transfer_within_a_station_outlined; - case DrawerMenuEntries.pets: - return Icons.pets; - case DrawerMenuEntries.peopleOnTheProperty: - return Icons.groups; - case DrawerMenuEntries.orders: - return Icons.inventory_2_outlined; - case DrawerMenuEntries.completeSchedule: - return Icons.event; - case DrawerMenuEntries.providerSchedule: - return Icons.engineering_outlined; - case DrawerMenuEntries.deliverySchedule: - return Icons.sports_motorsports_outlined; - case DrawerMenuEntries.fastPass: - return Icons.attach_email_outlined; - case DrawerMenuEntries.qrCode: - return Icons.qr_code; - case DrawerMenuEntries.visitors: - return Icons.person_add_alt_1_outlined; - case DrawerMenuEntries.aboutProperty: - return Icons.home; - case DrawerMenuEntries.settings: - return Icons.settings; - case DrawerMenuEntries.logout: - return Icons.exit_to_app; - } - } - - @override - String get route { - switch (this) { - case DrawerMenuEntries.messages: - return '/messageHistoryPage'; - case DrawerMenuEntries.liberations: - return '/liberationHistory'; - case DrawerMenuEntries.reservations: - return '/reservation'; - case DrawerMenuEntries.access: - return '/acessHistoryPage'; - case DrawerMenuEntries.pets: - return '/petsPage'; - case DrawerMenuEntries.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case DrawerMenuEntries.orders: - return '/packageOrder'; - case DrawerMenuEntries.completeSchedule: - return '/scheduleCompleteVisitPage'; - case DrawerMenuEntries.providerSchedule: - return '/provisionalSchedule'; - case DrawerMenuEntries.aboutProperty: - return '/aboutProperty'; - case DrawerMenuEntries.deliverySchedule: - return '/deliverySchedule'; - case DrawerMenuEntries.fastPass: - return '/fastPassPage'; - case DrawerMenuEntries.qrCode: - return '/qrCodePage'; - case DrawerMenuEntries.visitors: - return '/registerVisitorPage'; - case DrawerMenuEntries.settings: - return '/preferencesSettings'; - case DrawerMenuEntries.logout: - return '/WelcomePage'; - default: - return ''; - } - } -} From ff859a5516024cd2a59db5d5cf45e485ae106f2c Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 2 Dec 2024 08:07:17 -0300 Subject: [PATCH 23/75] check about property icons --- .../presentation/widgets/menu_entry/property_menu_entry.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart index b5d5caa4..5830a53d 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart @@ -27,11 +27,11 @@ enum AboutPropertyMenuEntries implements MenuEntry { IconData get icon { switch (this) { case AboutPropertyMenuEntries.residents: - return Icons.people; + return Icons.groups; case AboutPropertyMenuEntries.vehicles: return Icons.directions_car; case AboutPropertyMenuEntries.openedVisits: - return Icons.open_in_new; + return Icons.perm_contact_calendar; case AboutPropertyMenuEntries.petsHistory: return Icons.pets; } From 0863e92e002c27c40ab49b37fc32507bedf79934 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 2 Dec 2024 08:23:43 -0300 Subject: [PATCH 24/75] WIP --- .../molecules/modules/constants/index.dart | 1 + .../modules/constants/license_constants.dart | 44 +++++++++++++++++++ .../license_local_data_source.dart | 43 +----------------- .../modules/domain/entities/license.dart | 3 +- .../components/molecules/modules/index.dart | 1 + lib/shared/constants/index.dart | 1 + lib/shared/constants/keychain_constants.dart | 13 ++++++ .../helpers/database/database_helper.dart | 20 ++++----- .../helpers/storage/keychain_storage.dart | 3 +- lib/shared/index.dart | 0 10 files changed, 74 insertions(+), 55 deletions(-) create mode 100644 lib/shared/components/molecules/modules/constants/index.dart create mode 100644 lib/shared/components/molecules/modules/constants/license_constants.dart create mode 100644 lib/shared/constants/index.dart create mode 100644 lib/shared/constants/keychain_constants.dart create mode 100644 lib/shared/index.dart diff --git a/lib/shared/components/molecules/modules/constants/index.dart b/lib/shared/components/molecules/modules/constants/index.dart new file mode 100644 index 00000000..799c6845 --- /dev/null +++ b/lib/shared/components/molecules/modules/constants/index.dart @@ -0,0 +1 @@ +export 'license_constants.dart'; diff --git a/lib/shared/components/molecules/modules/constants/license_constants.dart b/lib/shared/components/molecules/modules/constants/license_constants.dart new file mode 100644 index 00000000..c57c07bb --- /dev/null +++ b/lib/shared/components/molecules/modules/constants/license_constants.dart @@ -0,0 +1,44 @@ + + const String tableLicense = 'license'; + + String get createLicenseTable => ''' + CREATE TABLE IF NOT EXISTS $tableLicense ( + key TEXT UNIQUE, + display TEXT, + expirationDate TEXT, + startDate TEXT, + quantity TEXT + ); + '''; + + String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;'; + + String get updatePetsHistoryTrigger => ''' + CREATE TRIGGER update_fre_hub_pets_history + AFTER INSERT ON $tableLicense + WHEN NEW.key = 'FRE-HUB-PETS' + BEGIN + INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) + VALUES ('FRE-HUB-PETS-HISTORY', NEW.display, NEW.expirationDate, NEW.startDate, NEW.quantity); + END; + '''; + + String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;'; + + String get updateDisplayTrigger => ''' + CREATE TRIGGER update_display_trigger + AFTER UPDATE ON $tableLicense + WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') + BEGIN + UPDATE $tableLicense + SET display = CASE + WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') AND display = 'VISIVEL') > 0 + THEN 'VISIVEL' + ELSE 'INVISIVEL' + END + WHERE key = 'FRE-HUB-ABOUT-PROPERTY'; + END; + '''; + + String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;'; + diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index e9fb7a32..01a71a31 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:sqflite/sqflite.dart'; @@ -19,48 +20,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { factory LicenseLocalDataSourceImpl() => _instance; LicenseLocalDataSourceImpl._internal(); - static const String tableLicense = 'license'; - - static String get createLicenseTable => ''' - CREATE TABLE IF NOT EXISTS $tableLicense ( - key TEXT UNIQUE, - display TEXT, - expirationDate TEXT, - startDate TEXT, - quantity TEXT - ); - '''; - - static String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;'; - - static String get updatePetsHistoryTrigger => ''' - CREATE TRIGGER update_fre_hub_pets_history - AFTER INSERT ON $tableLicense - WHEN NEW.key = 'FRE-HUB-PETS' - BEGIN - INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) - VALUES ('FRE-HUB-PETS-HISTORY', NEW.display, NEW.expirationDate, NEW.startDate, NEW.quantity); - END; - '''; - - static String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;'; - - static String get updateDisplayTrigger => ''' - CREATE TRIGGER update_display_trigger - AFTER UPDATE ON $tableLicense - WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') - BEGIN - UPDATE $tableLicense - SET display = CASE - WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') AND display = 'VISIVEL') > 0 - THEN 'VISIVEL' - ELSE 'INVISIVEL' - END - WHERE key = 'FRE-HUB-ABOUT-PROPERTY'; - END; - '''; - - static String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;'; Future init() async { await DatabaseStorage.instance.init(); diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 98aa8797..50f71990 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -169,8 +169,7 @@ class License { startDate: '', quantity: 0, ), - ] - ); + ]); } } diff --git a/lib/shared/components/molecules/modules/index.dart b/lib/shared/components/molecules/modules/index.dart index aa560630..385ad97a 100644 --- a/lib/shared/components/molecules/modules/index.dart +++ b/lib/shared/components/molecules/modules/index.dart @@ -1,3 +1,4 @@ export 'data/index.dart'; export 'domain/index.dart'; export 'presentation/index.dart'; +export 'constants/index.dart'; \ No newline at end of file diff --git a/lib/shared/constants/index.dart b/lib/shared/constants/index.dart new file mode 100644 index 00000000..a810e4ce --- /dev/null +++ b/lib/shared/constants/index.dart @@ -0,0 +1 @@ +export 'keychain_constants.dart'; diff --git a/lib/shared/constants/keychain_constants.dart b/lib/shared/constants/keychain_constants.dart new file mode 100644 index 00000000..4a44fcfb --- /dev/null +++ b/lib/shared/constants/keychain_constants.dart @@ -0,0 +1,13 @@ + const String tableKeychain = 'keychain'; + + String get createKeychainTable => ''' + CREATE TABLE $tableKeychain ( + key TEXT UNIQUE, + value TEXT, + type TEXT, + updateAt TEXT, + resolvedAt TEXT, + createdAt TEXT + ); + '''; + String get deleteKeychainTable => 'DROP TABLE IF EXISTS $tableKeychain;'; \ No newline at end of file diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 1311fbdc..29264dd3 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -1,5 +1,5 @@ -import 'package:hub/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart'; -import 'package:hub/shared/components/molecules/modules/data/repositories/license_repository_impl.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/constants/index.dart'; import 'package:hub/shared/helpers/storage/keychain_storage.dart'; import 'package:sqflite/sqflite.dart'; import 'package:path/path.dart'; @@ -38,33 +38,33 @@ class DatabaseStorage { Future _onCreate(Database database, int version) async { log('Creating database...'); - await database.execute(KeychainHelper.createKeychainTable); - await database.execute(LicenseLocalDataSourceImpl.createLicenseTable); + await database.execute(createKeychainTable); + await database.execute(createLicenseTable); if (version >= 2) { - await database.execute(LicenseLocalDataSourceImpl.updatePetsHistoryTrigger); + await database.execute(updatePetsHistoryTrigger); } if (version >= 3) { - await database.execute(LicenseLocalDataSourceImpl.updateDisplayTrigger); + await database.execute(updateDisplayTrigger); } } Future _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2 && newVersion >= 2) { - await database.execute(LicenseLocalDataSourceImpl.updatePetsHistoryTrigger); + await database.execute(updatePetsHistoryTrigger); } if (oldVersion < 3 && newVersion >= 3) { - await database.execute(LicenseLocalDataSourceImpl.updateDisplayTrigger); + await database.execute(updateDisplayTrigger); } } Future _onDowngrade(Database database, int oldVersion, int newVersion) async { log('Downgrading database from version $oldVersion to $newVersion...'); if (oldVersion >= 3 && newVersion < 3) { - await database.execute(LicenseLocalDataSourceImpl.dropDisplayTrigger); + await database.execute(dropDisplayTrigger); } if (oldVersion >= 2 && newVersion < 2) { - await database.execute(LicenseLocalDataSourceImpl.dropPetsHistoryTrigger); + await database.execute(dropPetsHistoryTrigger); } } } diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index d41cd1e4..f89c5394 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -9,9 +9,10 @@ class KeychainHelper implements BaseStorage { static final KeychainHelper instance = KeychainHelper._(); - static const String tableKeychain = 'keychain'; bool _isInitialized = false; + static const String tableKeychain = 'keychain'; + static String get createKeychainTable => ''' CREATE TABLE $tableKeychain ( key TEXT UNIQUE, diff --git a/lib/shared/index.dart b/lib/shared/index.dart new file mode 100644 index 00000000..e69de29b From 17f8cf733f29791c163a759616f8624b0b47f6ed Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 2 Dec 2024 09:12:38 -0300 Subject: [PATCH 25/75] remove logs --- lib/backend/api_requests/api_calls.dart | 76 +++++++++---------- .../locals_remote_data_source.dart | 50 ++++++------ .../presentation/blocs/menu_view_bloc.dart | 10 +-- .../molecules/modules/constants/index.dart | 2 +- .../modules/constants/license_constants.dart | 12 +++ .../license_remote_data_source.dart | 8 +- .../helpers/database/database_helper.dart | 8 +- .../helpers/storage/keychain_storage.dart | 15 +--- 8 files changed, 90 insertions(+), 91 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 96038903..269dcf4c 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -70,7 +70,7 @@ class GetOpenedVisits { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getOpenedVisits'; const String pageSize = '10'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getOpenedVisits', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -102,7 +102,7 @@ class GetResidentsByProperty { final String cliID = await StorageHelper().g(KeychainStorageKey.clientUUID.value) ?? ''; const String atividade = 'getResidentsByProperty'; const String pageSize = '10'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getResidentsByProperty', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -133,7 +133,7 @@ class GetVehiclesByProperty { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVehiclesByProperty'; const String pageSize = '10'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getVehiclesByProperty', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -165,7 +165,7 @@ class TestCall { const String usuEmail = 'email_app@exemplo.com'; const String idDestino = '1'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getLicense', apiUrl: 'https://residenceapi.fre.com.br/getLicenca.php', callType: ApiCallType.POST, @@ -195,7 +195,7 @@ class GetLicense { final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getLicense', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -225,7 +225,7 @@ class UnregisterDevice { final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'unregisterDevice', apiUrl: '$baseUrl/unregisterDevice.php', callType: ApiCallType.POST, @@ -255,7 +255,7 @@ class DeletePet { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'excluirPet'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'deletePet', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -300,7 +300,7 @@ class UpdatePet { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'atualizarPet'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'updatePet', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -346,7 +346,7 @@ class GetPets { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaPets'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getPets', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -380,7 +380,7 @@ class GetPetPhoto { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaFotoPet'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getPetPhoto', apiUrl: '$baseUrl/getImage.php', callType: ApiCallType.POST, @@ -423,7 +423,7 @@ class RegisterPet { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cadastrarPet'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'registerPet', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -470,7 +470,7 @@ class BuscaEnconcomendas { final String baseUrl = PhpGroup.getBaseUrl(); - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getEncomendas', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -512,7 +512,7 @@ class CancelaVisita { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'cancelaVisita', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -545,7 +545,7 @@ class DeleteAccount { final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String baseUrl = PhpGroup.getBaseUrl(); - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'deleteAccount', apiUrl: '$baseUrl/deleteAccount.php', callType: ApiCallType.POST, @@ -578,7 +578,7 @@ class ChangePanic { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'changePass', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -614,7 +614,7 @@ class ChangePass { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'changePass', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -649,7 +649,7 @@ class RespondeVinculo { final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'respondeVinculo', apiUrl: '$baseUrl/responderVinculo.php', callType: ApiCallType.POST, @@ -684,7 +684,7 @@ class ChangeNotifica { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'changeNotifica', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -719,7 +719,7 @@ class UpdateIDE { final String newIde = (await StorageHelper().g(KeychainStorageKey.userDevUUID.value)) ?? ''; const String atividade = 'updVisitado'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'changeNotifica', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -752,7 +752,7 @@ class UpdToken { final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String token = (await StorageHelper().g(SecureStorageKey.token.value)) ?? ''; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'updToken', apiUrl: '$baseUrl/updtoken.php', callType: ApiCallType.POST, @@ -792,7 +792,7 @@ class LoginCall { LogUtil.requestAPIFailed('login.php', email, "Login", e, s); } - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'login', apiUrl: '$baseUrl/login.php', callType: ApiCallType.POST, @@ -830,7 +830,7 @@ class RegisterCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'register', apiUrl: '$baseUrl/registro.php', callType: ApiCallType.POST, @@ -868,7 +868,7 @@ class ChangePasswordCall { final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'changePassword', apiUrl: '$baseUrl/alterarSenha.php', callType: ApiCallType.POST, @@ -900,7 +900,7 @@ class ForgotPasswordCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'forgotPassword', apiUrl: '$baseUrl/iforgot.php', callType: ApiCallType.POST, @@ -928,7 +928,7 @@ class GetLocalsCall { final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getLocals', apiUrl: '$baseUrl/getLocais.php', callType: ApiCallType.POST, @@ -970,7 +970,7 @@ class PostScheduleVisitorCall { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisitante'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'postScheduleVisitor', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -1025,7 +1025,7 @@ class PostScheduleVisitCall { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisita'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'postScheduleVisit', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -1079,7 +1079,7 @@ class GetScheduleVisitCall { final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getScheduleVisit', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -1353,7 +1353,7 @@ class GetDadosCall { final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getDados'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getDados', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -1586,7 +1586,7 @@ class GetVisitorByDocCall { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitante'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getVisitorByDoc', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -1640,7 +1640,7 @@ class GetFotoVisitanteCall { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getFotoVisitante'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getFotoVisitante', apiUrl: '$baseUrl/getImage.php', callType: ApiCallType.GET, @@ -1679,7 +1679,7 @@ class PostProvVisitSchedulingCall { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putAgendamentoProv'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'postProvVisitScheduling', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -1728,7 +1728,7 @@ class GetVisitsCall { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getVisits', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -1991,7 +1991,7 @@ class DeleteVisitCall { final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'deleteVisit', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -2034,7 +2034,7 @@ class GetPessoasLocalCall { final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', apiUrl: '$baseUrl/getPessoasLocal.php', callType: ApiCallType.POST, @@ -2100,7 +2100,7 @@ class RespondeSolicitacaoCall { final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'respondeSolicitacao'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'respondeSolicitacao', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -2150,7 +2150,7 @@ class GetAccessCall { final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getAcessos'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getAccess', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, @@ -2591,7 +2591,7 @@ class GetMessagesCall { final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getMensagens'; - return ApiManager.instance.makeApiCall( + return await ApiManager.instance.makeApiCall( callName: 'getMessages', apiUrl: '$baseUrl/processRequest.php', callType: ApiCallType.POST, diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index a07318f0..05ecdc28 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -147,15 +147,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { try { final GetDadosCall callback = PhpGroup.getDadosCall; ApiCallResponse? response = await callback.call(); - final bool? isError = response.jsonBody['error']; - - if (isError == true) { - final GetLocalsCall callback = PhpGroup.getLocalsCall; - response = await callback.call(); - final String errorMsg = response.jsonBody['error_msg']; - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); - return false; - } else if (response.jsonBody == null) { + if (response.jsonBody == null) { final GetLocalsCall callback = PhpGroup.getLocalsCall; response = await callback.call(); final String errorMsg = FFLocalizations.of(context).getVariableText( @@ -164,17 +156,24 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { ); await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; + } + + final bool? isError = response.jsonBody['error']; + if (isError == true) { + final GetLocalsCall callback = PhpGroup.getLocalsCall; + response = await callback.call(); + final String errorMsg = response.jsonBody['error_msg'] ?? 'Unknown error'; + await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + return false; } else { final bool isNewVersion = await _updateStorageUtil(response.jsonBody); await LicenseRepositoryImpl().setupLicense(isNewVersion); if (isNewVersion) { - log('(A) => isNewVersion: $isNewVersion'); return await LicenseRepositoryImpl().fetchLicense(isNewVersion); } return false; } } catch (e, s) { - log('() => stack processData: $s'); log('() => error processData: $e', stackTrace: s); final String errorMsg = FFLocalizations.of(context).getVariableText( enText: 'Error getting data, verify your connection', @@ -256,7 +255,6 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; final bool isDevLinked = !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); log('() => isLinked: $errorMsg'); - log('() => isLinked: $errorMsg'); if (!isAuthenticated) { errorMsg = FFLocalizations.of(context).getVariableText( ptText: 'Erro ao obter credenciais de autenticação', @@ -316,21 +314,21 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { } Future _updateStorageUtil(Map jsonBody) async { - await StorageHelper().s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] != null && jsonBody['whatsapp']); - await StorageHelper().s(KeychainStorageKey.provisional.value, jsonBody['provisional'] != null && jsonBody['provisional']); - await StorageHelper().s(KeychainStorageKey.pets.value, jsonBody['pet'] != null && jsonBody['pet']); - await StorageHelper().s(KeychainStorageKey.petAmount.value, - jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty ? '0' : jsonBody['petAmountRegister'].toString()); - await StorageHelper().s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME']); + try { + await StorageHelper().s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] ?? false); + await StorageHelper().s(KeychainStorageKey.provisional.value, jsonBody['provisional'] ?? false); + await StorageHelper().s(KeychainStorageKey.pets.value, jsonBody['pet'] ?? false); + await StorageHelper().s(KeychainStorageKey.petAmount.value, + jsonBody['petAmountRegister']?.toString().isEmpty ?? true ? '0' : jsonBody['petAmountRegister'].toString()); + await StorageHelper().s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'] ?? ''); - late final bool isNewVersion; - if (jsonBody['newVersion'] != null) - isNewVersion = jsonBody['newVersion']; - else - isNewVersion = false; - log('() => isNewVersion: ${jsonBody['newVersion']}'); - await StorageHelper().s(KeychainStorageKey.isNewVersion.value, isNewVersion); - return isNewVersion; + final bool isNewVersion = jsonBody['newVersion'] ?? false; + await StorageHelper().s(KeychainStorageKey.isNewVersion.value, isNewVersion); + return isNewVersion; + } catch (e, s) { + log('Error in _updateStorageUtil: $e', stackTrace: s); + return false; + } } bool _isActive(List locals) { diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart index 914c31d2..c85dd950 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart @@ -74,22 +74,19 @@ class MenuViewBloc extends Bloc { String? licenseValue = await LicenseRepositoryImpl().g(opt.value); if (licenseValue != null) { Map licenseMap = await stringToMap(licenseValue); - if (opt.value == 'FRE-HUB-PROPERTY') log('AboutProperty: $licenseMap'); - log('Module: ${opt.value} - License: ${licenseMap['display']}'); final String display = licenseMap['display'] ?? 'INVISIVEL'; final String startDate = licenseMap['startDate'] ?? ''; final String expirationDate = licenseMap['expirationDate'] ?? ''; final bool isStarted = await processStartDate(startDate, opt); - log('isStarted: $isStarted'); final bool isExpired = await processExpirationDate(expirationDate, opt); - log('isExpired: $isExpired'); if (isStarted && !isExpired) { await processDisplay(display, opt, entries); } } } - } catch (e) { - log('Error generating menu entries: $e'); + } catch (e, s) { + log('Error generating menu entries: $e', stackTrace: s); + } return entries; } @@ -143,7 +140,6 @@ class MenuViewBloc extends Bloc { } Future nav(String link) async { - log('Opening: $link'); navigatorKey.currentContext!.push(link, extra: { kTransitionInfoKey: const TransitionInfo( hasTransition: false, diff --git a/lib/shared/components/molecules/modules/constants/index.dart b/lib/shared/components/molecules/modules/constants/index.dart index 799c6845..20bc3626 100644 --- a/lib/shared/components/molecules/modules/constants/index.dart +++ b/lib/shared/components/molecules/modules/constants/index.dart @@ -1 +1 @@ -export 'license_constants.dart'; +export 'license_constants.dart'; \ No newline at end of file diff --git a/lib/shared/components/molecules/modules/constants/license_constants.dart b/lib/shared/components/molecules/modules/constants/license_constants.dart index c57c07bb..da40fef4 100644 --- a/lib/shared/components/molecules/modules/constants/license_constants.dart +++ b/lib/shared/components/molecules/modules/constants/license_constants.dart @@ -42,3 +42,15 @@ String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;'; + String get updatePeopleDisplayTrigger => ''' + CREATE TRIGGER update_people_display_trigger + AFTER UPDATE ON $tableLicense + WHEN NEW.key = 'FRE-HUB-ABOUT-PROPERTY' AND NEW.display = 'VISIVEL' + BEGIN + UPDATE $tableLicense + SET display = 'INVISIVEL' + WHERE key = 'FRE-HUB-PEOPLE'; + END; + '''; + + String get dropPeopleDisplayTrigger => 'DROP TRIGGER IF EXISTS update_people_display_trigger;'; \ No newline at end of file diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index d258fbcb..1e13a5b3 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -69,12 +69,9 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { @override Future fetchLicenses(bool isNewVersion) async { - log('(A) => license'); try { - log('Obtendo licenças...'); final response = await PhpGroup.getLicense(); final dynamic responseBody = response.jsonBody; - log('Licenças obtidas: $responseBody'); if (response.jsonBody is! List) { late final String error; @@ -100,13 +97,12 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } await Future.wait(saveOperations); - log('() => License stream add'); LicenseRepositoryImpl.license.add(true); _completerController.add(null); return true; - } catch (e) { - log('Erro ao obter licenças: $e'); + } catch (e, s) { + log('Erro ao obter licenças: $e', stackTrace: s); await setupLicense(DatabaseStorage.database, isNewVersion); return false; } diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 29264dd3..38415aa9 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -7,7 +7,7 @@ import 'dart:developer'; class DatabaseStorage { static final String _dbName = 'database.db'; - static final int _dbVersion = 3; + static final int _dbVersion = 4; static final DatabaseStorage instance = DatabaseStorage._internal(); factory DatabaseStorage() => instance; @@ -56,10 +56,16 @@ class DatabaseStorage { if (oldVersion < 3 && newVersion >= 3) { await database.execute(updateDisplayTrigger); } + if (oldVersion < 4 && newVersion >= 4) { + await database.execute(updatePeopleDisplayTrigger); + } } Future _onDowngrade(Database database, int oldVersion, int newVersion) async { log('Downgrading database from version $oldVersion to $newVersion...'); + if (oldVersion >= 4 && newVersion < 4) { + await database.execute(dropPeopleDisplayTrigger); + } if (oldVersion >= 3 && newVersion < 3) { await database.execute(dropDisplayTrigger); } diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index f89c5394..458c1e20 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:hub/shared/constants/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:sqflite/sqflite.dart'; @@ -11,19 +12,7 @@ class KeychainHelper implements BaseStorage { bool _isInitialized = false; - static const String tableKeychain = 'keychain'; - static String get createKeychainTable => ''' - CREATE TABLE $tableKeychain ( - key TEXT UNIQUE, - value TEXT, - type TEXT, - updateAt TEXT, - resolvedAt TEXT, - createdAt TEXT - ); - '''; - static String get deleteKeychainTable => 'DROP TABLE IF EXISTS $tableKeychain;'; @override Future init() async { @@ -67,4 +56,6 @@ class KeychainHelper implements BaseStorage { Future clearAll() async { await DatabaseStorage.database.delete(tableKeychain); } + + } From 39afcc91ef26511cae98568ba3f31c5b75dfe6df Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 2 Dec 2024 09:39:54 -0300 Subject: [PATCH 26/75] WIP --- .../message_well_component_model.dart | 72 +- .../message_well_component_widget.dart | 710 +++++++++--------- .../provisional_schedule_template_model.dart | 1 - ...earch_modal_template_component_widget.dart | 1 - lib/main.dart | 3 +- lib/pages/pets_page/pets_page_model.dart | 3 - .../preferences_settings_model.dart | 1 - .../reception_page/reception_page_widget.dart | 2 - .../license_local_data_source.dart | 3 - .../license_remote_data_source.dart | 1 - .../helpers/storage/keychain_storage.dart | 1 - .../services/deeplink/deep_link_service.dart | 2 - pubspec.lock | 180 +---- pubspec.yaml | 20 +- 14 files changed, 428 insertions(+), 572 deletions(-) diff --git a/lib/components/organism_components/message_well_component/message_well_component_model.dart b/lib/components/organism_components/message_well_component/message_well_component_model.dart index d18746ee..cf2a7682 100644 --- a/lib/components/organism_components/message_well_component/message_well_component_model.dart +++ b/lib/components/organism_components/message_well_component/message_well_component_model.dart @@ -1,44 +1,44 @@ -import 'package:hub/backend/api_requests/api_manager.dart'; -import 'package:hub/flutter_flow/request_manager.dart'; +// import 'package:hub/backend/api_requests/api_manager.dart'; +// import 'package:hub/flutter_flow/request_manager.dart'; -import '/flutter_flow/flutter_flow_util.dart'; -import 'message_well_component_widget.dart' show MessageWellComponentWidget; -import 'package:flutter/material.dart'; +// import '/flutter_flow/flutter_flow_util.dart'; +// import 'message_well_component_widget.dart' show MessageWellComponentWidget; +// import 'package:flutter/material.dart'; -class MessageWellComponentModel extends FlutterFlowModel { - final unfocusNode = FocusNode(); - // State field(s) for TextField widget. - FocusNode? textFieldFocusNode; - TextEditingController? textController; - String? Function(BuildContext, String?)? textControllerValidator; +// class MessageWellComponentModel extends FlutterFlowModel { +// final unfocusNode = FocusNode(); +// // State field(s) for TextField widget. +// FocusNode? textFieldFocusNode; +// TextEditingController? textController; +// String? Function(BuildContext, String?)? textControllerValidator; - /// Query cache managers for this widget. +// /// Query cache managers for this widget. - final _getLiberationsManager = StreamRequestManager(); - Stream getLiberations({ - String? uniqueQueryKey, - bool? overrideCache, - required Stream Function() requestFn, - }) => - _getLiberationsManager.performRequest( - uniqueQueryKey: uniqueQueryKey, - overrideCache: overrideCache, - requestFn: requestFn, - ); - void clearGetLiberationsCache() => _getLiberationsManager.clear(); - void clearGetLiberationsCacheKey(String? uniqueKey) => _getLiberationsManager.clearRequest(uniqueKey); +// final _getLiberationsManager = StreamRequestManager(); +// Stream getLiberations({ +// String? uniqueQueryKey, +// bool? overrideCache, +// required Stream Function() requestFn, +// }) => +// _getLiberationsManager.performRequest( +// uniqueQueryKey: uniqueQueryKey, +// overrideCache: overrideCache, +// requestFn: requestFn, +// ); +// void clearGetLiberationsCache() => _getLiberationsManager.clear(); +// void clearGetLiberationsCacheKey(String? uniqueKey) => _getLiberationsManager.clearRequest(uniqueKey); - @override - void initState(BuildContext context) {} +// @override +// void initState(BuildContext context) {} - @override - void dispose() { - unfocusNode.dispose(); - textFieldFocusNode?.dispose(); - textController?.dispose(); +// @override +// void dispose() { +// unfocusNode.dispose(); +// textFieldFocusNode?.dispose(); +// textController?.dispose(); - /// Dispose query cache managers for this widget. +// /// Dispose query cache managers for this widget. - clearGetLiberationsCache(); - } -} +// clearGetLiberationsCache(); +// } +// } 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 97b52e31..d4b93fc9 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 @@ -1,379 +1,379 @@ -import 'dart:async'; -import 'dart:collection'; +// import 'dart:async'; +// import 'dart:collection'; -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:provider/provider.dart'; -import 'package:rxdart/rxdart.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_riverpod/flutter_riverpod.dart'; +// import 'package:hub/backend/api_requests/api_calls.dart'; +// import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +// import 'package:hub/flutter_flow/flutter_flow_util.dart'; +// import 'package:provider/provider.dart'; +// import 'package:rxdart/rxdart.dart'; -// +// // -final dropdown = BehaviorSubject>.seeded( - LinkedHashMap.from({ - 'All': 'A', - }), -); +// final dropdown = BehaviorSubject>.seeded( +// LinkedHashMap.from({ +// 'All': 'A', +// }), +// ); -class MessageWellComponentWidget extends StatefulWidget { - const MessageWellComponentWidget({super.key}); +// class MessageWellComponentWidget extends StatefulWidget { +// const MessageWellComponentWidget({super.key}); - @override - State createState() => _MessageWellComponentWidgetState(); -} +// @override +// State createState() => _MessageWellComponentWidgetState(); +// } -class _MessageWellComponentWidgetState extends State { - StreamSubscription? _dropdownSubscription; +// class _MessageWellComponentWidgetState extends State { +// StreamSubscription? _dropdownSubscription; - @override - void initState() { - super.initState(); - WidgetsBinding.instance.addPostFrameCallback((_) { - context.read().fetchMessages(); - }); +// @override +// void initState() { +// super.initState(); +// WidgetsBinding.instance.addPostFrameCallback((_) { +// context.read().fetchMessages(); +// }); - _dropdownSubscription = dropdown.stream.listen((_) { - context.read().fetchMessages(); - }); - } +// _dropdownSubscription = dropdown.stream.listen((_) { +// context.read().fetchMessages(); +// }); +// } - @override - void dispose() { - _dropdownSubscription?.cancel(); - super.dispose(); - } +// @override +// void dispose() { +// _dropdownSubscription?.cancel(); +// super.dispose(); +// } - @override - Widget build(BuildContext context) { - final messages = context.read().getMessages(); - return Align( - alignment: Alignment.center, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 40.0), - child: SizedBox( - height: MediaQuery.of(context).size.height * 0.8, - child: Column( - children: [ - _buildHandleMessageWell(context, FlutterFlowTheme.of(context)), - _buildMenuMessageWell(context, FlutterFlowTheme.of(context)), - Expanded( - child: ListView.builder( - itemCount: messages.length, - shrinkWrap: true, - physics: const AlwaysScrollableScrollPhysics(), - itemBuilder: (context, index) { - var message = messages[index]; - return _buildMessageItem(context, message, index); - }, - ), - ), - ], - ), - ), - ), - ); - } +// @override +// Widget build(BuildContext context) { +// final messages = context.read().getMessages(); +// return Align( +// alignment: Alignment.center, +// child: Padding( +// padding: const EdgeInsets.symmetric(vertical: 40.0), +// child: SizedBox( +// height: MediaQuery.of(context).size.height * 0.8, +// child: Column( +// children: [ +// _buildHandleMessageWell(context, FlutterFlowTheme.of(context)), +// _buildMenuMessageWell(context, FlutterFlowTheme.of(context)), +// Expanded( +// child: ListView.builder( +// itemCount: messages.length, +// shrinkWrap: true, +// physics: const AlwaysScrollableScrollPhysics(), +// itemBuilder: (context, index) { +// var message = messages[index]; +// return _buildMessageItem(context, message, index); +// }, +// ), +// ), +// ], +// ), +// ), +// ), +// ); +// } - Widget _buildMenuMessageWell(BuildContext context, FlutterFlowTheme theme) { - final dropdownItems = LinkedHashMap.from({ - 'All': 'A', - 'Personal': 'O', - 'Global': 'C', - }); - return SizedBox( - key: UniqueKey(), - width: 200, - height: 40, - child: StreamBuilder( - stream: dropdown.stream.map((event) => event.keys.first), - builder: (context, snapshot) { - final value = snapshot.data; - return DropdownButtonFormField( - value: value, - decoration: InputDecoration( - isDense: true, - contentPadding: const EdgeInsets.symmetric(horizontal: 10.0), - errorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: theme.error, - width: 2, - ), - borderRadius: BorderRadius.circular(10), - ), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: theme.primary, - width: 2, - ), - borderRadius: BorderRadius.circular(10), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: theme.primary, - width: 2, - ), - borderRadius: BorderRadius.circular(10), - ), - disabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: theme.primary, - width: 2, - ), - borderRadius: BorderRadius.circular(10), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: theme.error, - width: 2, - ), - borderRadius: BorderRadius.circular(10), - ), - border: OutlineInputBorder( - borderSide: BorderSide( - color: theme.primary, - width: 2, - ), - borderRadius: BorderRadius.circular(10), - ), - filled: true, - fillColor: theme.primary, - ), - onChanged: (String? newValue) { - safeSetState(() => dropdown.value = LinkedHashMap.from({newValue!: dropdownItems[newValue].toString()})); - }, - items: dropdownItems.entries - .map((entry) => DropdownMenuItem( - value: entry.key, - child: Text(entry.key), - )) - .toList(), - style: theme.bodyMedium.copyWith( - color: theme.primaryText, - ), - ); - }, - ), - ); - } +// Widget _buildMenuMessageWell(BuildContext context, FlutterFlowTheme theme) { +// final dropdownItems = LinkedHashMap.from({ +// 'All': 'A', +// 'Personal': 'O', +// 'Global': 'C', +// }); +// return SizedBox( +// key: UniqueKey(), +// width: 200, +// height: 40, +// child: StreamBuilder( +// stream: dropdown.stream.map((event) => event.keys.first), +// builder: (context, snapshot) { +// final value = snapshot.data; +// return DropdownButtonFormField( +// value: value, +// decoration: InputDecoration( +// isDense: true, +// contentPadding: const EdgeInsets.symmetric(horizontal: 10.0), +// errorBorder: OutlineInputBorder( +// borderSide: BorderSide( +// color: theme.error, +// width: 2, +// ), +// borderRadius: BorderRadius.circular(10), +// ), +// enabledBorder: OutlineInputBorder( +// borderSide: BorderSide( +// color: theme.primary, +// width: 2, +// ), +// borderRadius: BorderRadius.circular(10), +// ), +// focusedBorder: OutlineInputBorder( +// borderSide: BorderSide( +// color: theme.primary, +// width: 2, +// ), +// borderRadius: BorderRadius.circular(10), +// ), +// disabledBorder: OutlineInputBorder( +// borderSide: BorderSide( +// color: theme.primary, +// width: 2, +// ), +// borderRadius: BorderRadius.circular(10), +// ), +// focusedErrorBorder: OutlineInputBorder( +// borderSide: BorderSide( +// color: theme.error, +// width: 2, +// ), +// borderRadius: BorderRadius.circular(10), +// ), +// border: OutlineInputBorder( +// borderSide: BorderSide( +// color: theme.primary, +// width: 2, +// ), +// borderRadius: BorderRadius.circular(10), +// ), +// filled: true, +// fillColor: theme.primary, +// ), +// onChanged: (String? newValue) { +// safeSetState(() => dropdown.value = LinkedHashMap.from({newValue!: dropdownItems[newValue].toString()})); +// }, +// items: dropdownItems.entries +// .map((entry) => DropdownMenuItem( +// value: entry.key, +// child: Text(entry.key), +// )) +// .toList(), +// style: theme.bodyMedium.copyWith( +// color: theme.primaryText, +// ), +// ); +// }, +// ), +// ); +// } - Text _buildHandleMessageWell(BuildContext context, FlutterFlowTheme theme) { - return Text( - FFLocalizations.of(context).getVariableText( - ptText: 'Mural de Mensagens', - enText: 'Message Wall', - ), - style: theme.bodyMedium.copyWith( - fontFamily: 'Nunito Sans', - letterSpacing: 0.0, - ), - ); - } +// Text _buildHandleMessageWell(BuildContext context, FlutterFlowTheme theme) { +// return Text( +// FFLocalizations.of(context).getVariableText( +// ptText: 'Mural de Mensagens', +// enText: 'Message Wall', +// ), +// style: theme.bodyMedium.copyWith( +// fontFamily: 'Nunito Sans', +// letterSpacing: 0.0, +// ), +// ); +// } - Widget _buildMessageItem(BuildContext context, dynamic message, int index) { - FlutterFlowTheme.of(context); - String formatMessageOrigin(String messageOrigin) { - final words = messageOrigin.split(' '); - final formattedWords = words.map((word) { - if (word.isEmpty) return word; // Handle empty words - final firstLetter = word.substring(0, 1).toUpperCase(); - final remainingLetters = word.length > 1 ? word.substring(1).toLowerCase() : ''; - return '$firstLetter$remainingLetters'; - }); - return formattedWords.join(' '); - } +// Widget _buildMessageItem(BuildContext context, dynamic message, int index) { +// FlutterFlowTheme.of(context); +// String formatMessageOrigin(String messageOrigin) { +// final words = messageOrigin.split(' '); +// final formattedWords = words.map((word) { +// if (word.isEmpty) return word; // Handle empty words +// final firstLetter = word.substring(0, 1).toUpperCase(); +// final remainingLetters = word.length > 1 ? word.substring(1).toLowerCase() : ''; +// return '$firstLetter$remainingLetters'; +// }); +// return formattedWords.join(' '); +// } - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 30), - child: Card( - color: FlutterFlowTheme.of(context).primaryBackground, - child: Container( - // height: 100, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 15.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Icon( - message['MSG_DESTINO_TP'] == 'T' - ? Icons.language - : message['MSG_DESTINO_TP'] == 'P' - ? Icons.person - : Icons.home, - color: FlutterFlowTheme.of(context).primary, - size: 25, - ), - Expanded( - child: Text( - message['MSG_ORIGEM_DESC'].toString(), - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 15, - color: FlutterFlowTheme.of(context).primary, - ), - overflow: TextOverflow.fade, - ), - ), - ].divide(const SizedBox(width: 10)), - ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Padding( - padding: const EdgeInsets.only(left: 5), - child: Icon( - Icons.history, - color: FlutterFlowTheme.of(context).customColor6, - size: 15, - ), - ), - Expanded( - child: Text( - message['MSG_DATE'].toString(), - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 10, - color: FlutterFlowTheme.of(context).customColor6, - ), - overflow: TextOverflow.ellipsis, - ), - ), - ].divide(const SizedBox(width: 15)), - ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Padding( - padding: const EdgeInsets.only(left: 5), - child: Icon( - Icons.message, - color: FlutterFlowTheme.of(context).customColor6, - size: 15, - ), - ), - Expanded( - child: Text( - message['MSG_TEXTO'].toString(), - ), - ), - ].divide(const SizedBox(width: 15)), - ), - ].divide(const SizedBox(height: 4)), - ), - ), - // Row( - // children: [ - // Icon( - // Icons.message, - // color: FlutterFlowTheme.of(context).customColor6, - // size: 15, - // ), - // Expanded( - // child: Padding( - // padding: const EdgeInsets.all(8.0), - // child: Text( - // message['MSG_TEXTO'].toString(), - // ), - // ), - // ), - // ] - // .addToStart(const SizedBox(width: 8)) - // .addToEnd(const SizedBox(width: 8))), - ].divide( - const SizedBox(height: 8), - ), - ), - ), - ), - )); - } -} +// return Padding( +// padding: const EdgeInsets.symmetric(horizontal: 30), +// child: Card( +// color: FlutterFlowTheme.of(context).primaryBackground, +// child: Container( +// // height: 100, +// child: Padding( +// padding: const EdgeInsets.all(8.0), +// child: Column( +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// Padding( +// padding: const EdgeInsets.symmetric(horizontal: 15.0), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// Row( +// mainAxisAlignment: MainAxisAlignment.start, +// mainAxisSize: MainAxisSize.max, +// children: [ +// Icon( +// message['MSG_DESTINO_TP'] == 'T' +// ? Icons.language +// : message['MSG_DESTINO_TP'] == 'P' +// ? Icons.person +// : Icons.home, +// color: FlutterFlowTheme.of(context).primary, +// size: 25, +// ), +// Expanded( +// child: Text( +// message['MSG_ORIGEM_DESC'].toString(), +// style: TextStyle( +// fontWeight: FontWeight.bold, +// fontSize: 15, +// color: FlutterFlowTheme.of(context).primary, +// ), +// overflow: TextOverflow.fade, +// ), +// ), +// ].divide(const SizedBox(width: 10)), +// ), +// Row( +// mainAxisAlignment: MainAxisAlignment.start, +// mainAxisSize: MainAxisSize.max, +// children: [ +// Padding( +// padding: const EdgeInsets.only(left: 5), +// child: Icon( +// Icons.history, +// color: FlutterFlowTheme.of(context).customColor6, +// size: 15, +// ), +// ), +// Expanded( +// child: Text( +// message['MSG_DATE'].toString(), +// style: TextStyle( +// fontWeight: FontWeight.bold, +// fontSize: 10, +// color: FlutterFlowTheme.of(context).customColor6, +// ), +// overflow: TextOverflow.ellipsis, +// ), +// ), +// ].divide(const SizedBox(width: 15)), +// ), +// Row( +// mainAxisAlignment: MainAxisAlignment.start, +// mainAxisSize: MainAxisSize.max, +// children: [ +// Padding( +// padding: const EdgeInsets.only(left: 5), +// child: Icon( +// Icons.message, +// color: FlutterFlowTheme.of(context).customColor6, +// size: 15, +// ), +// ), +// Expanded( +// child: Text( +// message['MSG_TEXTO'].toString(), +// ), +// ), +// ].divide(const SizedBox(width: 15)), +// ), +// ].divide(const SizedBox(height: 4)), +// ), +// ), +// // Row( +// // children: [ +// // Icon( +// // Icons.message, +// // color: FlutterFlowTheme.of(context).customColor6, +// // size: 15, +// // ), +// // Expanded( +// // child: Padding( +// // padding: const EdgeInsets.all(8.0), +// // child: Text( +// // message['MSG_TEXTO'].toString(), +// // ), +// // ), +// // ), +// // ] +// // .addToStart(const SizedBox(width: 8)) +// // .addToEnd(const SizedBox(width: 8))), +// ].divide( +// const SizedBox(height: 8), +// ), +// ), +// ), +// ), +// )); +// } +// } -class MessageWellState { - final List messages; - int pageNumber; - final bool allowScrollInSingleChildScrollView; +// class MessageWellState { +// final List messages; +// int pageNumber; +// final bool allowScrollInSingleChildScrollView; - MessageWellState({ - required this.messages, - this.pageNumber = 1, - required this.allowScrollInSingleChildScrollView, - }); +// MessageWellState({ +// required this.messages, +// this.pageNumber = 1, +// required this.allowScrollInSingleChildScrollView, +// }); - MessageWellState copyWith({ - List? messages, - int? pageNumber, - bool? allowScrollInSingleChildScrollView, - }) { - return MessageWellState( - messages: messages ?? this.messages, - pageNumber: pageNumber ?? this.pageNumber, - allowScrollInSingleChildScrollView: allowScrollInSingleChildScrollView ?? this.allowScrollInSingleChildScrollView, - ); - } -} +// MessageWellState copyWith({ +// List? messages, +// int? pageNumber, +// bool? allowScrollInSingleChildScrollView, +// }) { +// return MessageWellState( +// messages: messages ?? this.messages, +// pageNumber: pageNumber ?? this.pageNumber, +// allowScrollInSingleChildScrollView: allowScrollInSingleChildScrollView ?? this.allowScrollInSingleChildScrollView, +// ); +// } +// } -class MessageWellNotifier extends StateNotifier { - var _totalPageNumber = 1; - int get totalPageNumber => _totalPageNumber; +// class MessageWellNotifier extends StateNotifier { +// var _totalPageNumber = 1; +// int get totalPageNumber => _totalPageNumber; - set totalPageNumber(int value) { - _totalPageNumber = value; - } +// set totalPageNumber(int value) { +// _totalPageNumber = value; +// } - MessageWellNotifier() - : super(MessageWellState( - messages: [], - allowScrollInSingleChildScrollView: true, - )) { - fetchMessages(); - } +// MessageWellNotifier() +// : super(MessageWellState( +// messages: [], +// allowScrollInSingleChildScrollView: true, +// )) { +// fetchMessages(); +// } - void fetchMessages() async { - if (state.pageNumber <= totalPageNumber) { - var apiCall = GetMessagesCall(); - var response = await apiCall.call( - pageSize: '100', - pageNumber: state.pageNumber.toString(), - tipoDestino: dropdown.value.values.first, - ); - if (response.statusCode == 200) { - var messagesData = response.jsonBody['mensagens']; - var newMessages = [...state.messages, ...messagesData]; - state = state.copyWith(messages: newMessages); - // var rExp = RegExp(r'\d+') - // .allMatches(newMessages.toString()) - // .map((e) => e.group(0)) - // .toList(); - // Provider.of(context, listen: false).setCounter(int.parse(response.jsonBody['total_pages'])); - // totalPageNumber = int.parse(response.jsonBody['total_pages']); - } else {} - } else {} - } +// void fetchMessages() async { +// if (state.pageNumber <= totalPageNumber) { +// var apiCall = GetMessagesCall(); +// var response = await apiCall.call( +// pageSize: '100', +// pageNumber: state.pageNumber.toString(), +// tipoDestino: dropdown.value.values.first, +// ); +// if (response.statusCode == 200) { +// var messagesData = response.jsonBody['mensagens']; +// var newMessages = [...state.messages, ...messagesData]; +// state = state.copyWith(messages: newMessages); +// // var rExp = RegExp(r'\d+') +// // .allMatches(newMessages.toString()) +// // .map((e) => e.group(0)) +// // .toList(); +// // Provider.of(context, listen: false).setCounter(int.parse(response.jsonBody['total_pages'])); +// // totalPageNumber = int.parse(response.jsonBody['total_pages']); +// } else {} +// } else {} +// } - List getMessages() { - return state.messages; - } +// List getMessages() { +// return state.messages; +// } - void incrementPageNumber() { - if (state.pageNumber <= totalPageNumber) { - state = state.copyWith(pageNumber: state.pageNumber + 1); - } - } -} +// void incrementPageNumber() { +// if (state.pageNumber <= totalPageNumber) { +// state = state.copyWith(pageNumber: state.pageNumber + 1); +// } +// } +// } -final messageWellProvider = StateNotifierProvider((ref) { - return MessageWellNotifier(); -}); +// final messageWellProvider = StateNotifierProvider((ref) { +// return MessageWellNotifier(); +// }); 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 b57237ad..4f8bd82e 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 @@ -58,7 +58,6 @@ class ScheduleProvisionalVisitPageModel extends FlutterFlowModel sendVisitors(BuildContext context) async { await widget.getVisitors?.call(_model.visitors); - log('() => docs: ${_model.docs}'); await widget.getDocs?.call(_model.docs); context.pop(); } diff --git a/lib/main.dart b/lib/main.dart index 1053f9bd..c747270d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,7 +15,6 @@ import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; import 'package:responsive_framework/responsive_framework.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'backend/notifications/firebase_messaging_service.dart'; import 'initialization.dart'; @@ -24,7 +23,7 @@ final GlobalKey navigatorKey = GlobalKey(); void main() async { await initializeApp(); - runApp(const ProviderScope(child: App())); + runApp(const App()); FirebaseMessaging.onBackgroundMessage(_backgroundHandlerMessage); } diff --git a/lib/pages/pets_page/pets_page_model.dart b/lib/pages/pets_page/pets_page_model.dart index 4d4fd096..21f74d62 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -116,10 +116,8 @@ class PetsPageModel extends FlutterFlowModel { ); dropDownValueController1 = FormFieldController(dropDownValue1 ??= defaultDropDownText); dropDownValueController2 = FormFieldController(dropDownValue2 ??= defaultDropDownText); - log('() => ): $devUUID'); safeSetState?.call(); - log('() => ): $devUUID'); } @override @@ -157,7 +155,6 @@ class PetsPageModel extends FlutterFlowModel { } void setEditForm() { - log('item: $item'); if (item != null) petId = item['id']; diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index d5edb91f..734a8f92 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -79,7 +79,6 @@ class PreferencesPageModel with ChangeNotifier { } }) .catchError((e, s) { - log('toggleNotify', error: e, stackTrace: s); content = FFLocalizations.of(context).getVariableText( enText: 'Error changing notification', ptText: 'Erro ao alterar notificação', diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 2da2e1e8..3891122c 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -30,7 +30,6 @@ class _ReceptionPageWidgetState extends State with WidgetsB WidgetsBinding.instance.addObserver(this); () async { final lifecycle = await AwesomeNotifications().getAppLifeCycle(); - log('lifecycle: $lifecycle'); }(); FirebaseMessagingService().updateDeviceToken(); @@ -45,7 +44,6 @@ class _ReceptionPageWidgetState extends State with WidgetsB @override void didChangeAppLifecycleState(AppLifecycleState state) { - log('() => state: $state'); if (state == AppLifecycleState.resumed) { setState(() { LocalsRepositoryImpl().checkLocals(context); diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 01a71a31..13000803 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -29,7 +29,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { if (key.isEmpty) return; for (var element in key) { if (element != null) { - log('setByKey($element, $display)'); await s(element, { 'display': display, 'expirationDate': '', @@ -45,7 +44,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { if (response.isEmpty) { return false; } - log('isNewVersion(): ${response.first['display']}'); return response.first['display'] == 'true'; } @@ -58,7 +56,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { } Future s(String key, T value) async { - log('setLicense($key, $value)'); value as Map; await DatabaseStorage.database.insert( diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 1e13a5b3..6411e35c 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -118,7 +118,6 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { static Future _saveModule(final dynamic body) async { if (body is! Map) return; - log('Salvando módulo: ${body.toString()}'); await LicenseLocalDataSourceImpl().s(body['key'], body); } } diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index 458c1e20..ec1f6e80 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -23,7 +23,6 @@ class KeychainHelper implements BaseStorage { @override Future get(String key) async { - log('KeychainHelper.get: $key'); var response = await DatabaseStorage.database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; diff --git a/lib/shared/services/deeplink/deep_link_service.dart b/lib/shared/services/deeplink/deep_link_service.dart index 3bc1b4c4..5df6ff67 100644 --- a/lib/shared/services/deeplink/deep_link_service.dart +++ b/lib/shared/services/deeplink/deep_link_service.dart @@ -49,7 +49,6 @@ class DeepLinkService { } } catch (e, s) { print('Error handling deep link: $e, $s'); - log('Error handling', error: e, stackTrace: s); } } @@ -74,7 +73,6 @@ class DeepLinkService { }); } catch (e, s) { print('Error showing forgot password screen: $e, $s'); - log('Error handling', error: e, stackTrace: s); } } diff --git a/pubspec.lock b/pubspec.lock index 64d4e4b8..554f2649 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -230,46 +230,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" - camera: - dependency: "direct main" - description: - name: camera - sha256: "26ff41045772153f222ffffecba711a206f670f5834d40ebf5eed3811692f167" - url: "https://pub.dev" - source: hosted - version: "0.11.0+2" - camera_android_camerax: - dependency: transitive - description: - name: camera_android_camerax - sha256: e3627fdc2132d89212b8a8676679f5b07008c7e3d8ae00cea775c3397f9e742b - url: "https://pub.dev" - source: hosted - version: "0.6.10" - camera_avfoundation: - dependency: transitive - description: - name: camera_avfoundation - sha256: "2e4c568f70e406ccb87376bc06b53d2f5bebaab71e2fbcc1a950e31449381bcf" - url: "https://pub.dev" - source: hosted - version: "0.9.17+5" - camera_platform_interface: - dependency: transitive - description: - name: camera_platform_interface - sha256: b3ede1f171532e0d83111fe0980b46d17f1aa9788a07a2fbed07366bbdbb9061 - url: "https://pub.dev" - source: hosted - version: "2.8.0" - camera_web: - dependency: transitive - description: - name: camera_web - sha256: "595f28c89d1fb62d77c73c633193755b781c6d2e0ebcd8dc25b763b514e6ba8f" - url: "https://pub.dev" - source: hosted - version: "0.3.5" characters: dependency: transitive description: @@ -318,22 +278,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" - connectivity_plus: - dependency: "direct main" - description: - name: connectivity_plus - sha256: "876849631b0c7dc20f8b471a2a03142841b482438e3b707955464f5ffca3e4c3" - url: "https://pub.dev" - source: hosted - version: "6.1.0" - connectivity_plus_platform_interface: - dependency: transitive - description: - name: connectivity_plus_platform_interface - sha256: "42657c1715d48b167930d5f34d00222ac100475f73d10162ddf43e714932f204" - url: "https://pub.dev" - source: hosted - version: "2.0.1" convert: dependency: transitive description: @@ -342,14 +286,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.2" - crop_your_image: - dependency: "direct main" - description: - name: crop_your_image - sha256: "9ae3b33042de5bda5321fc48aad41054c196bf2cc28350cd30cb8a85c1a7b1bd" - url: "https://pub.dev" - source: hosted - version: "1.1.0" cross_file: dependency: transitive description: @@ -359,7 +295,7 @@ packages: source: hosted version: "0.3.4+2" crypto: - dependency: "direct main" + dependency: transitive description: name: crypto sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" @@ -390,14 +326,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.7" - dbus: - dependency: transitive - description: - name: dbus - sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" - url: "https://pub.dev" - source: hosted - version: "0.7.10" device_info_plus: dependency: "direct main" description: @@ -414,22 +342,6 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.1" - dio: - dependency: "direct main" - description: - name: dio - sha256: "5598aa796bbf4699afd5c67c0f5f6e2ed542afc956884b9cd58c306966efc260" - url: "https://pub.dev" - source: hosted - version: "5.7.0" - dio_web_adapter: - dependency: transitive - description: - name: dio_web_adapter - sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8" - url: "https://pub.dev" - source: hosted - version: "2.0.0" dropdown_button2: dependency: "direct main" description: @@ -450,10 +362,10 @@ packages: dependency: "direct main" description: name: equatable - sha256: b35578f687b79243d39008c44d638474d93e9091e578c970efef41ce0c3fa000 + sha256: "567c64b3cb4cf82397aac55f4f0cbd3ca20d77c6c03bedbc4ceaddc08904aef7" url: "https://pub.dev" source: hosted - version: "2.0.6" + version: "2.0.7" fake_async: dependency: transitive description: @@ -490,10 +402,10 @@ packages: dependency: transitive description: name: file_selector_linux - sha256: b2b91daf8a68ecfa4a01b778a6f52edef9b14ecd506e771488ea0f2e0784198b + sha256: "54cbbd957e1156d29548c7d9b9ec0c0ebb6de0a90452198683a7d23aed617a33" url: "https://pub.dev" source: hosted - version: "0.9.3+1" + version: "0.9.3+2" file_selector_macos: dependency: transitive description: @@ -636,21 +548,13 @@ packages: source: hosted version: "8.1.6" flutter_cache_manager: - dependency: "direct main" + dependency: transitive description: name: flutter_cache_manager sha256: "400b6592f16a4409a7f2bb929a9a7e38c72cceb8ffb99ee57bbf2cb2cecf8386" url: "https://pub.dev" source: hosted version: "3.4.1" - flutter_expandable_fab: - dependency: "direct main" - description: - name: flutter_expandable_fab - sha256: "85275279d19faf4fbe5639dc1f139b4555b150e079d056f085601a45688af12c" - url: "https://pub.dev" - source: hosted - version: "2.3.0" flutter_inappwebview: dependency: "direct main" description: @@ -671,10 +575,10 @@ packages: dependency: transitive description: name: flutter_inappwebview_internal_annotations - sha256: "5f80fd30e208ddded7dbbcd0d569e7995f9f63d45ea3f548d8dd4c0b473fb4c8" + sha256: "787171d43f8af67864740b6f04166c13190aa74a1468a1f1f1e9ee5b90c359cd" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" flutter_inappwebview_ios: dependency: transitive description: @@ -729,21 +633,13 @@ packages: source: sdk version: "0.0.0" flutter_plugin_android_lifecycle: - dependency: "direct main" + dependency: transitive description: name: flutter_plugin_android_lifecycle sha256: "9b78450b89f059e96c9ebb355fa6b3df1d6b330436e0b885fb49594c41721398" url: "https://pub.dev" source: hosted version: "2.0.23" - flutter_riverpod: - dependency: "direct main" - description: - name: flutter_riverpod - sha256: "9532ee6db4a943a1ed8383072a2e3eeda041db5657cdf6d2acecf3c21ecbe7e1" - url: "https://pub.dev" - source: hosted - version: "2.6.1" flutter_secure_storage: dependency: "direct main" description: @@ -820,10 +716,10 @@ packages: dependency: "direct main" description: name: flutter_svg - sha256: "936d9c1c010d3e234d1672574636f3352b4941ca3decaddd3cafaeb9ad49c471" + sha256: "54900a1a1243f3c4a5506d853a2b5c2dbc38d5f27e52a52618a8054401431123" url: "https://pub.dev" source: hosted - version: "2.0.15" + version: "2.0.16" flutter_test: dependency: "direct dev" description: flutter @@ -894,10 +790,10 @@ packages: dependency: "direct main" description: name: go_router - sha256: "8ae664a70174163b9f65ea68dd8673e29db8f9095de7b5cd00e167c621f4fef5" + sha256: "8660b74171fafae4aa8202100fa2e55349e078281dadc73a241eb8e758534d9d" url: "https://pub.dev" source: hosted - version: "14.6.0" + version: "14.6.1" google_fonts: dependency: "direct main" description: @@ -982,10 +878,10 @@ packages: dependency: "direct main" description: name: image_picker_android - sha256: "8faba09ba361d4b246dc0a17cb4289b3324c2b9f6db7b3d457ee69106a86bd32" + sha256: fa8141602fde3f7e2f81dbf043613eb44dfa325fa0bcf93c0f142c9f7a2c193e url: "https://pub.dev" source: hosted - version: "0.8.12+17" + version: "0.8.12+18" image_picker_for_web: dependency: "direct main" description: @@ -1067,7 +963,7 @@ packages: source: hosted version: "0.6.7" json_annotation: - dependency: "direct main" + dependency: transitive description: name: json_annotation sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" @@ -1198,10 +1094,10 @@ packages: dependency: "direct main" description: name: material_symbols_icons - sha256: "1dea2aef1c83434f832f14341a5ffa1254e76b68e4d90333f95f8a2643bf1024" + sha256: a783133f87c58e10b1cc19797f7c3192ff9c2bab301c4ade90312d8f2aed01b2 url: "https://pub.dev" source: hosted - version: "4.2799.0" + version: "4.2800.2" maybe_just_nothing: dependency: transitive description: @@ -1242,14 +1138,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" - nm: - dependency: transitive - description: - name: nm - sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254" - url: "https://pub.dev" - source: hosted - version: "0.5.0" octo_image: dependency: transitive description: @@ -1302,10 +1190,10 @@ packages: dependency: "direct main" description: name: path_provider_android - sha256: c464428172cb986b758c6d1724c603097febb8fb855aa265aeecc9280c294d4a + sha256: "8c4967f8b7cb46dc914e178daa29813d83ae502e0529d7b0478330616a691ef7" url: "https://pub.dev" source: hosted - version: "2.2.12" + version: "2.2.14" path_provider_foundation: dependency: "direct main" description: @@ -1342,10 +1230,10 @@ packages: dependency: "direct main" description: name: percent_indicator - sha256: c37099ad833a883c9d71782321cb65c3a848c21b6939b6185f0ff6640d05814c + sha256: "0d77d5c6fa9b7f60202cedf748b568ba9ba38d3f30405d6ceae4da76f5185462" url: "https://pub.dev" source: hosted - version: "4.2.3" + version: "4.2.4" permission_handler: dependency: "direct main" description: @@ -1490,14 +1378,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" - riverpod: - dependency: transitive - description: - name: riverpod - sha256: "59062512288d3056b2321804332a13ffdd1bf16df70dcc8e506e411280a72959" - url: "https://pub.dev" - source: hosted - version: "2.6.1" rxdart: dependency: "direct main" description: @@ -1679,14 +1559,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.1" - state_notifier: - dependency: transitive - description: - name: state_notifier - sha256: b8677376aa54f2d7c58280d5a007f9e8774f1968d1fb1c096adcb4792fba29bb - url: "https://pub.dev" - source: hosted - version: "1.0.0" stream_channel: dependency: transitive description: @@ -1851,10 +1723,10 @@ packages: dependency: transitive description: name: vector_graphics_compiler - sha256: ab9ff38fc771e9ee1139320adbe3d18a60327370c218c60752068ebee4b49ab1 + sha256: "1b4b9e706a10294258727674a340ae0d6e64a7231980f9f9a3d12e4b42407aad" url: "https://pub.dev" source: hosted - version: "1.1.15" + version: "1.1.16" vector_math: dependency: transitive description: @@ -1931,10 +1803,10 @@ packages: dependency: transitive description: name: webview_flutter_wkwebview - sha256: "3be297aa4ca78205abdd284cf55f168c35246c75b3079990ad8ba9d257681a30" + sha256: b7e92f129482460951d96ef9a46b49db34bd2e1621685de26e9eaafd9674e7eb url: "https://pub.dev" source: hosted - version: "3.16.2" + version: "3.16.3" win32: dependency: "direct overridden" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0f320ee2..becd74ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: rxdart: ^0.28.0 collection: 1.18.0 app_links: ^6.3.2 - crop_your_image: 1.1.0 + # crop_your_image: 1.1.0 csv: 6.0.0 device_info_plus: ^10.1.2 firebase_messaging: ^15.1.0 @@ -30,13 +30,13 @@ dependencies: easy_debounce: 2.0.3 equatable: ^2.0.6 file_picker: ^8.0.7 - flutter_expandable_fab: ^2.1.0 + # flutter_expandable_fab: ^2.1.0 firebase_analytics: ^11.3.0 flutter_animate: 4.5.0 - flutter_cache_manager: ^3.4.1 - flutter_plugin_android_lifecycle: ^2.0.23 + # flutter_cache_manager: ^3.4.1 + # flutter_plugin_android_lifecycle: ^2.0.23 share_plus: ^10.0.0 - connectivity_plus: ^6.0.5 + # connectivity_plus: ^6.0.5 flutter_secure_storage: 9.2.2 flutter_secure_storage_linux: 1.2.1 flutter_secure_storage_macos: 3.1.2 @@ -59,7 +59,7 @@ dependencies: image_picker_platform_interface: 2.10.0 local_auth: ^2.2.0 intl: ^0.19.0 - camera: ^0.11.0+2 + # camera: ^0.11.0+2 json_path: ^0.7.4 mime_type: ^1.0.1 page_transition: 2.1.0 @@ -93,16 +93,16 @@ dependencies: fluttertoast: ^8.2.8 cupertino_icons: ^1.0.0 flutter_bloc: ^8.1.6 - flutter_riverpod: ^2.5.1 + # flutter_riverpod: ^2.5.1 qr_flutter: ^4.1.0 permission_handler: ^11.3.1 firebase_crashlytics: ^4.0.1 awesome_notifications: ^0.10.0 app_tracking_transparency: ^2.0.6 - dio: ^5.7.0 - crypto: ^3.0.5 + # dio: ^5.7.0 + # crypto: ^3.0.5 freezed_annotation: ^2.4.4 - json_annotation: ^4.9.0 + # json_annotation: ^4.9.0 dependency_overrides: http: 1.2.1 From 9a426079fbc3301972fc3ebb4ebf0ba44640946e Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 2 Dec 2024 10:48:53 -0300 Subject: [PATCH 27/75] support oldVersion license processing --- .../home/presentation/pages/home_page.dart | 12 + lib/main.dart | 3 +- .../local_profile/local_profile_widget.dart | 2 + .../presentation/blocs/menu_view_bloc.dart | 6 + .../widgets/menu_entry/drawer_menu_entry.dart | 4 + .../widgets/menu_entry/home_menu_entry.dart | 2 + .../license_remote_data_source.dart | 4 +- .../modules/domain/entities/license.dart | 243 +++++++++++++----- .../authentication_service.dart | 16 +- pubspec.lock | 24 ++ pubspec.yaml | 2 +- 11 files changed, 240 insertions(+), 78 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index cecc978c..8b254a27 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -21,6 +21,18 @@ class HomePageWidget extends StatefulWidget { class _HomePageWidgetState extends State { final scaffoldKey = GlobalKey(); + @override + void initState() { + super.initState(); + _initializePage(); + } + + Future _initializePage() async { + await LocalsRepositoryImpl().processLocals(context).whenComplete(() async { + context.read().add(LocalProfileEvent()); + }); + } + @override Widget build(BuildContext context) { return BlocProvider( diff --git a/lib/main.dart b/lib/main.dart index c747270d..1053f9bd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,6 +15,7 @@ import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; import 'package:responsive_framework/responsive_framework.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'backend/notifications/firebase_messaging_service.dart'; import 'initialization.dart'; @@ -23,7 +24,7 @@ final GlobalKey navigatorKey = GlobalKey(); void main() async { await initializeApp(); - runApp(const App()); + runApp(const ProviderScope(child: App())); FirebaseMessaging.onBackgroundMessage(_backgroundHandlerMessage); } diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 9cba14c4..f5523433 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -17,6 +17,8 @@ class LocalProfileComponentWidget extends StatefulWidget { } class _LocalProfileComponentWidgetState extends State { + + @override Widget build(BuildContext context) { return BlocProvider( diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart index c85dd950..fab4e6f0 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart @@ -11,6 +11,7 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/services/authentication/authentication_service.dart'; class MenuViewEvent {} @@ -95,6 +96,11 @@ class MenuViewBloc extends Bloc { try { switch (display) { case 'VISIVEL': + if(opt.value == 'FRE-HUB-LOGOUT') + await addMenuEntry(entries, opt.icon, opt.name, () async { + await AuthenticationService.signOut(navigatorKey.currentContext!); + }); + else await addMenuEntry(entries, opt.icon, opt.name, () async { await nav(opt.route); }); diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart index 373b9b4a..5b86aae6 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart @@ -52,6 +52,10 @@ enum DrawerMenuEntries implements MenuEntry { return 'FRE-HUB-QRCODE'; case DrawerMenuEntries.peopleOnTheProperty: return 'FRE-HUB-PEOPLE'; + case DrawerMenuEntries.settings: + return 'FRE-HUB-SETTINGS'; + case DrawerMenuEntries.logout: + return 'FRE-HUB-LOGOUT'; default: return ''; } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart index 8ab3a975..3915c3d9 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart @@ -51,6 +51,8 @@ enum HomeMenuEntries implements MenuEntry { return 'FRE-HUB-QRCODE'; case HomeMenuEntries.peopleOnTheProperty: return 'FRE-HUB-PEOPLE'; + case HomeMenuEntries.settings: + return 'FRE-HUB-SETTINGS'; default: return ''; } diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 6411e35c..18ca868c 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -38,7 +38,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { @override Future setupLicense(Database database, bool isNewVersion) async { - final License license = License.getLicense(isNewVersion); + final License license = await License.getLicense(isNewVersion); final List inactiveModuleKey = license.modules .where((module) => module.display == ModuleStatus.inactive.key) @@ -113,7 +113,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } static bool licenseContainsKey(final String key) { - return License.mods.contains(key); + return LicenseKeys.values.map((e) => e.value).contains(key); } static Future _saveModule(final dynamic body) async { diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 50f71990..49306773 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -7,6 +7,76 @@ import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'module.dart'; +enum LicenseKeys { + messages, + liberations, + reservations, + access, + openedVisits, + vehicles, + residents, + pets, + orders, + completeSchedule, + providerSchedule, + deliverySchedule, + property, + fastPass, + visitors, + qrCode, + people, + petsHistory, + settings, + logout, +} + +extension LicenseKeysExtension on LicenseKeys { + String get value { + switch (this) { + case LicenseKeys.messages: + return 'FRE-HUB-MESSAGES'; + case LicenseKeys.liberations: + return 'FRE-HUB-LIBERATIONS'; + case LicenseKeys.reservations: + return 'FRE-HUB-RESERVATIONS'; + case LicenseKeys.access: + return 'FRE-HUB-ACCESS'; + case LicenseKeys.openedVisits: + return 'FRE-HUB-OPENED-VISITS'; + case LicenseKeys.vehicles: + return 'FRE-HUB-VEHICLES'; + case LicenseKeys.residents: + return 'FRE-HUB-RESIDENTS'; + case LicenseKeys.pets: + return 'FRE-HUB-PETS'; + case LicenseKeys.orders: + return 'FRE-HUB-ORDERS'; + case LicenseKeys.completeSchedule: + return 'FRE-HUB-COMPLETE-SCHEDULE'; + case LicenseKeys.providerSchedule: + return 'FRE-HUB-AGE-PROV-PRESTADOR'; + case LicenseKeys.deliverySchedule: + return 'FRE-HUB-AGE-PROV-DELIVERY'; + case LicenseKeys.property: + return 'FRE-HUB-PROPERTY'; + case LicenseKeys.fastPass: + return 'FRE-HUB-FASTPASS'; + case LicenseKeys.visitors: + return 'FRE-HUB-VISITORS'; + case LicenseKeys.qrCode: + return 'FRE-HUB-QRCODE'; + case LicenseKeys.people: + return 'FRE-HUB-PEOPLE'; + case LicenseKeys.petsHistory: + return 'FRE-HUB-PETS-HISTORY'; + case LicenseKeys.settings: + return 'FRE-HUB-SETTINGS'; + case LicenseKeys.logout: + return 'FRE-HUB-LOGOUT'; + } + } +} + class License { final List modules; @@ -14,161 +84,208 @@ class License { this.modules, ); - static List mods = [ - 'FRE-HUB-MESSAGES', - 'FRE-HUB-LIBERATIONS', - 'FRE-HUB-RESERVATIONS', - 'FRE-HUB-ACCESS', - 'FRE-HUB-OPENED-VISITS', - 'FRE-HUB-VEHICLES', - 'FRE-HUB-RESIDENTS', - 'FRE-HUB-PETS', - 'FRE-HUB-ORDERS', - 'FRE-HUB-COMPLETE-SCHEDULE', - 'FRE-HUB-AGE-PROV-PRESTADOR', - 'FRE-HUB-AGE-PROV-DELIVERY', - 'FRE-HUB-PROPERTY', - 'FRE-HUB-FASTPASS', - 'FRE-HUB-VISITORS', - 'FRE-HUB-QRCODE', - 'FRE-HUB-PEOPLE', - 'FRE-HUB-PETS-HISTORY' - ]; + // static List mods = [ + // 'FRE-HUB-MESSAGES', + // 'FRE-HUB-LIBERATIONS', + // 'FRE-HUB-RESERVATIONS', + // 'FRE-HUB-ACCESS', + // 'FRE-HUB-OPENED-VISITS', + // 'FRE-HUB-VEHICLES', + // 'FRE-HUB-RESIDENTS', + // 'FRE-HUB-PETS', + // 'FRE-HUB-ORDERS', + // 'FRE-HUB-COMPLETE-SCHEDULE', + // 'FRE-HUB-AGE-PROV-PRESTADOR', + // 'FRE-HUB-AGE-PROV-DELIVERY', + // 'FRE-HUB-PROPERTY', + // 'FRE-HUB-FASTPASS', + // 'FRE-HUB-VISITORS', + // 'FRE-HUB-QRCODE', + // 'FRE-HUB-PEOPLE', + // 'FRE-HUB-PETS-HISTORY' + // 'FRE-HUB-SETTINGS', + // 'FRE-HUB-LOGOUT', + // ]; - void processOldVersion() async { - final bool whatsapp = await StorageHelper().g(KeychainStorageKey.whatsapp as String).then((v) => v.toBoolean()); - final bool provisional = await StorageHelper().g(KeychainStorageKey.provisional as String).then((v) => v.toBoolean()); - final bool pets = await StorageHelper().g(KeychainStorageKey.pets as String).then((v) => v.toBoolean()); + static Future _proceessOldVersion(LicenseKeys key) async { + switch(key) { + case LicenseKeys.fastPass: + return await _precessWpp(); + case LicenseKeys.providerSchedule: + return await _processProvisional(); + case LicenseKeys.deliverySchedule: + return await _processProvisional(); + case LicenseKeys.pets: + return await _processPets(); + case LicenseKeys.petsHistory: + return await _processPets(); + default: + return ModuleStatus.active.key; + } } - factory License.getLicense(bool isNewVersion) { + static Future _precessWpp() async { + final bool whatsapp = await StorageHelper().g(KeychainStorageKey.whatsapp.value).then((v) => v.toBoolean()); + if (whatsapp) return ModuleStatus.active.key; + else return ModuleStatus.inactive.key; + } + static Future _processProvisional() async { + final bool provisional = await StorageHelper().g(KeychainStorageKey.provisional.value).then((v) => v.toBoolean()); + if (provisional) return ModuleStatus.active.key; + else return ModuleStatus.inactive.key; + } + + static Future _processPets() async { + final bool pets = await StorageHelper().g(KeychainStorageKey.pets.value).then((v) => v.toBoolean()); + if (pets) return ModuleStatus.active.key; + else return ModuleStatus.inactive.key; + } + + + + static Future getLicense(bool isNewVersion) async { return License([ Module( - key: 'FRE-HUB-MESSAGES', + key: LicenseKeys.messages.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-LIBERATIONS', + key: LicenseKeys.liberations.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-RESERVATIONS', + key: LicenseKeys.reservations.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-ACCESS', + key: LicenseKeys.access.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-OPENED-VISITS', + key: LicenseKeys.openedVisits.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-VEHICLES', + key: LicenseKeys.vehicles.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-RESIDENTS', + key: LicenseKeys.residents.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-PETS', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + key: LicenseKeys.pets.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.pets), expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-ORDERS', + key: LicenseKeys.orders.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-COMPLETE-SCHEDULE', + key: LicenseKeys.completeSchedule.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-AGE-PROV-PRESTADOR', + key: LicenseKeys.providerSchedule.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.providerSchedule), + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.deliverySchedule.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.deliverySchedule), + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.fastPass.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.fastPass), + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.qrCode.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-AGE-PROV-DELIVERY', + key: LicenseKeys.visitors.value, display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-FASTPASS', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, - expirationDate: '', - startDate: '', - quantity: 0, - ), - Module( - key: 'FRE-HUB-QRCODE', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, - expirationDate: '', - startDate: '', - quantity: 0, - ), - Module( - key: 'FRE-HUB-VISITORS', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, - expirationDate: '', - startDate: '', - quantity: 0, - ), - Module( - key: 'FRE-HUB-PROPERTY', + key: LicenseKeys.property.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-PEOPLE', + key: LicenseKeys.people.value, display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( - key: 'FRE-HUB-PETS-HISTORY', - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + key: LicenseKeys.petsHistory.value, + display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.petsHistory), expirationDate: '', startDate: '', quantity: 0, ), + Module( + key: LicenseKeys.settings.value, + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + Module( + key: LicenseKeys.logout.value, + display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + expirationDate: '', + startDate: '', + quantity: 0, + ), + ]); } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 6953fe7f..48463b0e 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -194,21 +194,13 @@ class AuthenticationService { String content; try { await PhpGroup.deleteAccount.call().then((value) async { - final Map extra = { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }; if (value.jsonBody['error'] == false) { content = FFLocalizations.of(context).getVariableText( enText: 'Account deleted successfully', ptText: 'Conta deletada com sucesso', ); - await StorageHelper().c(Storage.secureStorage); - context.pop(); - context.go('/welcomePage', extra: extra); + return await signOut(context); + } }).catchError((err) { context.pop(); @@ -216,7 +208,8 @@ class AuthenticationService { enText: 'Error deleting account', ptText: 'Erro ao deletar conta', ); - SnackBarUtil.showSnackBar(context, content); + SnackBarUtil.showSnackBar(context, content); + return; }); } catch (err) { context.pop(); @@ -225,6 +218,7 @@ class AuthenticationService { ptText: 'Erro ao deletar conta', ); SnackBarUtil.showSnackBar(context, content, isError: true); + return; } } } diff --git a/pubspec.lock b/pubspec.lock index 554f2649..b40d3b0b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -640,6 +640,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.23" + flutter_riverpod: + dependency: "direct main" + description: + name: flutter_riverpod + sha256: "9532ee6db4a943a1ed8383072a2e3eeda041db5657cdf6d2acecf3c21ecbe7e1" + url: "https://pub.dev" + source: hosted + version: "2.6.1" flutter_secure_storage: dependency: "direct main" description: @@ -1378,6 +1386,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" + riverpod: + dependency: transitive + description: + name: riverpod + sha256: "59062512288d3056b2321804332a13ffdd1bf16df70dcc8e506e411280a72959" + url: "https://pub.dev" + source: hosted + version: "2.6.1" rxdart: dependency: "direct main" description: @@ -1559,6 +1575,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.1" + state_notifier: + dependency: transitive + description: + name: state_notifier + sha256: b8677376aa54f2d7c58280d5a007f9e8774f1968d1fb1c096adcb4792fba29bb + url: "https://pub.dev" + source: hosted + version: "1.0.0" stream_channel: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index becd74ab..ffdff88d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -93,7 +93,7 @@ dependencies: fluttertoast: ^8.2.8 cupertino_icons: ^1.0.0 flutter_bloc: ^8.1.6 - # flutter_riverpod: ^2.5.1 + flutter_riverpod: ^2.5.1 qr_flutter: ^4.1.0 permission_handler: ^11.3.1 firebase_crashlytics: ^4.0.1 From a1698872e1f5877f6493bca9090235d49e9c2c86 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 2 Dec 2024 11:34:25 -0300 Subject: [PATCH 28/75] fix MultiBlocProvider --- .../home/presentation/pages/home_page.dart | 23 +- .../repositories/locals_repository_impl.dart | 7 +- .../local_profile/local_profile_widget.dart | 279 +++++++++++++----- .../widgets/menu_view/menu_view_factory.dart | 15 +- lib/shared/utils/loading_util.dart | 17 ++ 5 files changed, 235 insertions(+), 106 deletions(-) create mode 100644 lib/shared/utils/loading_util.dart diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 8b254a27..75d1916e 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -21,22 +21,19 @@ class HomePageWidget extends StatefulWidget { class _HomePageWidgetState extends State { final scaffoldKey = GlobalKey(); - @override - void initState() { - super.initState(); - _initializePage(); - } - - Future _initializePage() async { - await LocalsRepositoryImpl().processLocals(context).whenComplete(() async { - context.read().add(LocalProfileEvent()); - }); - } @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => HomeBloc()..add(HomeEvent()), + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => HomeBloc()..add(HomeEvent()), + ), + BlocProvider( + create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), + ), + + ], child: Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 27873228..cd711443 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -1,4 +1,5 @@ -import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; @@ -17,7 +18,9 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future processLocals(BuildContext context) async { - return await remoteDataSource.processLocals(context); + final bool response = await remoteDataSource.processLocals(context); + context.read().add(LocalProfileEvent()); + return response; } @override diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index f5523433..4a54b3fb 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -6,8 +6,10 @@ import 'package:hub/flutter_flow/custom_functions.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; +import 'package:hub/shared/components/molecules/modules/data/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:provider/provider.dart'; class LocalProfileComponentWidget extends StatefulWidget { const LocalProfileComponentWidget({super.key}); @@ -19,110 +21,229 @@ class LocalProfileComponentWidget extends StatefulWidget { class _LocalProfileComponentWidgetState extends State { + Future callback() async { + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await LocalsRepositoryImpl().processLocals(context); + } + @override Widget build(BuildContext context) { - return BlocProvider( - create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), - child: BlocBuilder( - builder: (context, state) { + + + return + StreamBuilder( + stream: LicenseRepositoryImpl.stream, + builder: (context, snapshot) { final textScaler = MediaQuery.textScalerOf(context); final double baseFontSize = 14.0; final double scaledFontSize = baseFontSize * textScaler.scale(1); final double limitedFontSize = scaledFontSize > 20 ? 12 : scaledFontSize; + + + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } else if (!snapshot.hasData || snapshot.data! == false) { + + return BlocBuilder( + builder: (context, state) { + return _buildDefaultLocalProfile(context, limitedFontSize); + }, + ); + + + } + + return BlocBuilder( + builder: (context, state) { + return _buildAsyncLocalProfile(context, state, limitedFontSize, callback); + }, + ); + + }, + ); + + } - return Container( - decoration: const BoxDecoration(), - child: Align( - alignment: const AlignmentDirectional(0.0, -1.0), - child: Material( - color: Colors.transparent, - elevation: 0.0, - child: Container( - width: double.infinity, - height: 119.0, - decoration: BoxDecoration( + Container _buildDefaultLocalProfile(BuildContext context, double limitedFontSize) { + return Container( + decoration: const BoxDecoration(), + child: Align( + alignment: const AlignmentDirectional(0.0, -1.0), + child: Material( + color: Colors.transparent, + elevation: 0.0, + child: Container( + width: double.infinity, + height: 119.0, + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primary, + border: Border.all( color: FlutterFlowTheme.of(context).primary, - border: Border.all( - color: FlutterFlowTheme.of(context).primary, - ), ), - child: Row( - mainAxisSize: MainAxisSize.max, - children: [ - Align( - alignment: const AlignmentDirectional(-1.0, 0.0), - child: Padding( - padding: const EdgeInsets.all(2.0), - child: InkWell( - splashColor: Colors.transparent, - focusColor: Colors.transparent, - hoverColor: Colors.transparent, - highlightColor: Colors.transparent, - onTap: () async { - await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); - await LocalsRepositoryImpl().processLocals(context).whenComplete(() async => context.read().add(LocalProfileEvent())); - }, - child: ClipRRect( - borderRadius: BorderRadius.circular(200.0), - child: CachedNetworkImage( - imageBuilder: (context, imageProvider) => Container( - decoration: BoxDecoration( - image: DecorationImage( - image: imageProvider, - fit: BoxFit.cover, - ), + ), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: const AlignmentDirectional(-1.0, 0.0), + child: Padding( + padding: const EdgeInsets.all(2.0), + child: InkWell( + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: () async { + await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await LocalsRepositoryImpl().processLocals(context); + }, + child: ClipRRect( + borderRadius: BorderRadius.circular(200.0), + child: CachedNetworkImage( + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, ), ), - imageUrl: valueOrDefault('https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', 'assets/images/home.png'), - width: 80.0, - height: 80.0, - fit: BoxFit.cover, - alignment: const Alignment(0.0, 0.0), - placeholder: (context, url) => Image.asset('assets/images/home.png'), - errorListener: (_) => Image.asset('assets/images/home.png'), - errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), ), - )), + imageUrl: 'assets/images/home.png', + width: 80.0, + height: 80.0, + fit: BoxFit.cover, + alignment: const Alignment(0.0, 0.0), + placeholder: (context, url) => Image.asset('assets/images/home.png'), + errorListener: (_) => Image.asset('assets/images/home.png'), + errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), + ), + )), + ), + ), + Expanded( + child: Tooltip( + message: FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + child: Text( + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), ), ), - Expanded( - child: Tooltip( - message: valueOrDefault( + ), + ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), + ), + ), + ), + ), + ); + } + + Container _buildAsyncLocalProfile(BuildContext context, LocalProfileState state, double limitedFontSize, Future Function() callback) { + return Container( + decoration: const BoxDecoration(), + child: Align( + alignment: const AlignmentDirectional(0.0, -1.0), + child: Material( + color: Colors.transparent, + elevation: 0.0, + child: Container( + width: double.infinity, + height: 119.0, + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primary, + border: Border.all( + color: FlutterFlowTheme.of(context).primary, + ), + ), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: const AlignmentDirectional(-1.0, 0.0), + child: Padding( + padding: const EdgeInsets.all(2.0), + child: InkWell( + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: callback, + child: ClipRRect( + borderRadius: BorderRadius.circular(200.0), + child: CachedNetworkImage( + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + ), + ), + ), + imageUrl: valueOrDefault('https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', 'assets/images/home.png'), + width: 80.0, + height: 80.0, + fit: BoxFit.cover, + alignment: const Alignment(0.0, 0.0), + placeholder: (context, url) => Image.asset('assets/images/home.png'), + errorListener: (_) => Image.asset('assets/images/home.png'), + errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), + ), + )), + ), + ), + Expanded( + child: Tooltip( + message: valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + ), + child: Text( + valueOrDefault( convertToUppercase(state.cliName), FFLocalizations.of(context).getVariableText( ptText: 'SEM LOCAL VINCULADO', enText: 'NO LINKED LOCAL', ), ), - child: Text( - valueOrDefault( - convertToUppercase(state.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), ), - ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Nunito', - color: FlutterFlowTheme.of(context).info, - fontSize: limitedFontSize, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), - ), - ), ), ), - ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), - ), + ), + ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), ), ), ), - ); - }, - ), - ); + ), + ); + + } } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart index 62634c64..23eb2f8c 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/utils/loading_util.dart'; class MenuViewFactory extends StatelessWidget { final MenuView view; @@ -30,7 +31,7 @@ class MenuViewFactory extends StatelessWidget { } else if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); } else if (!snapshot.hasData || snapshot.data! == false) { - return _buildLoadingIndicator(context); + return LoadingUtil.buildLoadingIndicator(context); } return _buildMenuBloc(context); }, @@ -41,17 +42,7 @@ class MenuViewFactory extends StatelessWidget { return _buildMenuBloc(context); } - Widget _buildLoadingIndicator(BuildContext context) { - return Center( - child: Padding( - padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), - child: CircularProgressIndicator( - backgroundColor: FlutterFlowTheme.of(navigatorKey.currentContext!).primaryBackground, - color: FlutterFlowTheme.of(navigatorKey.currentContext!).primary, - ), - ), - ); - } + Widget _buildMenuBloc(BuildContext context) { return BlocProvider( diff --git a/lib/shared/utils/loading_util.dart b/lib/shared/utils/loading_util.dart new file mode 100644 index 00000000..d30dfec3 --- /dev/null +++ b/lib/shared/utils/loading_util.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; + +class LoadingUtil { + static Widget buildLoadingIndicator(BuildContext context) { + return Center( + child: Padding( + padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 10), + child: CircularProgressIndicator( + backgroundColor: FlutterFlowTheme.of(navigatorKey.currentContext!).primaryBackground, + color: FlutterFlowTheme.of(navigatorKey.currentContext!).primary, + ), + ), + ); + } +} \ No newline at end of file From 38b452ed83ff52192acf17d689de60d6eca5b176 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 2 Dec 2024 11:35:26 -0300 Subject: [PATCH 29/75] WIP --- lib/features/home/presentation/pages/home_page.dart | 1 - .../widgets/local_profile/local_profile_widget.dart | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 75d1916e..79db0532 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -32,7 +32,6 @@ class _HomePageWidgetState extends State { BlocProvider( create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), ), - ], child: Scaffold( key: scaffoldKey, diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 4a54b3fb..d742425e 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -30,8 +30,7 @@ class _LocalProfileComponentWidgetState extends State( + return StreamBuilder( stream: LicenseRepositoryImpl.stream, builder: (context, snapshot) { final textScaler = MediaQuery.textScalerOf(context); @@ -62,7 +61,7 @@ class _LocalProfileComponentWidgetState extends State Date: Tue, 3 Dec 2024 12:54:56 -0300 Subject: [PATCH 30/75] fix null check in toBoolean string extension --- lib/shared/extensions/string_extensions.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/shared/extensions/string_extensions.dart b/lib/shared/extensions/string_extensions.dart index 0538bb7c..20fa5f75 100644 --- a/lib/shared/extensions/string_extensions.dart +++ b/lib/shared/extensions/string_extensions.dart @@ -1,5 +1,6 @@ extension StringNullableExtensions on String? { bool toBoolean() { + if (this == null) return false; return this!.toLowerCase() == 'true'; } } From a4ee7331ab21ea4f56b0ff6cfb642ef9785bc4ce Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 3 Dec 2024 15:58:50 -0300 Subject: [PATCH 31/75] WIP --- lib/backend/api_requests/api_calls.dart | 218 +++--- .../firebase_messaging_service.dart | 2 +- .../notifications/notification_service.dart | 8 +- ..._arrow_linked_locals_component_widget.dart | 16 +- .../schedule_visit_detail_model.dart | 6 +- ...p_arrow_linked_locals_component_model.dart | 8 +- ...cation_modal_template_component_model.dart | 6 +- .../change_pass_widget.dart | 2 +- ...item_details_template_component_model.dart | 6 +- .../provisional_schedule_template_model.dart | 10 +- ...siter_vistor_template_component_model.dart | 6 +- .../sign_up_template_component_widget.dart | 2 +- .../view_visit_detail_model.dart | 6 +- ...search_modal_template_component_model.dart | 6 +- .../home/presentation/blocs/home_bloc.dart | 10 +- .../home/presentation/pages/home_page.dart | 8 +- .../pages/about_property_screen.dart | 8 +- lib/flutter_flow/nav/nav.dart | 8 +- lib/main.dart | 10 +- .../acess_history_page_model.dart | 6 +- .../fast_pass_page/fast_pass_page_widget.dart | 10 +- .../liberation_history_model.dart | 6 +- .../message_history_page_model.dart | 6 +- .../package_order_page.dart | 2 +- .../pets_history_screen.dart | 8 +- lib/pages/pets_page/pets_page_model.dart | 8 +- .../preferences_settings_model.dart | 34 +- .../qr_code_page/qr_code_page_model.dart | 4 +- .../qr_code_page/qr_code_page_widget.dart | 2 +- .../reception_page/reception_page_model.dart | 2 +- .../reception_page/reception_page_widget.dart | 4 +- .../reservation_page_widget.dart | 10 +- .../residents_on_the_property_model.dart | 4 +- .../schedule_complete_visit_page_model.dart | 6 +- .../visit_history_page_widget.dart | 14 +- lib/pages/visits_on_the_property/model.dart | 4 +- .../welcome_page/welcome_page_widget.dart | 6 +- .../molecules/drawer/drawer_widget.dart | 8 +- .../locals_remote_data_source.dart | 160 +--- .../repositories/locals_repository_impl.dart | 17 +- .../respositories/locals_repository.dart | 7 +- .../components/molecules/locals/index.dart | 1 + .../blocs/local_profile_bloc.dart | 8 +- .../local_profile/local_profile_widget.dart | 8 +- .../molecules/locals/utils/index.dart | 1 + .../molecules/locals/utils/local_util.dart | 130 ++++ .../menu/data/data_sources/index.dart | 1 + .../data_sources/menu_local_data_source.dart | 98 +++ .../menu/data/repositories/index.dart | 1 + .../repositories/menu_repository_impl.dart | 45 ++ .../molecules/menu/domain/entities/index.dart | 2 - .../menu/domain/entities/menu_entry.dart | 20 - .../menu/domain/entities/menu_item.dart | 6 +- .../menu/domain/entities/menu_view.dart | 0 .../domain/respositories/menu_repository.dart | 6 + .../presentation/blocs/menu_view_bloc.dart | 119 +-- .../molecules/menu/presentation/index.dart | 1 + .../menu/presentation/mappers/index.dart | 1 + .../menu/presentation/mappers/menu_entry.dart | 219 ++++++ .../menu/presentation/widgets/index.dart | 4 +- .../widgets/menu_entry/drawer_menu_entry.dart | 228 ------ .../widgets/menu_entry/home_menu_entry.dart | 217 ------ .../widgets/menu_entry/index.dart | 4 - .../menu_entry/menu_entry_factory.dart | 38 - .../menu_entry/property_menu_entry.dart | 69 -- ...nu_view_factory.dart => menu_factory.dart} | 13 +- .../widgets/menu_factory/index.dart | 1 - .../widgets/menu_factory/menu_factory.dart | 25 - .../presentation/widgets/menu_item/index.dart | 1 - .../widgets/menu_item/menu_item_button.dart | 6 +- .../widgets/menu_item/menu_item_card.dart | 6 +- .../widgets/menu_item/menu_item_factory.dart | 24 - .../presentation/widgets/menu_view/index.dart | 1 - .../widgets/menu_view/menu_list_view.dart | 2 - .../menu_view/menu_staggered_view.dart | 3 +- .../license_local_data_source.dart | 4 +- .../license_remote_data_source.dart | 10 +- .../repositories/license_repository_impl.dart | 15 +- .../modules/domain/entities/license.dart | 710 +----------------- .../respositories/license_repository.dart | 7 +- .../helpers/database/database_helper.dart | 2 +- .../helpers/storage/storage_helper.dart | 8 +- .../authentication_service.dart | 26 +- lib/shared/utils/path_util.dart | 17 + lib/shared/utils/share_util.dart | 4 +- 85 files changed, 895 insertions(+), 1891 deletions(-) create mode 100644 lib/shared/components/molecules/locals/utils/index.dart create mode 100644 lib/shared/components/molecules/locals/utils/local_util.dart create mode 100644 lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart create mode 100644 lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart delete mode 100644 lib/shared/components/molecules/menu/domain/entities/menu_entry.dart delete mode 100644 lib/shared/components/molecules/menu/domain/entities/menu_view.dart create mode 100644 lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart create mode 100644 lib/shared/components/molecules/menu/presentation/mappers/index.dart create mode 100644 lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart rename lib/shared/components/molecules/menu/presentation/widgets/{menu_view/menu_view_factory.dart => menu_factory.dart} (87%) delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart delete mode 100644 lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart create mode 100644 lib/shared/utils/path_util.dart diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 269dcf4c..ca2f5d9c 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -65,9 +65,9 @@ class PhpGroup { class GetOpenedVisits { Future call(final String page) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getOpenedVisits'; const String pageSize = '10'; return await ApiManager.instance.makeApiCall( @@ -97,9 +97,9 @@ class GetOpenedVisits { class GetResidentsByProperty { Future call(final String page) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; - final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; - final String cliID = await StorageHelper().g(KeychainStorageKey.clientUUID.value) ?? ''; + final String devUUID = await StorageHelper().get(KeychainStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().get(KeychainStorageKey.userUUID.value) ?? ''; + final String cliID = await StorageHelper().get(KeychainStorageKey.clientUUID.value) ?? ''; const String atividade = 'getResidentsByProperty'; const String pageSize = '10'; return await ApiManager.instance.makeApiCall( @@ -128,9 +128,9 @@ class GetResidentsByProperty { class GetVehiclesByProperty { Future call(final String page) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVehiclesByProperty'; const String pageSize = '10'; return await ApiManager.instance.makeApiCall( @@ -191,9 +191,9 @@ class TestCall { class GetLicense { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; return await ApiManager.instance.makeApiCall( callName: 'getLicense', @@ -222,8 +222,8 @@ class GetLicense { class UnregisterDevice { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; return await ApiManager.instance.makeApiCall( callName: 'unregisterDevice', @@ -250,9 +250,9 @@ class UnregisterDevice { class DeletePet { Future call({final int? petID = 0}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'excluirPet'; return await ApiManager.instance.makeApiCall( @@ -295,9 +295,9 @@ class UpdatePet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'atualizarPet'; return await ApiManager.instance.makeApiCall( @@ -341,9 +341,9 @@ class GetPets { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaPets'; return await ApiManager.instance.makeApiCall( @@ -375,9 +375,9 @@ class GetPetPhoto { Future call({final int? petId}) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'consultaFotoPet'; return await ApiManager.instance.makeApiCall( @@ -418,9 +418,9 @@ class RegisterPet { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cadastrarPet'; return await ApiManager.instance.makeApiCall( @@ -463,9 +463,9 @@ class BuscaEnconcomendas { final String? adresseeType, final String? status, }) async { - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getEncomendas'; final String baseUrl = PhpGroup.getBaseUrl(); @@ -507,9 +507,9 @@ class CancelaVisita { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; return await ApiManager.instance.makeApiCall( @@ -541,8 +541,8 @@ class CancelaVisita { class DeleteAccount { Future call() async { - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; final String baseUrl = PhpGroup.getBaseUrl(); return await ApiManager.instance.makeApiCall( @@ -573,9 +573,9 @@ class ChangePanic { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return await ApiManager.instance.makeApiCall( @@ -609,9 +609,9 @@ class ChangePass { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return await ApiManager.instance.makeApiCall( @@ -645,9 +645,9 @@ class RespondeVinculo { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; return await ApiManager.instance.makeApiCall( callName: 'respondeVinculo', @@ -679,9 +679,9 @@ class ChangeNotifica { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'updVisitado'; return await ApiManager.instance.makeApiCall( @@ -713,10 +713,10 @@ class UpdateIDE { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - final String newIde = (await StorageHelper().g(KeychainStorageKey.userDevUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + final String newIde = (await StorageHelper().get(KeychainStorageKey.userDevUUID.value)) ?? ''; const String atividade = 'updVisitado'; return await ApiManager.instance.makeApiCall( @@ -748,9 +748,9 @@ class UpdToken { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String token = (await StorageHelper().g(SecureStorageKey.token.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String token = (await StorageHelper().get(SecureStorageKey.token.value)) ?? ''; return await ApiManager.instance.makeApiCall( callName: 'updToken', @@ -777,11 +777,11 @@ class UpdToken { class LoginCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String email = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; - final String password = (await StorageHelper().g(SecureStorageKey.password.value)) ?? ''; - final String type = (await StorageHelper().g(SecureStorageKey.deviceType.value)) ?? ''; - final String description = (await StorageHelper().g(SecureStorageKey.deviceDescription.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String email = (await StorageHelper().get(SecureStorageKey.email.value)) ?? ''; + final String password = (await StorageHelper().get(SecureStorageKey.password.value)) ?? ''; + final String type = (await StorageHelper().get(SecureStorageKey.deviceType.value)) ?? ''; + final String description = (await StorageHelper().get(SecureStorageKey.deviceDescription.value)) ?? ''; late final String token; try { token = await FirebaseMessagingService.getToken(); @@ -864,9 +864,9 @@ class ChangePasswordCall { required final String psswd, }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; return await ApiManager.instance.makeApiCall( callName: 'changePassword', @@ -925,8 +925,8 @@ class GetLocalsCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; - final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; + final String devUUID = await StorageHelper().get(KeychainStorageKey.devUUID.value) ?? ''; + final String userUUID = await StorageHelper().get(KeychainStorageKey.userUUID.value) ?? ''; return await ApiManager.instance.makeApiCall( callName: 'getLocals', @@ -965,9 +965,9 @@ class PostScheduleVisitorCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisitante'; return await ApiManager.instance.makeApiCall( @@ -1020,9 +1020,9 @@ class PostScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putVisita'; return await ApiManager.instance.makeApiCall( @@ -1074,9 +1074,9 @@ class GetScheduleVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; return await ApiManager.instance.makeApiCall( @@ -1348,9 +1348,9 @@ class GetDadosCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getDados'; return await ApiManager.instance.makeApiCall( @@ -1581,9 +1581,9 @@ class GetVisitorByDocCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitante'; return await ApiManager.instance.makeApiCall( @@ -1635,9 +1635,9 @@ class GetFotoVisitanteCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getFotoVisitante'; return await ApiManager.instance.makeApiCall( @@ -1674,9 +1674,9 @@ class PostProvVisitSchedulingCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'putAgendamentoProv'; return await ApiManager.instance.makeApiCall( @@ -1723,9 +1723,9 @@ class GetVisitsCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getVisitas'; return await ApiManager.instance.makeApiCall( @@ -1986,9 +1986,9 @@ class DeleteVisitCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'cancelaVisita'; return await ApiManager.instance.makeApiCall( @@ -2029,10 +2029,10 @@ class GetPessoasLocalCall { Future call() async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String ownerUUID = (await StorageHelper().get(KeychainStorageKey.ownerUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; return await ApiManager.instance.makeApiCall( callName: 'getPessoasLocal', @@ -2095,9 +2095,9 @@ class RespondeSolicitacaoCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'respondeSolicitacao'; return await ApiManager.instance.makeApiCall( @@ -2145,9 +2145,9 @@ class GetAccessCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getAcessos'; return await ApiManager.instance.makeApiCall( @@ -2394,9 +2394,9 @@ class GetLiberationsCall { final StreamController controller = StreamController(); Future.microtask(() async { - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getSolicitacoes'; try { @@ -2586,9 +2586,9 @@ class GetMessagesCall { }) async { final String baseUrl = PhpGroup.getBaseUrl(); - final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final String devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final String userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const String atividade = 'getMensagens'; return await ApiManager.instance.makeApiCall( diff --git a/lib/backend/notifications/firebase_messaging_service.dart b/lib/backend/notifications/firebase_messaging_service.dart index 390a2036..3b768ad2 100644 --- a/lib/backend/notifications/firebase_messaging_service.dart +++ b/lib/backend/notifications/firebase_messaging_service.dart @@ -43,7 +43,7 @@ class FirebaseMessagingService { final String? deviceToken = await _firebaseMessaging.getToken(); if (deviceToken != null) { - await StorageHelper().s(SecureStorageKey.token.value, deviceToken); + await StorageHelper().set(SecureStorageKey.token.value, 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 db0a7c0f..c771a378 100644 --- a/lib/backend/notifications/notification_service.dart +++ b/lib/backend/notifications/notification_service.dart @@ -15,7 +15,7 @@ import 'package:hub/shared/utils/dialog_util.dart'; Future onMessageReceived(Map payload, String? extra, String? handleClick) async { final localId = jsonDecode(payload['local']!)['CLI_ID']; - final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; answersRequest( {required BuildContext context, @@ -239,7 +239,7 @@ Future onMessageReceived(Map payload, String? extra, Stri break; case 'enroll_cond': - await StorageHelper().s(SecureStorageKey.haveLocal.value, true); + await StorageHelper().set(SecureStorageKey.haveLocal.value, true); StorageHelper().context!.go('/homePage'); break; default: @@ -271,11 +271,11 @@ class NotificationService { await AwesomeNotifications().isNotificationAllowed().then((isAllowed) async { final bool requestOSnotification = - (await StorageHelper().g(KeychainStorageKey.requestOSNotification.value)) == 'true'; + (await StorageHelper().get(KeychainStorageKey.requestOSNotification.value)) == 'true'; if (requestOSnotification == false) { if (isAllowed == false) { - await StorageHelper().s(KeychainStorageKey.requestOSNotification.value, true); + await StorageHelper().set(KeychainStorageKey.requestOSNotification.value, true); await AwesomeNotifications().requestPermissionToSendNotifications(); } } 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 8d5da9a3..8d781daa 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 @@ -105,9 +105,9 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State _fetchResponseLink(String status, String cliID) async { try { - await StorageHelper().s(KeychainStorageKey.clientUUID.value, cliID); + await StorageHelper().set(KeychainStorageKey.clientUUID.value, cliID); var response = await PhpGroup.resopndeVinculo.call(tarefa: status); if (response.jsonBody['error'] == false) { @@ -147,7 +147,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State initDB() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart b/lib/components/organism_components/up_arrow_linked_locals_component/up_arrow_linked_locals_component_model.dart index 746a34fe..87665faa 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 @@ -16,10 +16,10 @@ class UpArrowLinkedLocalsComponentModel extends FlutterFlowModel initDB() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; } @override diff --git a/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart b/lib/components/templates_components/access_notification_modal_template_component/access_notification_modal_template_component_model.dart index 114242ef..fa663658 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 @@ -32,9 +32,9 @@ class AccessNotificationModalTemplateComponentModel } Future initDB() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart b/lib/components/templates_components/change_passs_qr_code_pass_key_template_component/change_pass_widget.dart index 0e52975f..e361442d 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 @@ -49,7 +49,7 @@ class _PassKeyTemplateWidgetState extends State { } Future _initialize() async { - _accessPass = await StorageHelper().g(SecureStorageKey.accessPass.value) ?? ''; + _accessPass = await StorageHelper().get(SecureStorageKey.accessPass.value) ?? ''; } @override 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 b7d768b8..4a9c55bb 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 @@ -27,9 +27,9 @@ class LiberationHistoryItemDetailsTemplateComponentModel void initState(BuildContext context) {} Future initDatabase() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; ; } 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 4f8bd82e..8ec62766 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 @@ -137,12 +137,12 @@ class ScheduleProvisionalVisitPageModel extends FlutterFlowModel init() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; ; - cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; + cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + ownerUUID = (await StorageHelper().get(KeychainStorageKey.ownerUUID.value)) ?? ''; setState?.call(); } } 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 f7ff104f..d1f63dc2 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 @@ -129,9 +129,9 @@ class RegisiterVistorTemplateComponentModel extends FlutterFlowModel initializeDatabase() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; ; } 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 ca51110b..07614dfe 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 @@ -91,7 +91,7 @@ class _SignUpTemplateComponentWidgetState extends State _initialize() async { - _deviceType = (await StorageHelper().g(SecureStorageKey.deviceType.value)) ?? ''; + _deviceType = (await StorageHelper().get(SecureStorageKey.deviceType.value)) ?? ''; } @override 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 58ea89e5..3fde3bf2 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 @@ -37,9 +37,9 @@ class ViewVisitDetailModel extends FlutterFlowModel { } Future initializeDatabase() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; ; } 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 ab8f9fc4..e71a2c86 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 @@ -35,9 +35,9 @@ class VisitorSearchModalTemplateComponentModel extends FlutterFlowModel initDatabase() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; ; } diff --git a/lib/features/home/presentation/blocs/home_bloc.dart b/lib/features/home/presentation/blocs/home_bloc.dart index b92d32b3..bf6e580e 100644 --- a/lib/features/home/presentation/blocs/home_bloc.dart +++ b/lib/features/home/presentation/blocs/home_bloc.dart @@ -7,11 +7,11 @@ import 'index.dart'; class HomeBloc extends Bloc { HomeBloc() : super(HomeState()) { on((event, emit) async { - final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - final userName = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; - final userEmail = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; + final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + final userName = (await StorageHelper().get(KeychainStorageKey.userName.value)) ?? ''; + final userEmail = (await StorageHelper().get(SecureStorageKey.email.value)) ?? ''; emit(state.copyWith( devUUID: devUUID, diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 79db0532..f63c044e 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -128,10 +128,10 @@ class _HomePageWidgetState extends State { color: FlutterFlowTheme.of(context).primaryBackground, child: Padding( padding: const EdgeInsets.only(bottom: 40), - child: MenuFactory( - menuEntry: MenuEntries.home, - menuItem: EnumMenuItem.button, - menuView: MenuView.list_grid, + child: Menufactory( + entry: MenuEntry.getEntriesByType(MenuEntryType.Home), + item: EnumMenuItem.button, + view: MenuView.list_grid, ), ), ); diff --git a/lib/features/property/presentation/pages/about_property_screen.dart b/lib/features/property/presentation/pages/about_property_screen.dart index de4bc014..dea748d2 100644 --- a/lib/features/property/presentation/pages/about_property_screen.dart +++ b/lib/features/property/presentation/pages/about_property_screen.dart @@ -77,10 +77,10 @@ class _AboutPropertyPageState extends State with SingleTicker return SingleChildScrollView( child: Container( color: FlutterFlowTheme.of(context).primaryBackground, - child: MenuFactory( - menuEntry: MenuEntries.AboutProperty, - menuItem: EnumMenuItem.button, - menuView: MenuView.list_grid, + child: Menufactory( + entry: MenuEntry.getEntriesByType(MenuEntryType.Drawer), + item: EnumMenuItem.button, + view: MenuView.list_grid, ), ), ); diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 1efd1362..11bb57dd 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -85,10 +85,10 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { builder: (context, _) { return FutureBuilder( future: () async { - final bool isLogged = await StorageHelper().g(SecureStorageKey.isLogged.value) == 'true'; - final bool haveLocal = await StorageHelper().g(SecureStorageKey.haveLocal.value) == 'true'; - final bool haveUserUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value))?.isNotEmpty ?? false; - final bool haveDevUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value))?.isNotEmpty ?? false; + final bool isLogged = await StorageHelper().get(SecureStorageKey.isLogged.value) == 'true'; + final bool haveLocal = await StorageHelper().get(SecureStorageKey.haveLocal.value) == 'true'; + final bool haveUserUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value))?.isNotEmpty ?? false; + final bool haveDevUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value))?.isNotEmpty ?? false; if (isLogged && haveDevUUID && haveUserUUID) { return haveLocal ? const HomePageWidget() : const ReceptionPageWidget(); diff --git a/lib/main.dart b/lib/main.dart index 1053f9bd..409d2a04 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -30,7 +30,7 @@ void main() async { Future _foregroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, true); + await StorageHelper().set(SecureStorageKey.haveLocal.value, true); StorageHelper().context?.go('/homePage'); } @@ -41,7 +41,7 @@ Future _foregroundHandlerMessage(RemoteMessage message) async { Future _backgroundHandlerMessage(RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, true); + await StorageHelper().set(SecureStorageKey.haveLocal.value, true); StorageHelper().context?.go('/homePage'); } } @@ -133,7 +133,7 @@ class _AppState extends State with WidgetsBindingObserver { FirebaseMessaging.onMessage.listen(_foregroundHandlerMessage); FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, true); + await StorageHelper().set(SecureStorageKey.haveLocal.value, true); log('onMessageOpenedApp'); } else { onMessageReceived(message.data, message.notification!.body, message.data['click_action']); @@ -142,7 +142,7 @@ class _AppState extends State with WidgetsBindingObserver { FirebaseMessaging.instance.getInitialMessage().then((message) async { if (message != null) { if (message.data['click_action'] == 'enroll_cond') { - await StorageHelper().s(SecureStorageKey.haveLocal.value, true); + await StorageHelper().set(SecureStorageKey.haveLocal.value, true); log('getInitialMessage'); } } @@ -187,7 +187,7 @@ class _AppState extends State with WidgetsBindingObserver { @override void didChangeAppLifecycleState(AppLifecycleState state) async { if (state == AppLifecycleState.detached) { - await LocalsRepositoryImpl().processLocals(context); + await LocalsRepositoryImpl().update(context); await FirebaseMessagingService().updateDeviceToken(); } } 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 98a33bf6..429ae806 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -33,9 +33,9 @@ class AcessHistoryPageModel extends FlutterFlowModel { } Future initDatabase() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/fast_pass_page/fast_pass_page_widget.dart b/lib/pages/fast_pass_page/fast_pass_page_widget.dart index 8df206f9..31bb70eb 100644 --- a/lib/pages/fast_pass_page/fast_pass_page_widget.dart +++ b/lib/pages/fast_pass_page/fast_pass_page_widget.dart @@ -25,11 +25,11 @@ class _FastPassPageWidgetState extends State { late InAppWebViewController _controllerIOS; Future> initVariables() async { - final email = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; - final name = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; - final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final email = (await StorageHelper().get(SecureStorageKey.email.value)) ?? ''; + final name = (await StorageHelper().get(KeychainStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/fast-pass/$cliUUID'; final freUserData = diff --git a/lib/pages/liberation_history/liberation_history_model.dart b/lib/pages/liberation_history/liberation_history_model.dart index 7c64039a..8c016069 100644 --- a/lib/pages/liberation_history/liberation_history_model.dart +++ b/lib/pages/liberation_history/liberation_history_model.dart @@ -36,9 +36,9 @@ class LiberationHistoryModel extends FlutterFlowModel { } Future init() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } Future answersRequest( diff --git a/lib/pages/message_history_page/message_history_page_model.dart b/lib/pages/message_history_page/message_history_page_model.dart index 7db66d8a..1a2cd70d 100644 --- a/lib/pages/message_history_page/message_history_page_model.dart +++ b/lib/pages/message_history_page/message_history_page_model.dart @@ -39,9 +39,9 @@ class MessageHistoryPageModel extends FlutterFlowModel } Future init() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index c3d352f4..0df4e591 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -64,7 +64,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } @override diff --git a/lib/pages/pets_on_the_property_page/pets_history_screen.dart b/lib/pages/pets_on_the_property_page/pets_history_screen.dart index 1229f3c6..5c29a948 100644 --- a/lib/pages/pets_on_the_property_page/pets_history_screen.dart +++ b/lib/pages/pets_on_the_property_page/pets_history_screen.dart @@ -291,10 +291,10 @@ class _PetsHistoryScreenState extends State with TickerProvid } ], onTapCardItemAction: () async { - final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - final cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; 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 21f74d62..aeb213a9 100644 --- a/lib/pages/pets_page/pets_page_model.dart +++ b/lib/pages/pets_page/pets_page_model.dart @@ -147,10 +147,10 @@ class PetsPageModel extends FlutterFlowModel { textControllerObservation = TextEditingController(); WidgetsBinding.instance.addPostFrameCallback((_) async { - devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; - userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; - cliUUID = await StorageHelper().g(KeychainStorageKey.clientUUID.value) ?? ''; - petAmountRegister = await StorageHelper().g(KeychainStorageKey.petAmount.value) ?? ''; + devUUID = await StorageHelper().get(KeychainStorageKey.devUUID.value) ?? ''; + userUUID = await StorageHelper().get(KeychainStorageKey.userUUID.value) ?? ''; + cliUUID = await StorageHelper().get(KeychainStorageKey.clientUUID.value) ?? ''; + petAmountRegister = await StorageHelper().get(KeychainStorageKey.petAmount.value) ?? ''; }); } diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 734a8f92..2f8adda5 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -23,11 +23,11 @@ class PreferencesPageModel with ChangeNotifier { late bool isPanic = false; Future _initialize() async { - isFingerprint = await StorageHelper().g(KeychainStorageKey.fingerprint.value) == 'true'; - isPerson = await StorageHelper().g(KeychainStorageKey.person.value) == 'true'; - isNotify = await StorageHelper().g(KeychainStorageKey.notify.value) == 'true'; - isAccess = await StorageHelper().g(KeychainStorageKey.access.value) == 'true'; - isPanic = await StorageHelper().g(KeychainStorageKey.panic.value) == 'true'; + isFingerprint = await StorageHelper().get(KeychainStorageKey.fingerprint.value) == 'true'; + isPerson = await StorageHelper().get(KeychainStorageKey.person.value) == 'true'; + isNotify = await StorageHelper().get(KeychainStorageKey.notify.value) == 'true'; + isAccess = await StorageHelper().get(KeychainStorageKey.access.value) == 'true'; + isPanic = await StorageHelper().get(KeychainStorageKey.panic.value) == 'true'; notifyListeners(); } @@ -36,7 +36,7 @@ class PreferencesPageModel with ChangeNotifier { } Future enablePerson(BuildContext context) async { - final String userDevUUID = (await StorageHelper().g(KeychainStorageKey.userDevUUID.value)) ?? ''; + final String userDevUUID = (await StorageHelper().get(KeychainStorageKey.userDevUUID.value)) ?? ''; notifyListeners(); Share.share( FFLocalizations.of(context).getVariableText( @@ -63,7 +63,7 @@ class PreferencesPageModel with ChangeNotifier { .call(notifica: value) .then((value) async { if (value.jsonBody['error'] == false) { - await StorageHelper().s(KeychainStorageKey.notify.value, isNotify ? 'false' : 'true'); + await StorageHelper().set(KeychainStorageKey.notify.value, isNotify ? 'false' : 'true'); content = FFLocalizations.of(context).getVariableText( enText: 'Notification changed successfully', ptText: 'Notificação alterada com sucesso', @@ -85,7 +85,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => isNotify = await StorageHelper().g(KeychainStorageKey.notify.value) == 'true') + .then((_) async => isNotify = await StorageHelper().get(KeychainStorageKey.notify.value) == 'true') .whenComplete(() => notifyListeners()); context.pop(); } @@ -134,13 +134,13 @@ class PreferencesPageModel with ChangeNotifier { Future toggleAccess(BuildContext context) async { onChange(String key) async { - await StorageHelper().s(SecureStorageKey.accessPass.value, key); + await StorageHelper().set(SecureStorageKey.accessPass.value, key); await PhpGroup.changePass .call(newSenha: key) .then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - await StorageHelper().s(KeychainStorageKey.access.value, isAccess ? 'false' : 'true'); + await StorageHelper().set(KeychainStorageKey.access.value, isAccess ? 'false' : 'true'); notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Access pass changed successfully', @@ -162,7 +162,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => isAccess = await StorageHelper().g(KeychainStorageKey.access.value) == 'true') + .then((_) async => isAccess = await StorageHelper().get(KeychainStorageKey.access.value) == 'true') .whenComplete(() => notifyListeners()); } @@ -171,13 +171,13 @@ class PreferencesPageModel with ChangeNotifier { Future togglePanic(BuildContext context) async { onChange(String key) async { - await StorageHelper().s(SecureStorageKey.panicPass.value, key); + await StorageHelper().set(SecureStorageKey.panicPass.value, key); await PhpGroup.changePanic .call(newSenhaPanico: key) .then((value) async { final String content; if (jsonDecode(value.jsonBody['error'].toString()) == false) { - await StorageHelper().s(KeychainStorageKey.panic.value, isPanic ? 'false' : 'true'); + await StorageHelper().set(KeychainStorageKey.panic.value, isPanic ? 'false' : 'true'); notifyListeners(); content = FFLocalizations.of(context).getVariableText( enText: 'Panic password changed successfully', @@ -199,7 +199,7 @@ class PreferencesPageModel with ChangeNotifier { ); SnackBarUtil.showSnackBar(context, content, isError: true); }) - .then((_) async => isPanic = await StorageHelper().g(KeychainStorageKey.panic.value) == 'true') + .then((_) async => isPanic = await StorageHelper().get(KeychainStorageKey.panic.value) == 'true') .whenComplete(() => notifyListeners()); } @@ -214,11 +214,11 @@ class PreferencesPageModel with ChangeNotifier { onChange(String? key) async { isFingerprint = !isFingerprint; - await StorageHelper().s(SecureStorageKey.fingerprintPass.value, key ?? ''); - await StorageHelper().s(KeychainStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false'); + await StorageHelper().set(SecureStorageKey.fingerprintPass.value, key ?? ''); + await StorageHelper().set(KeychainStorageKey.fingerprint.value, isFingerprint ? 'true' : 'false'); notifyListeners(); SnackBarUtil.showSnackBar(context, content); - isFingerprint = await StorageHelper().g(KeychainStorageKey.fingerprint.value) == 'true'; + isFingerprint = await StorageHelper().get(KeychainStorageKey.fingerprint.value) == 'true'; } isFingerprint ? onChange(null) : _showPassKey(context, onChange); 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 002192ad..41df6e77 100644 --- a/lib/pages/qr_code_page/qr_code_page_model.dart +++ b/lib/pages/qr_code_page/qr_code_page_model.dart @@ -29,8 +29,8 @@ class QrCodePageModel extends FlutterFlowModel { } Future initVariable() async { - isFingerprint = await StorageHelper().g(KeychainStorageKey.fingerprint.value) == 'true'; - userDevUUID = await StorageHelper().g(KeychainStorageKey.userDevUUID.value) ?? ''; + isFingerprint = await StorageHelper().get(KeychainStorageKey.fingerprint.value) == 'true'; + userDevUUID = await StorageHelper().get(KeychainStorageKey.userDevUUID.value) ?? ''; safeSetState?.call(); } diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index b2005f96..6aad1599 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -353,7 +353,7 @@ class _QrCodePageWidgetState extends State with TickerProvider await BiometricHelper.checkBiometrics() .then((value) async => await BiometricHelper.authenticateBiometric().then((value) async { if (value == false) throw Exception('Biometric authentication failed'); - final key = await StorageHelper().g(SecureStorageKey.fingerprintPass.value); + final key = await StorageHelper().get(SecureStorageKey.fingerprintPass.value); if (key == null || key.isEmpty) throw Exception('No key found'); safeSetState(() { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { diff --git a/lib/pages/reception_page/reception_page_model.dart b/lib/pages/reception_page/reception_page_model.dart index e0afe000..239f675a 100644 --- a/lib/pages/reception_page/reception_page_model.dart +++ b/lib/pages/reception_page/reception_page_model.dart @@ -6,7 +6,7 @@ import 'package:share_plus/share_plus.dart'; class ReceptionPageModel with ChangeNotifier { Future getIdenfifier(BuildContext context) async { - final String userDevUUID = (await StorageHelper().g(KeychainStorageKey.userDevUUID.value)) ?? ''; + final String userDevUUID = (await StorageHelper().get(KeychainStorageKey.userDevUUID.value)) ?? ''; notifyListeners(); Share.share( diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index 3891122c..a29e194b 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -33,7 +33,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB }(); FirebaseMessagingService().updateDeviceToken(); - LocalsRepositoryImpl().checkLocals(context); + LocalsRepositoryImpl().validateLocal(context); } @override @@ -46,7 +46,7 @@ class _ReceptionPageWidgetState extends State with WidgetsB void didChangeAppLifecycleState(AppLifecycleState state) { if (state == AppLifecycleState.resumed) { setState(() { - LocalsRepositoryImpl().checkLocals(context); + LocalsRepositoryImpl().validateLocal(context); }); } } diff --git a/lib/pages/reservation_page/reservation_page_widget.dart b/lib/pages/reservation_page/reservation_page_widget.dart index 37b0fe1a..4d9091ac 100644 --- a/lib/pages/reservation_page/reservation_page_widget.dart +++ b/lib/pages/reservation_page/reservation_page_widget.dart @@ -22,11 +22,11 @@ class _ReservationPageWidgetState extends State { late WebViewController _controllerAll; Future> initVariables() async { - final email = (await StorageHelper().g(SecureStorageKey.email.value)) ?? ''; - final name = (await StorageHelper().g(KeychainStorageKey.userName.value)) ?? ''; - final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final clientId = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final email = (await StorageHelper().get(SecureStorageKey.email.value)) ?? ''; + final name = (await StorageHelper().get(KeychainStorageKey.userName.value)) ?? ''; + final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final clientId = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; const createdAt = '0000-00-00 00:00:00'; final url = 'https://hub.freaccess.com.br/hub/reservation/$clientId'; final freUserData = diff --git a/lib/pages/residents_on_the_property/residents_on_the_property_model.dart b/lib/pages/residents_on_the_property/residents_on_the_property_model.dart index e5f1f84c..4883ceb3 100644 --- a/lib/pages/residents_on_the_property/residents_on_the_property_model.dart +++ b/lib/pages/residents_on_the_property/residents_on_the_property_model.dart @@ -18,8 +18,8 @@ class ResidentsOnThePropertyModel extends FlutterFlowModel } Future _initVariables() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } @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 c20c8927..e706f92f 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 @@ -35,9 +35,9 @@ class _VisitHistoryWidgetState extends State with TickerProv List _visitWrap = []; Future _initVariables() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; } @override @@ -245,10 +245,10 @@ class _VisitHistoryWidgetState extends State with TickerProv }, ], onTapCardItemAction: () async { - final devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - final cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; + final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; await showDialog( useSafeArea: true, diff --git a/lib/pages/visits_on_the_property/model.dart b/lib/pages/visits_on_the_property/model.dart index c880c726..9870b4bb 100644 --- a/lib/pages/visits_on_the_property/model.dart +++ b/lib/pages/visits_on_the_property/model.dart @@ -30,8 +30,8 @@ class VisitsModel extends FlutterFlowModel { void dispose() {} Future initAsync() async { - devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; onRefresh?.call(); } diff --git a/lib/pages/welcome_page/welcome_page_widget.dart b/lib/pages/welcome_page/welcome_page_widget.dart index a2a0e7bd..53ac8018 100644 --- a/lib/pages/welcome_page/welcome_page_widget.dart +++ b/lib/pages/welcome_page/welcome_page_widget.dart @@ -32,13 +32,13 @@ class _WelcomePageWidgetState extends State { // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { if (isAndroid == true) { - await StorageHelper().s(SecureStorageKey.deviceType.value, 'Android'); + await StorageHelper().set(SecureStorageKey.deviceType.value, 'Android'); setState(() {}); } else if (isiOS == true) { - await StorageHelper().s(SecureStorageKey.deviceType.value, 'iOS'); + await StorageHelper().set(SecureStorageKey.deviceType.value, 'iOS'); setState(() {}); } else { - await StorageHelper().s(SecureStorageKey.deviceType.value, 'Web'); + await StorageHelper().set(SecureStorageKey.deviceType.value, 'Web'); setState(() {}); } }); diff --git a/lib/shared/components/molecules/drawer/drawer_widget.dart b/lib/shared/components/molecules/drawer/drawer_widget.dart index c913dcb5..253540d1 100644 --- a/lib/shared/components/molecules/drawer/drawer_widget.dart +++ b/lib/shared/components/molecules/drawer/drawer_widget.dart @@ -189,10 +189,10 @@ class CustomDrawer extends StatelessWidget { } Widget _buildDrawerBody(BuildContext context) { - return MenuFactory( - menuEntry: MenuEntries.drawer, - menuItem: EnumMenuItem.tile, - menuView: MenuView.list, + return Menufactory( + entry: MenuEntry.getEntriesByType(MenuEntryType.Property), + item: EnumMenuItem.tile, + view: MenuView.list, ); } } diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index 05ecdc28..c2321d4d 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -8,13 +8,13 @@ import 'package:hub/components/organism_components/bottom_arrow_linked_locals_co import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:hub/shared/utils/dialog_util.dart'; -import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/snackbar_util.dart'; abstract class LocalsRemoteDataSource { @@ -22,7 +22,7 @@ abstract class LocalsRemoteDataSource { Future processLocals(BuildContext context) async => false; Future processData(BuildContext context) async => false; Future selectLocal(BuildContext context, ApiCallResponse? response) async => false; - Future unlinkLocal(BuildContext context) async {} + Future detachLocal(BuildContext context) async {} } class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { @@ -38,7 +38,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { final bool? isError = response.jsonBody['error']; if (isError == true) { - _handleError(context, response.jsonBody['error_msg']); + LocalUtil.handleError(context, response.jsonBody['error_msg']); return; } if (response.jsonBody == null) { @@ -56,11 +56,11 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { final bool isEnable = !isEmpty && isActive; if (isEnable) { - await StorageHelper().s(SecureStorageKey.haveLocal.value, true); - await StorageHelper().s(SecureStorageKey.isLogged.value, true); + await StorageHelper().set(SecureStorageKey.haveLocal.value, true); + await StorageHelper().set(SecureStorageKey.isLogged.value, true); await WidgetsBinding.instance.endOfFrame; - await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); - await StorageHelper().s(KeychainStorageKey.ownerUUID.value, ''); + await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerUUID.value, ''); StorageHelper().context?.go('/homePage'); } } catch (e, s) { @@ -78,7 +78,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { if (isError == true) { final String errorMsg = response.jsonBody['error_msg']; - _handleError(context, errorMsg); + LocalUtil.handleError(context, errorMsg); return false; } if (response.jsonBody == null) { @@ -91,27 +91,27 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { } final List locals = response.jsonBody['locais'].toList() ?? []; - _logLocalsStatus(locals); + LocalUtil.logLocalsStatus(locals); - final bool isActive = _isActive(locals); - final bool isInactived = await _isInactived(locals); - final bool isPending = _isPending(locals); + final bool isActive = LocalUtil.isActive(locals); + final bool isInactived = await LocalUtil.isInactived(locals); + final bool isPending = LocalUtil.isPending(locals); final bool isUnique = locals.length == 1; final bool isBlocked = locals.where((local) => local['CLU_STATUS'] == 'B').isNotEmpty; final bool isEnabled = isUnique && isActive; final bool isDisabled = isUnique && isBlocked; - final bool isUnselected = await _isUnselected(); - final bool isSelected = await _isSelected(isInactived); + final bool isUnselected = await LocalUtil.isUnselected(); + final bool isSelected = await LocalUtil.isSelected(isInactived); final bool isUnavailable = isPending && isUnselected && isUnique; - final bool isAvailable = await _isAvailable(); + final bool isAvailable = await LocalUtil.isAvailable(); if (isDisabled) { AuthenticationService.signOut(context); return true; } else if (isUnavailable) { - return await _handleUnavailable(context, locals); + return await LocalUtil.handleUnavailable(context, locals); } else if (isEnabled) { - return await _handleEnabled(context, locals[0]); + return await LocalUtil.handleEnabled(context, locals[0]); } else if (isUnselected) { log('() => isUnselected'); return await selectLocal(context, response); @@ -166,12 +166,8 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } else { - final bool isNewVersion = await _updateStorageUtil(response.jsonBody); - await LicenseRepositoryImpl().setupLicense(isNewVersion); - if (isNewVersion) { - return await LicenseRepositoryImpl().fetchLicense(isNewVersion); - } - return false; + final bool isNewVersion = await LocalUtil.updateStorageUtil(response.jsonBody); + return await LicenseRepositoryImpl().updateLicense(isNewVersion); } } catch (e, s) { log('() => error processData: $e', stackTrace: s); @@ -205,7 +201,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { } @override - Future unlinkLocal(BuildContext context) async { + Future detachLocal(BuildContext context) async { String content; try { content = FFLocalizations.of(context).getVariableText( @@ -215,8 +211,8 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async { if (value.jsonBody['error'] == false) { - await StorageHelper().s(KeychainStorageKey.clientName.value, ''); - await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); + await StorageHelper().set(KeychainStorageKey.clientName.value, ''); + await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); context.pop(); context.go( '/homePage', @@ -249,117 +245,5 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { } } - void _handleError(BuildContext context, String errorMsg) async { - final String devUUID = await StorageHelper().g(KeychainStorageKey.devUUID.value) ?? ''; - final String userUUID = await StorageHelper().g(KeychainStorageKey.userUUID.value) ?? ''; - final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; - final bool isDevLinked = !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); - log('() => isLinked: $errorMsg'); - if (!isAuthenticated) { - errorMsg = FFLocalizations.of(context).getVariableText( - ptText: 'Erro ao obter credenciais de autenticação', - enText: 'Error getting authentication credentials', - ); - await DialogUtil.error(context, errorMsg); - return; - // await DialogUtil.error(context, errorMsg).whenComplete(() async => await AuthenticationService.signOut(context)); - } - if (!isDevLinked) { - errorMsg = FFLocalizations.of(context).getVariableText( - ptText: 'Não foi possível vincular o dispositivo, tente novamente.', - enText: 'Unable to link device, try again', - ); - await DialogUtil.warning(context, errorMsg); - return; - } - await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); - } - Future _handleUnavailable(BuildContext context, List locals) async { - log('() => isUnavailable'); - try { - await StorageHelper().s(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); - await StorageHelper().s(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); - await StorageHelper().s(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); - var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); - if (response.jsonBody['error'] == true) { - await StorageHelper().s(KeychainStorageKey.clientUUID.value, ''); - await StorageHelper().s(KeychainStorageKey.ownerUUID.value, ''); - await StorageHelper().s(KeychainStorageKey.clientName.value, ''); - return false; - } - if (response.jsonBody['error'] == false) return await processData(context).then((value) => value); - } catch (e, s) { - await DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed('responderVinculo.php', '', 'Responder Vínculo', e, s); - return false; - } - return false; - } - - Future _handleEnabled(BuildContext context, dynamic local) async { - log('() => isEnabled'); - await StorageHelper().s(KeychainStorageKey.clientUUID.value, local['CLI_ID']); - await StorageHelper().s(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); - await StorageHelper().s(KeychainStorageKey.clientName.value, local['CLI_NOME']); - await StorageHelper().s(KeychainStorageKey.userName.value, local['USU_NOME']); - return await processData(context); - } - - void _logLocalsStatus(List locals) { - for (var local in locals) { - final String status = local['CLU_STATUS']; - log('() => CLU_STATUS: $status'); - } - } - - Future _updateStorageUtil(Map jsonBody) async { - try { - await StorageHelper().s(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] ?? false); - await StorageHelper().s(KeychainStorageKey.provisional.value, jsonBody['provisional'] ?? false); - await StorageHelper().s(KeychainStorageKey.pets.value, jsonBody['pet'] ?? false); - await StorageHelper().s(KeychainStorageKey.petAmount.value, - jsonBody['petAmountRegister']?.toString().isEmpty ?? true ? '0' : jsonBody['petAmountRegister'].toString()); - await StorageHelper().s(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'] ?? ''); - - final bool isNewVersion = jsonBody['newVersion'] ?? false; - await StorageHelper().s(KeychainStorageKey.isNewVersion.value, isNewVersion); - return isNewVersion; - } catch (e, s) { - log('Error in _updateStorageUtil: $e', stackTrace: s); - return false; - } - } - - bool _isActive(List locals) { - return locals.where((local) => local['CLU_STATUS'] == 'A').isNotEmpty; - } - - Future _isInactived(List locals) async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; - } - - bool _isPending(List locals) { - return locals.where((local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A').isNotEmpty; - } - - Future _isUnselected() async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - String ownerUUID = (await StorageHelper().g(KeychainStorageKey.ownerUUID.value)) ?? ''; - return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; - } - - Future _isSelected(bool isInactived) async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; - } - - Future _isAvailable() async { - String cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; - String cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - return cliUUID.isNotEmpty && cliName.isNotEmpty; - } } diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index cd711443..39916fc1 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -1,35 +1,24 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; class LocalsRepositoryImpl implements LocalsRepository { final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl(); @override - Future checkLocals(BuildContext context) async { + Future validateLocal(BuildContext context) async { return await remoteDataSource.checkLocals(context); } @override - Future processData(BuildContext context) async { - return await remoteDataSource.processData(context); - } - - @override - Future processLocals(BuildContext context) async { + Future update(BuildContext context) async { final bool response = await remoteDataSource.processLocals(context); context.read().add(LocalProfileEvent()); return response; } - @override - Future selectLocal(BuildContext context, ApiCallResponse? response) async { - return await remoteDataSource.selectLocal(context, response); - } - @override Future unlinkLocal(BuildContext context) { - return remoteDataSource.unlinkLocal(context); + return remoteDataSource.detachLocal(context); } } diff --git a/lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart b/lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart index 39577166..1862d79c 100644 --- a/lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart +++ b/lib/shared/components/molecules/locals/domain/respositories/locals_repository.dart @@ -1,10 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:hub/backend/api_requests/api_calls.dart'; abstract class LocalsRepository { - Future checkLocals(BuildContext context) async {} - Future processLocals(BuildContext context) async => false; - Future processData(BuildContext context) async => false; - Future selectLocal(BuildContext context, ApiCallResponse? response) async => false; + Future validateLocal(BuildContext context) async {} + Future update(BuildContext context) async => false; Future unlinkLocal(BuildContext context) async {} } diff --git a/lib/shared/components/molecules/locals/index.dart b/lib/shared/components/molecules/locals/index.dart index aa560630..c6e39062 100644 --- a/lib/shared/components/molecules/locals/index.dart +++ b/lib/shared/components/molecules/locals/index.dart @@ -1,3 +1,4 @@ export 'data/index.dart'; export 'domain/index.dart'; export 'presentation/index.dart'; +export 'utils/index.dart'; \ No newline at end of file diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index cd838442..b91360f2 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -24,8 +24,8 @@ class LocalProfileState { class LocalProfileBloc extends Bloc { LocalProfileBloc() : super(LocalProfileState()) { on((event, emit) async { - final cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - final cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); }); } @@ -42,8 +42,8 @@ class LocalProfileComponentModel extends FlutterFlowModel getData() async { - cliName = (await StorageHelper().g(KeychainStorageKey.clientName.value)) ?? ''; - cliUUID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; setStateCallback?.call(); } diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index d742425e..189cb702 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -22,8 +22,8 @@ class _LocalProfileComponentWidgetState extends State isLinked: $errorMsg'); + if (!isAuthenticated) { + errorMsg = FFLocalizations.of(context).getVariableText( + ptText: 'Erro ao obter credenciais de autenticação', + enText: 'Error getting authentication credentials', + ); + await DialogUtil.error(context, errorMsg); + return; + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await AuthenticationService.signOut(context)); + } + if (!isDevLinked) { + errorMsg = FFLocalizations.of(context).getVariableText( + ptText: 'Não foi possível vincular o dispositivo, tente novamente.', + enText: 'Unable to link device, try again', + ); + await DialogUtil.warning(context, errorMsg); + return; + } + await DialogUtil.error(context, errorMsg).whenComplete(() async => await LocalsRemoteDataSourceImpl().selectLocal(context, null)); + } + + static Future handleUnavailable(BuildContext context, List locals) async { + log('() => isUnavailable'); + try { + await StorageHelper().set(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); + await StorageHelper().set(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); + await StorageHelper().set(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); + var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); + if (response.jsonBody['error'] == true) { + await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerUUID.value, ''); + await StorageHelper().set(KeychainStorageKey.clientName.value, ''); + return false; + } + if (response.jsonBody['error'] == false) return await LocalsRemoteDataSourceImpl().processData(context).then((value) => value); + } catch (e, s) { + await DialogUtil.errorDefault(context); + LogUtil.requestAPIFailed('responderVinculo.php', '', 'Responder Vínculo', e, s); + return false; + } + return false; + } + + static Future handleEnabled(BuildContext context, dynamic local) async { + log('() => isEnabled'); + await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']); + await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); + await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']); + await StorageHelper().set(KeychainStorageKey.userName.value, local['USU_NOME']); + return await LocalsRemoteDataSourceImpl().processData(context); + } + + static void logLocalsStatus(List locals) { + for (var local in locals) { + final String status = local['CLU_STATUS']; + log('() => CLU_STATUS: $status'); + } + } + + static Future updateStorageUtil(Map jsonBody) async { + try { + await StorageHelper().set(KeychainStorageKey.whatsapp.value, jsonBody['whatsapp'] ?? false); + await StorageHelper().set(KeychainStorageKey.provisional.value, jsonBody['provisional'] ?? false); + await StorageHelper().set(KeychainStorageKey.pets.value, jsonBody['pet'] ?? false); + await StorageHelper().set(KeychainStorageKey.petAmount.value, + jsonBody['petAmountRegister']?.toString().isEmpty ?? true ? '0' : jsonBody['petAmountRegister'].toString()); + await StorageHelper().set(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'] ?? ''); + + final bool isNewVersion = jsonBody['newVersion'] ?? false; + await StorageHelper().set(KeychainStorageKey.isNewVersion.value, isNewVersion); + return isNewVersion; + } catch (e, s) { + log('Error in _updateStorageUtil: $e', stackTrace: s); + return false; + } + } + + static bool isActive(List locals) { + return locals.where((local) => local['CLU_STATUS'] == 'A').isNotEmpty; + } + + static Future isInactived(List locals) async { + String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + return locals.where((local) => local['CLI_ID'] != cliUUID && local['CLU_STATUS'] == 'A').isNotEmpty; + } + + static bool isPending(List locals) { + return locals.where((local) => local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A').isNotEmpty; + } + + static Future isUnselected() async { + String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + String ownerUUID = (await StorageHelper().get(KeychainStorageKey.ownerUUID.value)) ?? ''; + return cliUUID.isEmpty && cliName.isEmpty && ownerUUID.isEmpty; + } + + static Future isSelected(bool isInactived) async { + String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + return cliUUID.isNotEmpty && cliName.isNotEmpty && isInactived; + } + + static Future isAvailable() async { + String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + return cliUUID.isNotEmpty && cliName.isNotEmpty; + } + +} \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/data/data_sources/index.dart b/lib/shared/components/molecules/menu/data/data_sources/index.dart index e69de29b..8b421899 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/index.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/index.dart @@ -0,0 +1 @@ +export 'menu_local_data_source.dart'; diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart new file mode 100644 index 00000000..ebccda7b --- /dev/null +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -0,0 +1,98 @@ + + +import 'dart:developer'; + +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/extensions/dialog_extensions.dart'; +import 'package:hub/shared/services/authentication/authentication_service.dart'; +import 'package:hub/shared/utils/path_util.dart'; + +abstract class MenuLocalDataSource { + Future addMenuEntry(EnumMenuItem item, List entries, IconData icon, String text, Function() action); + Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries); + Future processDisplay(EnumMenuItem item, String display, MenuEntry opt, List entries); + Future processStartDate(String startDate, MenuEntry opt); + Future processExpirationDate(String expirationDate, MenuEntry opt); +} + +class MenuLocalDataSourceImpl implements MenuLocalDataSource { + static final MenuLocalDataSourceImpl _instance = MenuLocalDataSourceImpl._internal(); + factory MenuLocalDataSourceImpl() => _instance; + MenuLocalDataSourceImpl._internal(); + + @override + Future addMenuEntry(EnumMenuItem item, List entries, IconData icon, String text, Function() action) async { + final menuItem = item == EnumMenuItem.button + ? ButtonMenuItem(icon: icon, action: action, title: text) + : item == EnumMenuItem.card || item == EnumMenuItem.tile + ? CardMenuItem(icon: icon, action: action, title: text) + : null; + if (menuItem != null) { + entries.add(menuItem); + } + return null; + } + + @override + Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries) async { + if (opt.value == 'FRE-HUB-LOGOUT') { + await addMenuEntry(item, entries, opt.icon, opt.name, () async { + await AuthenticationService.signOut(navigatorKey.currentContext!); + }); + return true; + + } + else return false; + } + + @override + Future processDisplay(EnumMenuItem item, String display, MenuEntry opt, List entries) async { + try { + switch (display) { + case 'VISIVEL': + await addMenuEntry(item, entries, opt.icon, opt.name, () async { + await PathUtil.nav(opt.route); + }); + break; + case 'DESABILITADO': + await addMenuEntry(item, entries, opt.icon, opt.name, () async { + await DialogUnavailable.unavailableFeature(navigatorKey.currentContext!); + }); + break; + case 'INVISIVEL': + break; + } + } catch (e) { + log('Error processing display for module ${opt.value}: $e'); + } + } + + @override + Future processStartDate(String startDate, MenuEntry opt) async { + try { + if (startDate.isEmpty) return true; + final start = DateTime.tryParse(startDate); + return start != null && DateTime.now().isAfter(start); + } catch (e) { + log('Error processing start date for module ${opt.value}: $e'); + } + return false; + } + + @override + Future processExpirationDate(String expirationDate, MenuEntry opt) async { + try { + if (expirationDate.isEmpty) return false; + final expiration = DateTime.tryParse(expirationDate); + return expiration != null && DateTime.now().isAfter(expiration); + } catch (e) { + log('Error processing expiration date for module ${opt.value}: $e'); + } + return false; + } + + + +} \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/data/repositories/index.dart b/lib/shared/components/molecules/menu/data/repositories/index.dart index e69de29b..f3a81afb 100644 --- a/lib/shared/components/molecules/menu/data/repositories/index.dart +++ b/lib/shared/components/molecules/menu/data/repositories/index.dart @@ -0,0 +1 @@ +export 'menu_repository_impl.dart'; diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart new file mode 100644 index 00000000..fdf1d434 --- /dev/null +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -0,0 +1,45 @@ + + +import 'dart:developer'; + +import 'package:hub/flutter_flow/custom_functions.dart'; +import 'package:hub/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart'; +import 'package:hub/shared/components/molecules/menu/domain/respositories/menu_repository.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + + +class MenuRepositoryImpl implements MenuRepository { + final MenuLocalDataSource menuDataSource = MenuLocalDataSourceImpl(); + + + @override + Future> generateMenuEntries(List menuOptions, EnumMenuItem item) async { + List entries = []; + try { + for (var opt in menuOptions) { + final bool isDefault = await menuDataSource.processDisplayDefault(item, opt, entries); + if (isDefault) continue; + final licenseValue = await LicenseRepositoryImpl().getLicense(opt.value); + if (licenseValue != null) { + final licenseMap = await stringToMap(licenseValue); + final display = licenseMap['display'] ?? 'INVISIVEL'; + final startDate = licenseMap['startDate'] ?? ''; + final expirationDate = licenseMap['expirationDate'] ?? ''; + final isStarted = await menuDataSource.processStartDate(startDate, opt); + final isExpired = await menuDataSource.processExpirationDate(expirationDate, opt); + if (isStarted && !isExpired) { + await menuDataSource.processDisplay(item, display, opt, entries); + } + } + } + } catch (e, s) { + log('Error generating menu entries: $e', stackTrace: s); + } + return entries; + } + + + + +} \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/domain/entities/index.dart b/lib/shared/components/molecules/menu/domain/entities/index.dart index ab4ce12a..329a4c9c 100644 --- a/lib/shared/components/molecules/menu/domain/entities/index.dart +++ b/lib/shared/components/molecules/menu/domain/entities/index.dart @@ -1,3 +1 @@ -export 'menu_entry.dart'; export 'menu_item.dart'; -export 'menu_view.dart'; diff --git a/lib/shared/components/molecules/menu/domain/entities/menu_entry.dart b/lib/shared/components/molecules/menu/domain/entities/menu_entry.dart deleted file mode 100644 index 6a7bb9e7..00000000 --- a/lib/shared/components/molecules/menu/domain/entities/menu_entry.dart +++ /dev/null @@ -1,20 +0,0 @@ - -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/modules/domain/entities/base_module.dart'; - - -class MenuEntry implements BaseModule { - @override - IconData get icon => throw UnimplementedError(); - - @override - String get name => throw UnimplementedError(); - - @override - String get route => throw UnimplementedError(); - - @override - String get value => throw UnimplementedError(); -} - - diff --git a/lib/shared/components/molecules/menu/domain/entities/menu_item.dart b/lib/shared/components/molecules/menu/domain/entities/menu_item.dart index 479ce679..31b36da6 100644 --- a/lib/shared/components/molecules/menu/domain/entities/menu_item.dart +++ b/lib/shared/components/molecules/menu/domain/entities/menu_item.dart @@ -9,11 +9,11 @@ enum EnumMenuItem { MenuItem getInstance(final Function() action, final String title, final IconData icon) { switch (this) { case EnumMenuItem.button: - return MenuButtonWidget(action: action, title: title, icon: icon); + return ButtonMenuItem(action: action, title: title, icon: icon); case EnumMenuItem.card: - return MenuCardItem(action: action, title: title, icon: icon); + return CardMenuItem(action: action, title: title, icon: icon); case EnumMenuItem.tile: - return MenuCardItem(action: action, title: title, icon: icon); + return CardMenuItem(action: action, title: title, icon: icon); } } } diff --git a/lib/shared/components/molecules/menu/domain/entities/menu_view.dart b/lib/shared/components/molecules/menu/domain/entities/menu_view.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart b/lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart new file mode 100644 index 00000000..1abf171d --- /dev/null +++ b/lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart @@ -0,0 +1,6 @@ +import 'package:hub/shared/components/molecules/menu/domain/entities/menu_item.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; + +abstract class MenuRepository { + Future> generateMenuEntries(List menuOptions, EnumMenuItem item); +} \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart index fab4e6f0..fa22cbfc 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart @@ -1,17 +1,11 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:developer'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/schema/enums/enums.dart'; -import 'package:hub/flutter_flow/custom_functions.dart'; -import 'package:hub/flutter_flow/flutter_flow_util.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import 'package:hub/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; -import 'package:hub/shared/extensions/dialog_extensions.dart'; -import 'package:hub/shared/services/authentication/authentication_service.dart'; + class MenuViewEvent {} @@ -32,15 +26,14 @@ class MenuViewState { class MenuViewBloc extends Bloc { final MenuView style; final EnumMenuItem item; - final bool expandable; final List menuOptions; late StreamSubscription _completer; - MenuViewBloc({required this.style, required this.item, required this.expandable, required this.menuOptions}) : super(MenuViewState()) { + MenuViewBloc({required this.style, required this.item, required this.menuOptions}) : super(MenuViewState()) { on((event, emit) async { await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - final entries = await generateMenuEntries(); + final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); emit(state.copyWith(menuEntries: entries)); }); @@ -54,104 +47,6 @@ class MenuViewBloc extends Bloc { _completer.cancel(); return super.close(); } + - Future addMenuEntry(List entries, IconData icon, String text, Function() action) async { - entries.add( - item == EnumMenuItem.button - ? MenuButtonWidget(icon: icon, action: action, title: text) - : item == EnumMenuItem.card - ? MenuCardItem(icon: icon, action: action, title: text) - : item == EnumMenuItem.tile - ? MenuCardItem(icon: icon, action: action, title: text) - : null, - ); - return null; - } - - Future> generateMenuEntries() async { - List entries = []; - try { - for (var opt in menuOptions) { - String? licenseValue = await LicenseRepositoryImpl().g(opt.value); - if (licenseValue != null) { - Map licenseMap = await stringToMap(licenseValue); - final String display = licenseMap['display'] ?? 'INVISIVEL'; - final String startDate = licenseMap['startDate'] ?? ''; - final String expirationDate = licenseMap['expirationDate'] ?? ''; - final bool isStarted = await processStartDate(startDate, opt); - final bool isExpired = await processExpirationDate(expirationDate, opt); - if (isStarted && !isExpired) { - await processDisplay(display, opt, entries); - } - } - } - } catch (e, s) { - log('Error generating menu entries: $e', stackTrace: s); - - } - return entries; - } - - Future processDisplay(String display, MenuEntry opt, List entries) async { - try { - switch (display) { - case 'VISIVEL': - if(opt.value == 'FRE-HUB-LOGOUT') - await addMenuEntry(entries, opt.icon, opt.name, () async { - await AuthenticationService.signOut(navigatorKey.currentContext!); - }); - else - await addMenuEntry(entries, opt.icon, opt.name, () async { - await nav(opt.route); - }); - break; - case 'DESABILITADO': - await addMenuEntry(entries, opt.icon, opt.name, () async { - await DialogUnavailable.unavailableFeature(navigatorKey.currentContext!); - }); - break; - case 'INVISIVEL': - default: - break; - } - } catch (e) { - log('Error processing display for module ${opt.value}: $e'); - } - } - - Future processStartDate(String startDate, MenuEntry opt) async { - try { - if (startDate.isEmpty) return true; - final DateTime? start = DateTime.tryParse(startDate); - if (start != null) { - return DateTime.now().isAfter(start); - } - } catch (e) { - log('Error processing start date for module ${opt.value}: $e'); - } - return false; - } - - Future processExpirationDate(String expirationDate, MenuEntry opt) async { - try { - if (expirationDate.isEmpty) return false; - final DateTime? expiration = DateTime.tryParse(expirationDate); - if (expiration != null) { - return DateTime.now().isAfter(expiration); - } - } catch (e) { - log('Error processing expiration date for module ${opt.value}: $e'); - } - return false; - } - - Future nav(String link) async { - navigatorKey.currentContext!.push(link, extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: false, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }); - } } diff --git a/lib/shared/components/molecules/menu/presentation/index.dart b/lib/shared/components/molecules/menu/presentation/index.dart index 688818c6..2bb09756 100644 --- a/lib/shared/components/molecules/menu/presentation/index.dart +++ b/lib/shared/components/molecules/menu/presentation/index.dart @@ -1,2 +1,3 @@ export 'blocs/index.dart'; export 'widgets/index.dart'; +export 'mappers/index.dart'; \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/presentation/mappers/index.dart b/lib/shared/components/molecules/menu/presentation/mappers/index.dart new file mode 100644 index 00000000..8b9365b1 --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/mappers/index.dart @@ -0,0 +1 @@ +export 'menu_entry.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart new file mode 100644 index 00000000..39b8e3c7 --- /dev/null +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -0,0 +1,219 @@ +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/modules/domain/entities/base_module.dart'; + +enum MenuEntryType { Home, Drawer, Property } + +class MenuEntry implements BaseModule { + final String value; + final IconData icon; + final String name; + final String route; + final List types; + + const MenuEntry({ + required this.value, + required this.icon, + required this.name, + required this.route, + required this.types, + }); + + static List entries = [ + MenuEntry( + value: 'FRE-HUB-MESSAGES', + icon: Icons.chat_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ), + route: '/messageHistoryPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-LIBERATIONS', + icon: Icons.how_to_reg_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ), + route: '/liberationHistory', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-RESERVATIONS', + icon: Icons.event_available, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ), + route: '/reservation', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-ACCESS', + icon: Icons.transfer_within_a_station_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ), + route: '/acessHistoryPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-PETS', + icon: Icons.pets, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ), + route: '/petsPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-PEOPLE', + icon: Icons.groups, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ), + route: '/peopleOnThePropertyPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-ORDERS', + icon: Icons.inventory_2_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ), + route: '/packageOrder', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-COMPLETE-SCHEDULE', + icon: Icons.event, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agenda Completa', + enText: 'Complete Schedule', + ), + route: '/scheduleCompleteVisitPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-AGE-PROV-PRESTADOR', + icon: Icons.engineering_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Prestadores', + enText: 'Schedule Providers', + ), + route: '/provisionalSchedule', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-AGE-PROV-DELIVERY', + icon: Icons.sports_motorsports_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Agendar Delivery', + enText: 'Schedule Delivery', + ), + route: '/deliverySchedule', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-FASTPASS', + icon: Icons.attach_email_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Fast Pass', + enText: 'Fast Pass', + ), + route: '/fastPassPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-QRCODE', + icon: Icons.qr_code, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ), + route: '/qrCodePage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-VISITORS', + icon: Icons.person_add_alt_1_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Cadastrar Visitantes', + enText: 'Register Visitors', + ), + route: '/registerVisitorPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-PROPERTY', + icon: Icons.home, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sobre a Propriedade', + enText: 'About the Property', + ), + route: '/aboutProperty', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-SETTINGS', + icon: Icons.settings, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Configurações', + enText: 'Settings', + ), + route: '/preferencesSettings', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-LOGOUT', + icon: Icons.exit_to_app, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Sair', + enText: 'Logout', + ), + route: '/WelcomePage', + types: [MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-RESIDENTS', + icon: Icons.groups, + name: 'Residents', + route: '/residentsOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + value: 'FRE-HUB-VEHICLES', + icon: Icons.directions_car, + name: 'Vehicles', + route: '/vehiclesOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + value: 'FRE-HUB-OPENED-VISITS', + icon: Icons.perm_contact_calendar, + name: 'Opened Visits', + route: '/openedVisitsPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + value: 'FRE-HUB-PETS-HISTORY', + icon: Icons.pets, + name: 'Pets History', + route: '/petsOnThePropertyPage', + types: [MenuEntryType.Property], + ), + ]; + + static List getEntriesByType(MenuEntryType type) { + return entries.where((entry) => entry.types.contains(type)).toList(); + } +} + + diff --git a/lib/shared/components/molecules/menu/presentation/widgets/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/index.dart index 3101060a..800e0aa8 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/index.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/index.dart @@ -1,4 +1,4 @@ export 'menu_item/index.dart'; export 'menu_view/index.dart'; -export 'menu_factory/index.dart'; -export 'menu_entry/index.dart'; + +export 'menu_factory.dart'; \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart deleted file mode 100644 index 5b86aae6..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/drawer_menu_entry.dart +++ /dev/null @@ -1,228 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; - -enum DrawerMenuEntries implements MenuEntry { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - peopleOnTheProperty, - settings, - logout; - - @override - String get value { - switch (this) { - case DrawerMenuEntries.messages: - return 'FRE-HUB-MESSAGES'; - case DrawerMenuEntries.liberations: - return 'FRE-HUB-LIBERATIONS'; - case DrawerMenuEntries.reservations: - return 'FRE-HUB-RESERVATIONS'; - case DrawerMenuEntries.access: - return 'FRE-HUB-ACCESS'; - case DrawerMenuEntries.pets: - return 'FRE-HUB-PETS'; - case DrawerMenuEntries.orders: - return 'FRE-HUB-ORDERS'; - case DrawerMenuEntries.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case DrawerMenuEntries.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case DrawerMenuEntries.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case DrawerMenuEntries.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case DrawerMenuEntries.fastPass: - return 'FRE-HUB-FASTPASS'; - case DrawerMenuEntries.visitors: - return 'FRE-HUB-VISITORS'; - case DrawerMenuEntries.qrCode: - return 'FRE-HUB-QRCODE'; - case DrawerMenuEntries.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - case DrawerMenuEntries.settings: - return 'FRE-HUB-SETTINGS'; - case DrawerMenuEntries.logout: - return 'FRE-HUB-LOGOUT'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case DrawerMenuEntries.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case DrawerMenuEntries.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case DrawerMenuEntries.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case DrawerMenuEntries.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case DrawerMenuEntries.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case DrawerMenuEntries.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case DrawerMenuEntries.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case DrawerMenuEntries.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case DrawerMenuEntries.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case DrawerMenuEntries.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case DrawerMenuEntries.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case DrawerMenuEntries.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case DrawerMenuEntries.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case DrawerMenuEntries.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case DrawerMenuEntries.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - case DrawerMenuEntries.logout: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sair', - enText: 'Logout', - ); - } - } - - @override - IconData get icon { - switch (this) { - case DrawerMenuEntries.messages: - return Icons.chat_outlined; - case DrawerMenuEntries.liberations: - return Icons.how_to_reg_outlined; - case DrawerMenuEntries.reservations: - return Icons.event_available; - case DrawerMenuEntries.access: - return Icons.transfer_within_a_station_outlined; - case DrawerMenuEntries.pets: - return Icons.pets; - case DrawerMenuEntries.peopleOnTheProperty: - return Icons.groups; - case DrawerMenuEntries.orders: - return Icons.inventory_2_outlined; - case DrawerMenuEntries.completeSchedule: - return Icons.event; - case DrawerMenuEntries.providerSchedule: - return Icons.engineering_outlined; - case DrawerMenuEntries.deliverySchedule: - return Icons.sports_motorsports_outlined; - case DrawerMenuEntries.fastPass: - return Icons.attach_email_outlined; - case DrawerMenuEntries.qrCode: - return Icons.qr_code; - case DrawerMenuEntries.visitors: - return Icons.person_add_alt_1_outlined; - case DrawerMenuEntries.aboutProperty: - return Icons.home; - case DrawerMenuEntries.settings: - return Icons.settings; - case DrawerMenuEntries.logout: - return Icons.exit_to_app; - } - } - - @override - String get route { - switch (this) { - case DrawerMenuEntries.messages: - return '/messageHistoryPage'; - case DrawerMenuEntries.liberations: - return '/liberationHistory'; - case DrawerMenuEntries.reservations: - return '/reservation'; - case DrawerMenuEntries.access: - return '/acessHistoryPage'; - case DrawerMenuEntries.pets: - return '/petsPage'; - case DrawerMenuEntries.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case DrawerMenuEntries.orders: - return '/packageOrder'; - case DrawerMenuEntries.completeSchedule: - return '/scheduleCompleteVisitPage'; - case DrawerMenuEntries.providerSchedule: - return '/provisionalSchedule'; - case DrawerMenuEntries.aboutProperty: - return '/aboutProperty'; - case DrawerMenuEntries.deliverySchedule: - return '/deliverySchedule'; - case DrawerMenuEntries.fastPass: - return '/fastPassPage'; - case DrawerMenuEntries.qrCode: - return '/qrCodePage'; - case DrawerMenuEntries.visitors: - return '/registerVisitorPage'; - case DrawerMenuEntries.settings: - return '/preferencesSettings'; - case DrawerMenuEntries.logout: - return '/WelcomePage'; - default: - return ''; - } - } - -} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart deleted file mode 100644 index 3915c3d9..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/home_menu_entry.dart +++ /dev/null @@ -1,217 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; - -enum HomeMenuEntries implements MenuEntry { - providerSchedule, - deliverySchedule, - fastPass, - completeSchedule, - orders, - reservations, - visitors, - qrCode, - pets, - access, - liberations, - messages, - aboutProperty, - peopleOnTheProperty, - settings; - - @override - String get value { - switch (this) { - case HomeMenuEntries.messages: - return 'FRE-HUB-MESSAGES'; - case HomeMenuEntries.liberations: - return 'FRE-HUB-LIBERATIONS'; - case HomeMenuEntries.reservations: - return 'FRE-HUB-RESERVATIONS'; - case HomeMenuEntries.access: - return 'FRE-HUB-ACCESS'; - case HomeMenuEntries.pets: - return 'FRE-HUB-PETS'; - case HomeMenuEntries.orders: - return 'FRE-HUB-ORDERS'; - case HomeMenuEntries.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case HomeMenuEntries.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case HomeMenuEntries.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case HomeMenuEntries.aboutProperty: - return 'FRE-HUB-PROPERTY'; - case HomeMenuEntries.fastPass: - return 'FRE-HUB-FASTPASS'; - case HomeMenuEntries.visitors: - return 'FRE-HUB-VISITORS'; - case HomeMenuEntries.qrCode: - return 'FRE-HUB-QRCODE'; - case HomeMenuEntries.peopleOnTheProperty: - return 'FRE-HUB-PEOPLE'; - case HomeMenuEntries.settings: - return 'FRE-HUB-SETTINGS'; - default: - return ''; - } - } - - @override - String get name { - switch (this) { - case HomeMenuEntries.messages: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ); - case HomeMenuEntries.liberations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ); - case HomeMenuEntries.reservations: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ); - case HomeMenuEntries.access: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ); - case HomeMenuEntries.pets: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ); - case HomeMenuEntries.peopleOnTheProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ); - case HomeMenuEntries.orders: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ); - case HomeMenuEntries.completeSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ); - case HomeMenuEntries.providerSchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Prestadores', - enText: 'Schedule Providers', - ); - case HomeMenuEntries.deliverySchedule: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agendar Delivery', - enText: 'Schedule Delivery', - ); - case HomeMenuEntries.fastPass: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Fast Pass', - enText: 'Fast Pass', - ); - case HomeMenuEntries.qrCode: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', - ); - case HomeMenuEntries.visitors: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Cadastrar Visitantes', - enText: 'Register Visitors', - ); - case HomeMenuEntries.aboutProperty: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Sobre a Propriedade', - enText: 'About the Property', - ); - case HomeMenuEntries.settings: - return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Configurações', - enText: 'Settings', - ); - } - } - - @override - IconData get icon { - switch (this) { - case HomeMenuEntries.messages: - return Icons.chat_outlined; - case HomeMenuEntries.liberations: - return Icons.how_to_reg_outlined; - case HomeMenuEntries.reservations: - return Icons.event_available; - case HomeMenuEntries.access: - return Icons.transfer_within_a_station_outlined; - case HomeMenuEntries.pets: - return Icons.pets; - case HomeMenuEntries.peopleOnTheProperty: - return Icons.groups; - case HomeMenuEntries.orders: - return Icons.inventory_2_outlined; - case HomeMenuEntries.completeSchedule: - return Icons.event; - case HomeMenuEntries.providerSchedule: - return Icons.engineering_outlined; - case HomeMenuEntries.deliverySchedule: - return Icons.sports_motorsports_outlined; - case HomeMenuEntries.fastPass: - return Icons.attach_email_outlined; - case HomeMenuEntries.qrCode: - return Icons.qr_code; - case HomeMenuEntries.visitors: - return Icons.person_add_alt_1_outlined; - case HomeMenuEntries.aboutProperty: - return Icons.home; - case HomeMenuEntries.settings: - return Icons.settings; - } - } - - @override - String get route { - switch (this) { - case HomeMenuEntries.messages: - return '/messageHistoryPage'; - case HomeMenuEntries.liberations: - return '/liberationHistory'; - case HomeMenuEntries.reservations: - return '/reservation'; - case HomeMenuEntries.access: - return '/acessHistoryPage'; - case HomeMenuEntries.pets: - return '/petsPage'; - case HomeMenuEntries.peopleOnTheProperty: - return '/peopleOnThePropertyPage'; - case HomeMenuEntries.orders: - return '/packageOrder'; - case HomeMenuEntries.completeSchedule: - return '/scheduleCompleteVisitPage'; - case HomeMenuEntries.providerSchedule: - return '/provisionalSchedule'; - case HomeMenuEntries.aboutProperty: - return '/aboutProperty'; - case HomeMenuEntries.deliverySchedule: - return '/deliverySchedule'; - case HomeMenuEntries.fastPass: - return '/fastPassPage'; - case HomeMenuEntries.qrCode: - return '/qrCodePage'; - case HomeMenuEntries.visitors: - return '/registerVisitorPage'; - case HomeMenuEntries.settings: - return '/preferencesSettings'; - default: - return ''; - } - } - - -} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart deleted file mode 100644 index 9b5d30cf..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/index.dart +++ /dev/null @@ -1,4 +0,0 @@ -export 'drawer_menu_entry.dart'; -export 'home_menu_entry.dart'; -export 'property_menu_entry.dart'; -export 'menu_entry_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart deleted file mode 100644 index 88d11129..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/menu_entry_factory.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; - -enum MenuEntries { - home, - drawer, - AboutProperty; - - List get getValues { - switch (this) { - case MenuEntries.home: - return HomeMenuEntries.values.toList(); - case MenuEntries.drawer: - return DrawerMenuEntries.values.toList(); - case MenuEntries.AboutProperty: - return AboutPropertyMenuEntries.values.toList(); - } - } -} - -class MenuEntryFactory { - static List createMenuEntry(MenuEntry type) { - switch (type) { - case HomeMenuEntries _: - return HomeMenuEntries.values.toList(); - case DrawerMenuEntries _: - return DrawerMenuEntries.values.toList(); - case AboutPropertyMenuEntries _: - return AboutPropertyMenuEntries.values.toList(); - default: - throw ArgumentError('Invalid menu entry type'); - } - } - - List buildMenuEntry(MenuEntry type) { - return createMenuEntry(type); - } -} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart deleted file mode 100644 index 5830a53d..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_entry/property_menu_entry.dart +++ /dev/null @@ -1,69 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; - -enum AboutPropertyMenuEntries implements MenuEntry { - residents, - vehicles, - openedVisits, - petsHistory; - - @override - String get value { - switch (this) { - case AboutPropertyMenuEntries.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case AboutPropertyMenuEntries.vehicles: - return 'FRE-HUB-VEHICLES'; - case AboutPropertyMenuEntries.residents: - return 'FRE-HUB-RESIDENTS'; - case AboutPropertyMenuEntries.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - default: - return ''; - } - } - - @override - IconData get icon { - switch (this) { - case AboutPropertyMenuEntries.residents: - return Icons.groups; - case AboutPropertyMenuEntries.vehicles: - return Icons.directions_car; - case AboutPropertyMenuEntries.openedVisits: - return Icons.perm_contact_calendar; - case AboutPropertyMenuEntries.petsHistory: - return Icons.pets; - } - } - - @override - String get name { - switch (this) { - case AboutPropertyMenuEntries.residents: - return 'Residents'; - case AboutPropertyMenuEntries.vehicles: - return 'Vehicles'; - case AboutPropertyMenuEntries.openedVisits: - return 'Opened Visits'; - case AboutPropertyMenuEntries.petsHistory: - return 'Pets History'; - } - } - - @override - String get route { - switch (this) { - case AboutPropertyMenuEntries.residents: - return '/residentsOnThePropertyPage'; - case AboutPropertyMenuEntries.vehicles: - return '/vehiclesOnThePropertyPage'; - case AboutPropertyMenuEntries.openedVisits: - return '/openedVisitsPage'; - case AboutPropertyMenuEntries.petsHistory: - return '/petsOnThePropertyPage'; - } - } - - -} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart similarity index 87% rename from lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart rename to lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart index 23eb2f8c..927fda08 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_view_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart @@ -7,17 +7,15 @@ import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/utils/loading_util.dart'; -class MenuViewFactory extends StatelessWidget { +class Menufactory extends StatelessWidget { final MenuView view; final EnumMenuItem item; - final bool expandable; - final MenuEntries entry; + final List entry; - const MenuViewFactory({ + const Menufactory({ super.key, required this.view, required this.item, - required this.expandable, required this.entry, }); @@ -49,15 +47,13 @@ class MenuViewFactory extends StatelessWidget { create: (context) => MenuViewBloc( style: view, item: item, - menuOptions: entry.getValues, - expandable: expandable, + menuOptions: entry, )..add(MenuViewEvent()), child: BlocBuilder( builder: (context, state) { if (view == MenuView.list_grid) { return MenuStaggeredView( options: state.menuEntries, - expandable: expandable, item: item, changeMenuStyle: () async {}, isGrid: state.isGrid, @@ -65,7 +61,6 @@ class MenuViewFactory extends StatelessWidget { } else if (view == MenuView.list) { return MenuListView( options: state.menuEntries, - expandable: expandable, item: item, changeMenuStyle: () async {}, ); diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart deleted file mode 100644 index aa113121..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/index.dart +++ /dev/null @@ -1 +0,0 @@ -export 'menu_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart deleted file mode 100644 index d5fd0458..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory/menu_factory.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; - -class MenuFactory extends StatelessWidget { - final MenuView menuView; - final MenuEntries menuEntry; - final EnumMenuItem menuItem; - - const MenuFactory({ - super.key, - required this.menuView, - required this.menuEntry, - required this.menuItem, - }); - - @override - Widget build(BuildContext context) { - return MenuViewFactory( - view: menuView, - item: menuItem, - expandable: false, - entry: menuEntry, - ); - } -} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart index 375b35a2..6380393e 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/index.dart @@ -1,3 +1,2 @@ export 'menu_item_button.dart'; export 'menu_item_card.dart'; -export 'menu_item_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart index d95720e6..f5204eca 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart @@ -4,8 +4,8 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; -class MenuButtonWidget extends MenuItem { - const MenuButtonWidget({ +class ButtonMenuItem extends MenuItem { + const ButtonMenuItem({ super.key, required this.action, required this.title, @@ -23,7 +23,7 @@ class MenuButtonWidget extends MenuItem { _MenuButtonWidgetState createState() => _MenuButtonWidgetState(); } -class _MenuButtonWidgetState extends State { +class _MenuButtonWidgetState extends State { bool _isProcessing = false; @override diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart index b8031eac..074d5a22 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart @@ -4,8 +4,8 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; -class MenuCardItem extends MenuItem { - const MenuCardItem({ +class CardMenuItem extends MenuItem { + const CardMenuItem({ super.key, required this.action, required this.title, @@ -23,7 +23,7 @@ class MenuCardItem extends MenuItem { _MenuCardItemState createState() => _MenuCardItemState(); } -class _MenuCardItemState extends State { +class _MenuCardItemState extends State { bool _isProcessing = false; @override diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart deleted file mode 100644 index dfebce2b..00000000 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_factory.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; - -class MenuItemFactory { - static MenuItem createMenuItem( - EnumMenuItem type, { - Key? key, - required Function() action, - required String title, - required IconData icon, - }) { - return MenuItem.create(type, key: key, action: action, title: title, icon: icon); - } - - MenuItem buildMenuItem( - EnumMenuItem type, { - Key? key, - required Function() action, - required String title, - required IconData icon, - }) { - return createMenuItem(type, key: key, action: action, title: title, icon: icon); - } -} diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart index 43bd7226..fae17fc0 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/index.dart @@ -1,3 +1,2 @@ export 'menu_list_view.dart'; export 'menu_staggered_view.dart'; -export 'menu_view_factory.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart index c8c836db..277fd2c3 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_list_view.dart @@ -19,12 +19,10 @@ class MenuListView extends StatefulWidget { const MenuListView({ super.key, required this.changeMenuStyle, - required this.expandable, required this.item, required this.options, }); - final bool expandable; final EnumMenuItem item; final List options; final Future Function()? changeMenuStyle; diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart index 1d279b70..fbaf5056 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_view/menu_staggered_view.dart @@ -13,9 +13,8 @@ class MenuStaggeredViewModel extends FlutterFlowModel { } class MenuStaggeredView extends StatefulWidget { - const MenuStaggeredView({super.key, required this.changeMenuStyle, required this.expandable, required this.item, required this.options, required this.isGrid}); + const MenuStaggeredView({super.key, required this.changeMenuStyle, required this.item, required this.options, required this.isGrid}); - final bool expandable; final EnumMenuItem item; final bool isGrid; final List options; diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 13000803..06cc2e68 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -7,7 +7,7 @@ import 'package:sqflite/sqflite.dart'; abstract class LicenseLocalDataSource { Future init(); - Future setByKey(final List key, final String display); + Future setDisplayByKey(final List key, final String display); Future isNewVersion(); Future g(String key); Future s(String key, T value); @@ -25,7 +25,7 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { await DatabaseStorage.instance.init(); } - Future setByKey(final List key, final String display) async { + Future setDisplayByKey(final List key, final String display) async { if (key.isEmpty) return; for (var element in key) { if (element != null) { diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 18ca868c..8755b436 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -55,13 +55,13 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { .map((module) => module.key) .toList(); - await LicenseLocalDataSourceImpl().setByKey(inactiveModuleKey, 'INVISIVEL'); - await LicenseLocalDataSourceImpl().setByKey(activeModuleKey, 'VISIVEL'); + await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL'); + await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL'); if (isNewVersion == true) { - await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'VISIVEL'); - await LicenseLocalDataSourceImpl().setByKey(['FRE-HUB-PROPERTY'], 'VISIVEL'); + await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'VISIVEL'); + await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-PROPERTY'], 'VISIVEL'); } else { - await LicenseLocalDataSourceImpl().setByKey(disabledModuleKey, 'DESABILITADO'); + await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO'); } LicenseRepositoryImpl.license.add(true); diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index dcd97a3e..8cb1c549 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -17,23 +17,24 @@ class LicenseRepositoryImpl implements LicenseRepository { static final license = BehaviorSubject(); static get stream => license.stream; - Future fetchLicense(bool isNewVersion) async { - return await remoteDataSource.fetchLicenses(isNewVersion); - } + Future updateLicense(bool isNewVersion) async { + await remoteDataSource.setupLicense(database, isNewVersion); + if (isNewVersion) { + return await remoteDataSource.fetchLicenses(isNewVersion); + } + return false; - Future setupLicense(bool isNewVersion) async { - return await remoteDataSource.setupLicense(database, isNewVersion); } Future cleanLicense() async { return await remoteDataSource.cleanLicense(); } - Future g(String key) async { + Future getLicense(String key) async { return await localDataSource.g(key); } - Future s(String key, T value) async { + Future setLicense(String key, T value) async { return await localDataSource.s(key, value); } } diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 49306773..1c3d6410 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -1,81 +1,41 @@ import 'package:hub/shared/extensions/string_extensions.dart'; -import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'module.dart'; enum LicenseKeys { - messages, - liberations, - reservations, - access, - openedVisits, - vehicles, - residents, - pets, - orders, - completeSchedule, - providerSchedule, - deliverySchedule, - property, - fastPass, - visitors, - qrCode, - people, - petsHistory, - settings, - logout, + + messages('FRE-HUB-MESSAGES'), + liberations('FRE-HUB-LIBERATIONS'), + reservations('FRE-HUB-RESERVATIONS'), + access('FRE-HUB-ACCESS'), + openedVisits('FRE-HUB-OPENED-VISITS'), + vehicles('FRE-HUB-VEHICLES'), + residents('FRE-HUB-RESIDENTS'), + pets('FRE-HUB-PETS'), + orders('FRE-HUB-ORDERS'), + completeSchedule('FRE-HUB-COMPLETE-SCHEDULE'), + providerSchedule('FRE-HUB-AGE-PROV-PRESTADOR'), + deliverySchedule('FRE-HUB-AGE-PROV-DELIVERY'), + property('FRE-HUB-PROPERTY'), + fastPass('FRE-HUB-FASTPASS'), + visitors('FRE-HUB-VISITORS'), + qrCode('FRE-HUB-QRCODE'), + people('FRE-HUB-PEOPLE'), + petsHistory('FRE-HUB-PETS-HISTORY'), + settings('FRE-HUB-SETTINGS'), + logout('FRE-HUB-LOGOUT'); + + + final String value; + const LicenseKeys(this.value); } -extension LicenseKeysExtension on LicenseKeys { - String get value { - switch (this) { - case LicenseKeys.messages: - return 'FRE-HUB-MESSAGES'; - case LicenseKeys.liberations: - return 'FRE-HUB-LIBERATIONS'; - case LicenseKeys.reservations: - return 'FRE-HUB-RESERVATIONS'; - case LicenseKeys.access: - return 'FRE-HUB-ACCESS'; - case LicenseKeys.openedVisits: - return 'FRE-HUB-OPENED-VISITS'; - case LicenseKeys.vehicles: - return 'FRE-HUB-VEHICLES'; - case LicenseKeys.residents: - return 'FRE-HUB-RESIDENTS'; - case LicenseKeys.pets: - return 'FRE-HUB-PETS'; - case LicenseKeys.orders: - return 'FRE-HUB-ORDERS'; - case LicenseKeys.completeSchedule: - return 'FRE-HUB-COMPLETE-SCHEDULE'; - case LicenseKeys.providerSchedule: - return 'FRE-HUB-AGE-PROV-PRESTADOR'; - case LicenseKeys.deliverySchedule: - return 'FRE-HUB-AGE-PROV-DELIVERY'; - case LicenseKeys.property: - return 'FRE-HUB-PROPERTY'; - case LicenseKeys.fastPass: - return 'FRE-HUB-FASTPASS'; - case LicenseKeys.visitors: - return 'FRE-HUB-VISITORS'; - case LicenseKeys.qrCode: - return 'FRE-HUB-QRCODE'; - case LicenseKeys.people: - return 'FRE-HUB-PEOPLE'; - case LicenseKeys.petsHistory: - return 'FRE-HUB-PETS-HISTORY'; - case LicenseKeys.settings: - return 'FRE-HUB-SETTINGS'; - case LicenseKeys.logout: - return 'FRE-HUB-LOGOUT'; - } - } -} + + class License { final List modules; @@ -84,28 +44,6 @@ class License { this.modules, ); - // static List mods = [ - // 'FRE-HUB-MESSAGES', - // 'FRE-HUB-LIBERATIONS', - // 'FRE-HUB-RESERVATIONS', - // 'FRE-HUB-ACCESS', - // 'FRE-HUB-OPENED-VISITS', - // 'FRE-HUB-VEHICLES', - // 'FRE-HUB-RESIDENTS', - // 'FRE-HUB-PETS', - // 'FRE-HUB-ORDERS', - // 'FRE-HUB-COMPLETE-SCHEDULE', - // 'FRE-HUB-AGE-PROV-PRESTADOR', - // 'FRE-HUB-AGE-PROV-DELIVERY', - // 'FRE-HUB-PROPERTY', - // 'FRE-HUB-FASTPASS', - // 'FRE-HUB-VISITORS', - // 'FRE-HUB-QRCODE', - // 'FRE-HUB-PEOPLE', - // 'FRE-HUB-PETS-HISTORY' - // 'FRE-HUB-SETTINGS', - // 'FRE-HUB-LOGOUT', - // ]; static Future _proceessOldVersion(LicenseKeys key) async { switch(key) { @@ -125,22 +63,25 @@ class License { } static Future _precessWpp() async { - final bool whatsapp = await StorageHelper().g(KeychainStorageKey.whatsapp.value).then((v) => v.toBoolean()); + final bool whatsapp = await StorageHelper().get(KeychainStorageKey.whatsapp.value).then((v) => v.toBoolean()); if (whatsapp) return ModuleStatus.active.key; else return ModuleStatus.inactive.key; } static Future _processProvisional() async { - final bool provisional = await StorageHelper().g(KeychainStorageKey.provisional.value).then((v) => v.toBoolean()); + final bool provisional = await StorageHelper().get(KeychainStorageKey.provisional.value).then((v) => v.toBoolean()); if (provisional) return ModuleStatus.active.key; else return ModuleStatus.inactive.key; } static Future _processPets() async { - final bool pets = await StorageHelper().g(KeychainStorageKey.pets.value).then((v) => v.toBoolean()); + final bool pets = await StorageHelper().get(KeychainStorageKey.pets.value).then((v) => v.toBoolean()); if (pets) return ModuleStatus.active.key; else return ModuleStatus.inactive.key; } + static getKeyByModule(String s) { + + } static Future getLicense(bool isNewVersion) async { @@ -290,588 +231,3 @@ class License { } } -// import 'package:equatable/equatable.dart'; -// import 'module.dart'; - -// import 'package:flutter/material.dart'; -// import 'package:hub/flutter_flow/internationalization.dart'; -// import 'package:hub/flutter_flow/nav/nav.dart'; -// import 'package:hub/shared/components/molecules/modules/index.dart'; - -// enum ModuleStatus { active, inactive, disabled } - -// extension ModuleStatusExtension on ModuleStatus { -// String get value { -// switch (this) { -// case ModuleStatus.active: -// return 'VISIVEL'; -// case ModuleStatus.inactive: -// return 'INVISIVEL'; -// case ModuleStatus.disabled: -// return 'DESABILITADO'; -// } -// } -// } - -// class ModuleExt { -// final String value; -// final String name; -// final IconData icon; -// final String route; -// final (ModuleStatus inOldVersion, ModuleStatus inNewVersion) status; - -// const ModuleExt({ -// required this.value, -// required this.name, -// required this.icon, -// required this.route, -// required this.status, -// }); - -// static List get license => [ -// ModuleExt( -// value: 'FRE-HUB-MESSAGES', -// name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Consultar Mensagens', -// enText: 'Messages History', -// ), -// icon: Icons.chat_outlined, -// route: '/messageHistoryPage', -// status: (ModuleStatus.active, ModuleStatus.disabled), -// ), -// ]; -// } - -// enum EModule implements BaseModule { -// providerSchedule, -// deliverySchedule, -// fastPass, -// completeSchedule, -// orders, -// reservations, -// visitors, -// vehicles, -// residents, -// openedVisits, -// qrCode, -// pets, -// access, -// liberations, -// messages, -// aboutProperty, -// petsHistory, -// peopleOnTheProperty, -// settings, -// logout; - -// @override -// String get value { -// switch (this) { -// case Module.messages: -// return 'FRE-HUB-MESSAGES'; -// case Module.liberations: -// return 'FRE-HUB-LIBERATIONS'; -// case Module.reservations: -// return 'FRE-HUB-RESERVATIONS'; -// case Module.access: -// return 'FRE-HUB-ACCESS'; -// case Module.openedVisits: -// return 'FRE-HUB-OPENED-VISITS'; -// case Module.vehicles: -// return 'FRE-HUB-VEHICLES'; -// case Module.residents: -// return 'FRE-HUB-RESIDENTS'; -// case Module.pets: -// return 'FRE-HUB-PETS'; -// case Module.orders: -// return 'FRE-HUB-ORDERS'; -// case Module.completeSchedule: -// return 'FRE-HUB-COMPLETE-SCHEDULE'; -// case Module.providerSchedule: -// return 'FRE-HUB-AGE-PROV-PRESTADOR'; -// case Module.deliverySchedule: -// return 'FRE-HUB-AGE-PROV-DELIVERY'; -// case Module.aboutProperty: -// return 'FRE-HUB-PROPERTY'; -// case Module.fastPass: -// return 'FRE-HUB-FASTPASS'; -// case Module.visitors: -// return 'FRE-HUB-VISITORS'; -// case Module.qrCode: -// return 'FRE-HUB-QRCODE'; -// case Module.peopleOnTheProperty: -// return 'FRE-HUB-PEOPLE'; -// case Module.petsHistory: -// return 'FRE-HUB-PETS-HISTORY'; -// default: -// return ''; -// } -// } - -// @override -// String get name { -// switch (this) { -// case Module.messages: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Consultar Mensagens', -// enText: 'Messages History', -// ); -// case Module.liberations: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Consultar Liberações', -// enText: 'Liberations History', -// ); -// case Module.reservations: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Reservas', -// enText: 'Reservations', -// ); -// case Module.access: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Consultar Acessos', -// enText: 'Access History', -// ); -// case Module.openedVisits: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Visitas em Aberto', -// enText: 'Opened Visits', -// ); -// case Module.vehicles: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Veículos', -// enText: 'Vehicles', -// ); -// case Module.residents: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Moradores', -// enText: 'Residents', -// ); -// case Module.pets: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Pets', -// enText: 'Pets', -// ); -// case Module.petsHistory: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Pets', -// enText: 'Pets', -// ); -// case Module.peopleOnTheProperty: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Pessoas na Propriedade', -// enText: 'People on the Property', -// ); -// case Module.orders: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Minhas Encomendas', -// enText: 'My Orders', -// ); -// case Module.completeSchedule: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Agenda Completa', -// enText: 'Complete Schedule', -// ); -// case Module.providerSchedule: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Agendar Prestadores', -// enText: 'Schedule Providers', -// ); -// case Module.deliverySchedule: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Agendar Delivery', -// enText: 'Schedule Delivery', -// ); -// case Module.fastPass: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Fast Pass', -// enText: 'Fast Pass', -// ); -// case Module.qrCode: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'QRCode de Acesso', -// enText: 'Access QRCode', -// ); -// case Module.visitors: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Cadastrar Visitantes', -// enText: 'Register Visitors', -// ); -// case Module.aboutProperty: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Sobre a Propriedade', -// enText: 'About the Property', -// ); -// case Module.settings: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Configurações', -// enText: 'Settings', -// ); -// case Module.logout: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Sair', -// enText: 'Logout', -// ); -// } -// } - -// @override -// IconData get icon { -// switch (this) { -// case Module.messages: -// return Icons.chat_outlined; -// case Module.liberations: -// return Icons.how_to_reg_outlined; -// case Module.reservations: -// return Icons.event_available; -// case Module.access: -// return Icons.transfer_within_a_station_outlined; -// case Module.openedVisits: -// return Icons.perm_contact_calendar; -// case Module.vehicles: -// return Icons.directions_car; -// case Module.residents: -// return Icons.groups; -// case Module.pets: -// return Icons.pets; -// case Module.petsHistory: -// return Icons.pets; -// case Module.peopleOnTheProperty: -// return Icons.groups; -// case Module.orders: -// return Icons.inventory_2_outlined; -// case Module.completeSchedule: -// return Icons.event; -// case Module.providerSchedule: -// return Icons.engineering_outlined; -// case Module.deliverySchedule: -// return Icons.sports_motorsports_outlined; -// case Module.fastPass: -// return Icons.attach_email_outlined; -// case Module.qrCode: -// return Icons.qr_code; -// case Module.visitors: -// return Icons.person_add_alt_1_outlined; -// case Module.aboutProperty: -// return Icons.home; -// case Module.settings: -// return Icons.settings; -// case Module.logout: -// return Icons.logout; -// } -// } - -// @override -// String get route { -// switch (this) { -// case Module.messages: -// return '/messageHistoryPage'; -// case Module.liberations: -// return '/liberationHistory'; -// case Module.reservations: -// return '/reservation'; -// case Module.access: -// return '/acessHistoryPage'; -// case Module.openedVisits: -// return '/visitsOnThePropertyPage'; -// case Module.vehicles: -// return '/vehiclesOnThePropertyPage'; -// case Module.residents: -// return '/residentsOnThePropertyPage'; -// case Module.pets: -// return '/petsPage'; -// case Module.petsHistory: -// return '/petsHistoryPage'; -// case Module.peopleOnTheProperty: -// return '/peopleOnThePropertyPage'; -// case Module.orders: -// return '/packageOrder'; -// case Module.completeSchedule: -// return '/scheduleCompleteVisitPage'; -// case Module.providerSchedule: -// return '/provisionalSchedule'; -// case Module.aboutProperty: -// return '/aboutProperty'; -// case Module.deliverySchedule: -// return '/deliverySchedule'; -// case Module.fastPass: -// return '/fastPassPage'; -// case Module.qrCode: -// return '/qrCodePage'; -// case Module.visitors: -// return '/registerVisitorPage'; -// case Module.settings: -// return '/preferencesSettings'; -// case Module.logout: -// return '/WelcomePage'; -// default: -// return ''; -// } -// } -// } - -// enum ELicense implements BaseModule { -// providerSchedule, -// deliverySchedule, -// fastPass, -// completeSchedule, -// orders, -// reservations, -// visitors, -// vehicles, -// residents, -// openedVisits, -// qrCode, -// pets, -// access, -// liberations, -// messages, -// aboutProperty, -// petsHistory, -// peopleOnTheProperty, -// settings, -// logout; - -// @override -// String get value { -// switch (this) { -// case License.messages: -// return 'FRE-HUB-MESSAGES'; -// case License.liberations: -// return 'FRE-HUB-LIBERATIONS'; -// case License.reservations: -// return 'FRE-HUB-RESERVATIONS'; -// case License.access: -// return 'FRE-HUB-ACCESS'; -// case License.openedVisits: -// return 'FRE-HUB-OPENED-VISITS'; -// case License.vehicles: -// return 'FRE-HUB-VEHICLES'; -// case License.residents: -// return 'FRE-HUB-RESIDENTS'; -// case License.pets: -// return 'FRE-HUB-PETS'; -// case License.orders: -// return 'FRE-HUB-ORDERS'; -// case License.completeSchedule: -// return 'FRE-HUB-COMPLETE-SCHEDULE'; -// case License.providerSchedule: -// return 'FRE-HUB-AGE-PROV-PRESTADOR'; -// case License.deliverySchedule: -// return 'FRE-HUB-AGE-PROV-DELIVERY'; -// case License.aboutProperty: -// return 'FRE-HUB-PROPERTY'; -// case License.fastPass: -// return 'FRE-HUB-FASTPASS'; -// case License.visitors: -// return 'FRE-HUB-VISITORS'; -// case License.qrCode: -// return 'FRE-HUB-QRCODE'; -// case License.peopleOnTheProperty: -// return 'FRE-HUB-PEOPLE'; -// case License.petsHistory: -// return 'FRE-HUB-PETS-HISTORY'; -// default: -// return ''; -// } -// } - -// @override -// String get name { -// switch (this) { -// case License.messages: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Consultar Mensagens', -// enText: 'Messages History', -// ); -// case License.liberations: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Consultar Liberações', -// enText: 'Liberations History', -// ); -// case License.reservations: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Reservas', -// enText: 'Reservations', -// ); -// case License.access: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Consultar Acessos', -// enText: 'Access History', -// ); -// case License.openedVisits: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Visitas em Aberto', -// enText: 'Opened Visits', -// ); -// case License.vehicles: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Veículos', -// enText: 'Vehicles', -// ); -// case License.residents: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Moradores', -// enText: 'Residents', -// ); -// case License.pets: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Pets', -// enText: 'Pets', -// ); -// case License.petsHistory: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Pets', -// enText: 'Pets', -// ); -// case License.peopleOnTheProperty: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Pessoas na Propriedade', -// enText: 'People on the Property', -// ); -// case License.orders: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Minhas Encomendas', -// enText: 'My Orders', -// ); -// case License.completeSchedule: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Agenda Completa', -// enText: 'Complete Schedule', -// ); -// case License.providerSchedule: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Agendar Prestadores', -// enText: 'Schedule Providers', -// ); -// case License.deliverySchedule: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Agendar Delivery', -// enText: 'Schedule Delivery', -// ); -// case License.fastPass: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Fast Pass', -// enText: 'Fast Pass', -// ); -// case License.qrCode: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'QRCode de Acesso', -// enText: 'Access QRCode', -// ); -// case License.visitors: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Cadastrar Visitantes', -// enText: 'Register Visitors', -// ); -// case License.aboutProperty: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Sobre a Propriedade', -// enText: 'About the Property', -// ); -// case License.settings: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Configurações', -// enText: 'Settings', -// ); -// case License.logout: -// return FFLocalizations.of(navigatorKey.currentContext!).getVariableText( -// ptText: 'Sair', -// enText: 'Logout', -// ); -// } -// } - -// @override -// IconData get icon { -// switch (this) { -// case License.messages: -// return Icons.chat_outlined; -// case License.liberations: -// return Icons.how_to_reg_outlined; -// case License.reservations: -// return Icons.event_available; -// case License.access: -// return Icons.transfer_within_a_station_outlined; -// case License.openedVisits: -// return Icons.perm_contact_calendar; -// case License.vehicles: -// return Icons.directions_car; -// case License.residents: -// return Icons.groups; -// case License.pets: -// return Icons.pets; -// case License.petsHistory: -// return Icons.pets; -// case License.peopleOnTheProperty: -// return Icons.groups; -// case License.orders: -// return Icons.inventory_2_outlined; -// case License.completeSchedule: -// return Icons.event; -// case License.providerSchedule: -// return Icons.engineering_outlined; -// case License.deliverySchedule: -// return Icons.sports_motorsports_outlined; -// case License.fastPass: -// return Icons.attach_email_outlined; -// case License.qrCode: -// return Icons.qr_code; -// case License.visitors: -// return Icons.person_add_alt_1_outlined; -// case License.aboutProperty: -// return Icons.home; -// case License.settings: -// return Icons.settings; -// case License.logout: -// return Icons.logout; -// } -// } - -// @override -// String get route { -// switch (this) { -// case License.messages: -// return '/messageHistoryPage'; -// case License.liberations: -// return '/liberationHistory'; -// case License.reservations: -// return '/reservation'; -// case License.access: -// return '/acessHistoryPage'; -// case License.openedVisits: -// return '/visitsOnThePropertyPage'; -// case License.vehicles: -// return '/vehiclesOnThePropertyPage'; -// case License.residents: -// return '/residentsOnThePropertyPage'; -// case License.pets: -// return '/petsPage'; -// case License.petsHistory: -// return '/petsHistoryPage'; -// case License.peopleOnTheProperty: -// return '/peopleOnThePropertyPage'; -// case License.orders: -// return '/packageOrder'; -// case License.completeSchedule: -// return '/scheduleCompleteVisitPage'; -// case License.providerSchedule: -// return '/provisionalSchedule'; -// case License.aboutProperty: -// return '/aboutProperty'; -// case License.deliverySchedule: -// return '/deliverySchedule'; -// case License.fastPass: -// return '/fastPassPage'; -// case License.qrCode: -// return '/qrCodePage'; -// case License.visitors: -// return '/registerVisitorPage'; -// case License.settings: -// return '/preferencesSettings'; -// case License.logout: -// return '/WelcomePage'; -// default: -// return ''; -// } -// } -// } diff --git a/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart index 877ed320..1d1691d2 100644 --- a/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart +++ b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart @@ -1,8 +1,7 @@ abstract class LicenseRepository { - Future fetchLicense(bool isNewVersion); - Future setupLicense(bool isNewVersion); + Future updateLicense(bool isNewVersion); Future cleanLicense(); - Future g(String key); - Future s(String key, T value); + Future getLicense(String key); + Future setLicense(String key, T value); } diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 38415aa9..e3093ad5 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -32,7 +32,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - await LicenseRepositoryImpl().setupLicense(false); + await LicenseRepositoryImpl().updateLicense(false); isInitialized = true; } diff --git a/lib/shared/helpers/storage/storage_helper.dart b/lib/shared/helpers/storage/storage_helper.dart index cb5a3e1b..9600a652 100644 --- a/lib/shared/helpers/storage/storage_helper.dart +++ b/lib/shared/helpers/storage/storage_helper.dart @@ -51,19 +51,19 @@ class StorageHelper { } } - Future g(String key) async { + Future get(String key) async { return await getInstanceByKey(key).get(key); } - Future s(String key, T value) async { + Future set(String key, T value) async { return await getInstanceByKey(key).set(key, value); } - Future d(String key) async { + Future del(String key) async { return await getInstanceByKey(key).delete(key); } - Future c(Storage storage) async { + Future clean(Storage storage) async { return await getInstance(storage).clearAll(); } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 48463b0e..2053ede1 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -25,14 +25,14 @@ class AuthenticationService { List locals = response.jsonBody['locais'] ?? []; if (locals.isEmpty) { - await StorageHelper().s(SecureStorageKey.haveLocal.value, false); + await StorageHelper().set(SecureStorageKey.haveLocal.value, false); context.go('/receptionPage'); } else { - await StorageHelper().s(SecureStorageKey.haveLocal.value, true); + await StorageHelper().set(SecureStorageKey.haveLocal.value, true); context.go('/homePage'); } - await StorageHelper().s(SecureStorageKey.isLogged.value, true); + await StorageHelper().set(SecureStorageKey.isLogged.value, true); } static Future signIn( @@ -45,7 +45,7 @@ class AuthenticationService { final ApiCallResponse? response; final LoginCall callback = PhpGroup.loginCall; String deviceDescription = randomString(10, 10, true, false, false); - await StorageHelper().s(SecureStorageKey.deviceDescription.value, deviceDescription); + await StorageHelper().set(SecureStorageKey.deviceDescription.value, deviceDescription); final String? devUUID; final String userUUID; @@ -60,9 +60,9 @@ class AuthenticationService { devUUID = await DeviceUtil.getDevUUID(); if ((email != '') && (passwd != '')) { - await StorageHelper().s(SecureStorageKey.email.value, email); - await StorageHelper().s(SecureStorageKey.password.value, passwd); - await StorageHelper().s(KeychainStorageKey.devUUID.value, devUUID!); + await StorageHelper().set(SecureStorageKey.email.value, email); + await StorageHelper().set(SecureStorageKey.password.value, passwd); + await StorageHelper().set(KeychainStorageKey.devUUID.value, devUUID!); response = await callback.call(); if (response.jsonBody['error'] == false) { @@ -71,10 +71,10 @@ class AuthenticationService { userDevUUID = response.jsonBody['user']['dev_id']; userName = response.jsonBody['user']['name']; - await StorageHelper().s(KeychainStorageKey.userUUID.value, userUUID); - await StorageHelper().s(KeychainStorageKey.userDevUUID.value, userDevUUID); - await StorageHelper().s(KeychainStorageKey.status.value, status); - await StorageHelper().s(KeychainStorageKey.userName.value, userName); + await StorageHelper().set(KeychainStorageKey.userUUID.value, userUUID); + await StorageHelper().set(KeychainStorageKey.userDevUUID.value, userDevUUID); + await StorageHelper().set(KeychainStorageKey.status.value, status); + await StorageHelper().set(KeychainStorageKey.userName.value, userName); await login(context); } else { @@ -138,8 +138,8 @@ class AuthenticationService { alignment: Alignment.bottomCenter, ), }; - await StorageHelper().c(Storage.secureStorage); - await StorageHelper().c(Storage.databaseStorage); + await StorageHelper().clean(Storage.secureStorage); + await StorageHelper().clean(Storage.databaseStorage); context.go('/welcomePage', extra: extra); } diff --git a/lib/shared/utils/path_util.dart b/lib/shared/utils/path_util.dart new file mode 100644 index 00000000..4692235a --- /dev/null +++ b/lib/shared/utils/path_util.dart @@ -0,0 +1,17 @@ + +import 'package:flutter/material.dart'; +import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; + +class PathUtil { + + static Future nav(String link) async { + navigatorKey.currentContext!.push(link, extra: { + kTransitionInfoKey: const TransitionInfo( + hasTransition: false, + transitionType: PageTransitionType.scale, + alignment: Alignment.bottomCenter, + ), + }); + } +} \ No newline at end of file diff --git a/lib/shared/utils/share_util.dart b/lib/shared/utils/share_util.dart index 511e143a..e04e11bf 100644 --- a/lib/shared/utils/share_util.dart +++ b/lib/shared/utils/share_util.dart @@ -4,8 +4,8 @@ import 'package:share_plus/share_plus.dart'; class ShareUtil { static Future showShare(payload) async { - final cliName = await StorageHelper().g(KeychainStorageKey.clientName.value); - final cliUUID = await StorageHelper().g(KeychainStorageKey.clientUUID.value); + final cliName = await StorageHelper().get(KeychainStorageKey.clientName.value); + final cliUUID = await StorageHelper().get(KeychainStorageKey.clientUUID.value); for (var i = 0; i < payload['convites'].length; i++) { await Share.share(''' From cf8ce52fd7dad0553d5702af8fd46f4507ef9bf4 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 3 Dec 2024 17:47:03 -0300 Subject: [PATCH 32/75] WIP --- .../home/presentation/pages/home_page.dart | 23 +++++---- .../pages/about_property_screen.dart | 2 +- lib/main.dart | 2 + .../residents_on_the_property_screen.dart | 6 +-- .../molecules/drawer/drawer_widget.dart | 2 +- .../locals_remote_data_source.dart | 4 +- .../blocs/local_profile_bloc.dart | 23 ++++++--- .../data_sources/menu_local_data_source.dart | 8 +-- .../repositories/menu_repository_impl.dart | 2 +- .../menu/presentation/blocs/index.dart | 2 + .../menu/presentation/blocs/menu_bloc.dart | 50 ++++++++++++++++++- .../presentation/blocs/menu_view_bloc.dart | 47 ++--------------- .../menu/presentation/mappers/menu_entry.dart | 1 + .../presentation/widgets/menu_factory.dart | 6 +-- .../widgets/menu_item/menu_item_button.dart | 2 +- .../widgets/menu_item/menu_item_card.dart | 2 +- .../license_local_data_source.dart | 36 +++++++------ .../license_remote_data_source.dart | 3 +- .../repositories/license_repository_impl.dart | 7 +-- .../modules/domain/entities/base_module.dart | 2 + .../modules/domain/entities/license.dart | 2 +- .../modules/domain/entities/module.dart | 24 +++++++++ .../respositories/license_repository.dart | 2 +- .../helpers/database/database_helper.dart | 2 +- .../helpers/storage/keychain_storage.dart | 10 +++- .../helpers/storage/storage_helper.dart | 2 +- .../authentication_service.dart | 4 ++ 27 files changed, 174 insertions(+), 102 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index f63c044e..d1c2ad24 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -29,18 +29,23 @@ class _HomePageWidgetState extends State { BlocProvider( create: (context) => HomeBloc()..add(HomeEvent()), ), - BlocProvider( + BlocProvider( create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), ), ], - child: Scaffold( - key: scaffoldKey, - backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - drawerEnableOpenDragGesture: true, - drawerDragStartBehavior: DragStartBehavior.start, - drawer: CustomDrawer(), - appBar: buildAppBar(context), - body: buildPage(context), + child: Builder( + builder: (context) { + context.read().updateProfile(context); + return Scaffold( + key: scaffoldKey, + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + drawerEnableOpenDragGesture: true, + drawerDragStartBehavior: DragStartBehavior.start, + drawer: CustomDrawer(), + appBar: buildAppBar(context), + body: buildPage(context), + ); + }, ), ); } diff --git a/lib/features/property/presentation/pages/about_property_screen.dart b/lib/features/property/presentation/pages/about_property_screen.dart index dea748d2..7560cc25 100644 --- a/lib/features/property/presentation/pages/about_property_screen.dart +++ b/lib/features/property/presentation/pages/about_property_screen.dart @@ -78,7 +78,7 @@ class _AboutPropertyPageState extends State with SingleTicker child: Container( color: FlutterFlowTheme.of(context).primaryBackground, child: Menufactory( - entry: MenuEntry.getEntriesByType(MenuEntryType.Drawer), + entry: MenuEntry.getEntriesByType(MenuEntryType.Property), item: EnumMenuItem.button, view: MenuView.list_grid, ), diff --git a/lib/main.dart b/lib/main.dart index 409d2a04..324221f9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,9 +16,11 @@ import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/services/deeplink/deep_link_service.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:hub/shared/extensions/string_extensions.dart'; import 'backend/notifications/firebase_messaging_service.dart'; import 'initialization.dart'; +import 'shared/components/molecules/modules/index.dart'; final GlobalKey navigatorKey = GlobalKey(); diff --git a/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart index fb3b4696..cdc96579 100644 --- a/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart +++ b/lib/pages/residents_on_the_property/residents_on_the_property_screen.dart @@ -34,7 +34,7 @@ class _ResidentsOnThePropertyState extends State with Ti void initState() { super.initState(); model = createModel(context, () => ResidentsOnThePropertyModel(onRefresh: () => safeSetState(() {}))); - _future = _fetchVisits(); + _future = _fetch(); _scrollController = ScrollController() ..addListener(() { @@ -160,7 +160,7 @@ class _ResidentsOnThePropertyState extends State with Ti ); } - Future _fetchVisits() async { + Future _fetch() async { try { setState(() => _loading = true); @@ -202,7 +202,7 @@ class _ResidentsOnThePropertyState extends State with Ti if (_hasData == true) { _pageNumber++; - _future = _fetchVisits(); + _future = _fetch(); } } diff --git a/lib/shared/components/molecules/drawer/drawer_widget.dart b/lib/shared/components/molecules/drawer/drawer_widget.dart index 253540d1..a022f8c8 100644 --- a/lib/shared/components/molecules/drawer/drawer_widget.dart +++ b/lib/shared/components/molecules/drawer/drawer_widget.dart @@ -190,7 +190,7 @@ class CustomDrawer extends StatelessWidget { Widget _buildDrawerBody(BuildContext context) { return Menufactory( - entry: MenuEntry.getEntriesByType(MenuEntryType.Property), + entry: MenuEntry.getEntriesByType(MenuEntryType.Drawer), item: EnumMenuItem.tile, view: MenuView.list, ); diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index c2321d4d..42b16d9c 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -162,12 +162,12 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { if (isError == true) { final GetLocalsCall callback = PhpGroup.getLocalsCall; response = await callback.call(); - final String errorMsg = response.jsonBody['error_msg'] ?? 'Unknown error'; + final String errorMsg = response.jsonBody['error_msg'] ?? 'Local indisponível'; await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } else { final bool isNewVersion = await LocalUtil.updateStorageUtil(response.jsonBody); - return await LicenseRepositoryImpl().updateLicense(isNewVersion); + return await LicenseRepositoryImpl().updateLicense(); } } catch (e, s) { log('() => error processData: $e', stackTrace: s); diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index b91360f2..d79f115c 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -1,11 +1,14 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; -class LocalProfileEvent {} +class LocalProfileEvent { + +} class LocalProfileState { final String cliName; @@ -14,6 +17,7 @@ class LocalProfileState { LocalProfileState({this.cliName = '', this.cliUUID = ''}); LocalProfileState copyWith({String? cliName, String? cliUUID}) { + return LocalProfileState( cliName: cliName ?? this.cliName, cliUUID: cliUUID ?? this.cliUUID, @@ -23,11 +27,18 @@ class LocalProfileState { class LocalProfileBloc extends Bloc { LocalProfileBloc() : super(LocalProfileState()) { - on((event, emit) async { - final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; - final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; - emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); - }); + on(_onLocalProfileEvent); + } + + Future _onLocalProfileEvent(LocalProfileEvent event, Emitter emit) async { + final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); + } + + void updateProfile(BuildContext context) { + add(LocalProfileEvent()); + LocalsRepositoryImpl().update(context); } } diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index ebccda7b..f88d1c55 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -9,10 +9,12 @@ import 'package:hub/shared/extensions/dialog_extensions.dart'; import 'package:hub/shared/services/authentication/authentication_service.dart'; import 'package:hub/shared/utils/path_util.dart'; +import '../../../modules/domain/entities/index.dart'; + abstract class MenuLocalDataSource { Future addMenuEntry(EnumMenuItem item, List entries, IconData icon, String text, Function() action); Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries); - Future processDisplay(EnumMenuItem item, String display, MenuEntry opt, List entries); + Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries); Future processStartDate(String startDate, MenuEntry opt); Future processExpirationDate(String expirationDate, MenuEntry opt); } @@ -48,9 +50,9 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { } @override - Future processDisplay(EnumMenuItem item, String display, MenuEntry opt, List entries) async { + Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries) async { try { - switch (display) { + switch (display.value) { case 'VISIVEL': await addMenuEntry(item, entries, opt.icon, opt.name, () async { await PathUtil.nav(opt.route); diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index fdf1d434..7f692ccb 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -23,7 +23,7 @@ class MenuRepositoryImpl implements MenuRepository { final licenseValue = await LicenseRepositoryImpl().getLicense(opt.value); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); - final display = licenseMap['display'] ?? 'INVISIVEL'; + final display = EnumDisplay.fromString(licenseMap['display']); final startDate = licenseMap['startDate'] ?? ''; final expirationDate = licenseMap['expirationDate'] ?? ''; final isStarted = await menuDataSource.processStartDate(startDate, opt); diff --git a/lib/shared/components/molecules/menu/presentation/blocs/index.dart b/lib/shared/components/molecules/menu/presentation/blocs/index.dart index 952e1026..3f1ac83b 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/index.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/index.dart @@ -1 +1,3 @@ +export 'menu_bloc.dart'; +export 'menu_item_bloc.dart'; export 'menu_view_bloc.dart'; diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index 59a48fbe..6866013a 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -1,9 +1,55 @@ + +import 'dart:async'; + import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; + +import 'package:flutter_bloc/flutter_bloc.dart'; + + class MenuEvent {} -class MenuState {} +class MenuState { + final List menuEntries; + final bool isGrid; + + MenuState({this.menuEntries = const [], this.isGrid = false}); + + MenuState copyWith({List? menuEntries, bool? isGrid}) { + return MenuState( + menuEntries: menuEntries ?? this.menuEntries, + isGrid: isGrid ?? this.isGrid, + ); + } +} class MenuBloc extends Bloc { - MenuBloc() : super(MenuState()); + final MenuView style; + final EnumMenuItem item; + final List menuOptions; + late StreamSubscription _completer; + + + MenuBloc({required this.style, required this.item, required this.menuOptions}) : super(MenuState()) { + on((event, emit) async { + await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); + final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); + emit(state.copyWith(menuEntries: entries)); + }); + + _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { + add(MenuEvent()); + }); + } + + @override + Future close() { + _completer.cancel(); + return super.close(); + } + + } diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart index fa22cbfc..bd77e2de 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_view_bloc.dart @@ -1,52 +1,11 @@ -import 'dart:async'; + import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart'; -import 'package:hub/shared/components/molecules/menu/index.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; - - class MenuViewEvent {} -class MenuViewState { - final List menuEntries; - final bool isGrid; - - MenuViewState({this.menuEntries = const [], this.isGrid = false}); - - MenuViewState copyWith({List? menuEntries, bool? isGrid}) { - return MenuViewState( - menuEntries: menuEntries ?? this.menuEntries, - isGrid: isGrid ?? this.isGrid, - ); - } -} +class MenuViewState {} class MenuViewBloc extends Bloc { - final MenuView style; - final EnumMenuItem item; - final List menuOptions; - late StreamSubscription _completer; - - - MenuViewBloc({required this.style, required this.item, required this.menuOptions}) : super(MenuViewState()) { - on((event, emit) async { - await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); - emit(state.copyWith(menuEntries: entries)); - }); - - _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { - add(MenuViewEvent()); - }); - } - - @override - Future close() { - _completer.cancel(); - return super.close(); - } - - + MenuViewBloc() : super(MenuViewState()); } diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index 39b8e3c7..42b535fd 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -214,6 +214,7 @@ class MenuEntry implements BaseModule { static List getEntriesByType(MenuEntryType type) { return entries.where((entry) => entry.types.contains(type)).toList(); } + } diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart index 927fda08..3528588d 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart @@ -44,12 +44,12 @@ class Menufactory extends StatelessWidget { Widget _buildMenuBloc(BuildContext context) { return BlocProvider( - create: (context) => MenuViewBloc( + create: (context) => MenuBloc( style: view, item: item, menuOptions: entry, - )..add(MenuViewEvent()), - child: BlocBuilder( + )..add(MenuEvent()), + child: BlocBuilder( builder: (context, state) { if (view == MenuView.list_grid) { return MenuStaggeredView( diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart index f5204eca..7e861894 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_button.dart @@ -44,7 +44,7 @@ class _MenuButtonWidgetState extends State { setState(() { _isProcessing = true; }); - widget.action.call(); + await widget.action.call(); setState(() { _isProcessing = false; }); diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart index 074d5a22..b120a09d 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_item/menu_item_card.dart @@ -39,7 +39,7 @@ class _MenuCardItemState extends State { setState(() { _isProcessing = true; }); - widget.action.call(); + await widget.action.call(); setState(() { _isProcessing = false; }); diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 06cc2e68..138e114f 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -1,18 +1,19 @@ -import 'dart:developer'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:hub/shared/extensions/string_extensions.dart'; import 'package:sqflite/sqflite.dart'; abstract class LicenseLocalDataSource { Future init(); Future setDisplayByKey(final List key, final String display); Future isNewVersion(); - Future g(String key); - Future s(String key, T value); - Future d(String key); - Future c(); + Future get(String key); + Future set(String key, T value); + Future del(String key); + Future clear(); } class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { @@ -21,15 +22,17 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { LicenseLocalDataSourceImpl._internal(); + @override Future init() async { await DatabaseStorage.instance.init(); } + @override Future setDisplayByKey(final List key, final String display) async { if (key.isEmpty) return; for (var element in key) { if (element != null) { - await s(element, { + await set(element, { 'display': display, 'expirationDate': '', 'startDate': '', @@ -39,15 +42,15 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { } } + @override Future isNewVersion() async { - var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [KeychainStorageKey.isNewVersion.value], columns: ['display']); - if (response.isEmpty) { - return false; - } - return response.first['display'] == 'true'; + final String? reponse = await StorageHelper().get(KeychainStorageKey.isNewVersion.value); + final bool isNewVersion = reponse.toBoolean(); + return isNewVersion; } - Future g(String key) async { + @override + Future get(String key) async { var response = await DatabaseStorage.database.query(tableLicense, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; @@ -55,7 +58,8 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { return response.first.toString(); } - Future s(String key, T value) async { + @override + Future set(String key, T value) async { value as Map; await DatabaseStorage.database.insert( @@ -71,11 +75,13 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { return; } - Future d(String key) async { + @override + Future del(String key) async { await DatabaseStorage.database.delete(tableLicense, where: 'key = ?', whereArgs: [key]); } - Future c() async { + @override + Future clear() async { await DatabaseStorage.database.delete(tableLicense); } } diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 8755b436..5835bd60 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -7,7 +7,6 @@ import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; -import 'package:rxdart/rxdart.dart'; import 'package:sqflite/sqflite.dart'; abstract class LicenseRemoteDataSource { @@ -118,6 +117,6 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { static Future _saveModule(final dynamic body) async { if (body is! Map) return; - await LicenseLocalDataSourceImpl().s(body['key'], body); + await LicenseLocalDataSourceImpl().set(body['key'], body); } } diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index 8cb1c549..48cd0436 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -17,7 +17,8 @@ class LicenseRepositoryImpl implements LicenseRepository { static final license = BehaviorSubject(); static get stream => license.stream; - Future updateLicense(bool isNewVersion) async { + Future updateLicense() async { + final bool isNewVersion = await localDataSource.isNewVersion(); await remoteDataSource.setupLicense(database, isNewVersion); if (isNewVersion) { return await remoteDataSource.fetchLicenses(isNewVersion); @@ -31,10 +32,10 @@ class LicenseRepositoryImpl implements LicenseRepository { } Future getLicense(String key) async { - return await localDataSource.g(key); + return await localDataSource.get(key); } Future setLicense(String key, T value) async { - return await localDataSource.s(key, value); + return await localDataSource.set(key, value); } } diff --git a/lib/shared/components/molecules/modules/domain/entities/base_module.dart b/lib/shared/components/molecules/modules/domain/entities/base_module.dart index b67b25a9..662fa7b2 100644 --- a/lib/shared/components/molecules/modules/domain/entities/base_module.dart +++ b/lib/shared/components/molecules/modules/domain/entities/base_module.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; + + abstract class BaseModule { String get value; String get name; diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 1c3d6410..7daaac0e 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -6,8 +6,8 @@ import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'module.dart'; -enum LicenseKeys { +enum LicenseKeys { messages('FRE-HUB-MESSAGES'), liberations('FRE-HUB-LIBERATIONS'), reservations('FRE-HUB-RESERVATIONS'), diff --git a/lib/shared/components/molecules/modules/domain/entities/module.dart b/lib/shared/components/molecules/modules/domain/entities/module.dart index 060586aa..7dc2e8c2 100644 --- a/lib/shared/components/molecules/modules/domain/entities/module.dart +++ b/lib/shared/components/molecules/modules/domain/entities/module.dart @@ -3,6 +3,30 @@ import 'package:hub/shared/components/molecules/modules/data/models/module_model enum ModuleStatus { active, inactive, disabled } +enum EnumDisplay { + active('VISIVEL'), + inactive('INVISIVEL'), + expired('DESABILITADO'); + + final String value; + const EnumDisplay(this.value); + + static EnumDisplay fromString(String? value) { + if (value == null) return EnumDisplay.inactive; + switch (value) { + case 'VISIVEL': + return EnumDisplay.active; + case 'INVISIVEL': + return EnumDisplay.inactive; + case 'DESABILITADO': + return EnumDisplay.expired; + default: + return EnumDisplay.inactive; + } + } +} + + extension ModuleStatusExtension on ModuleStatus { String get key { switch (this) { diff --git a/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart index 1d1691d2..732e7baf 100644 --- a/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart +++ b/lib/shared/components/molecules/modules/domain/respositories/license_repository.dart @@ -1,5 +1,5 @@ abstract class LicenseRepository { - Future updateLicense(bool isNewVersion); + Future updateLicense(); Future cleanLicense(); Future getLicense(String key); diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index e3093ad5..86830d4b 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -32,7 +32,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - await LicenseRepositoryImpl().updateLicense(false); + await LicenseRepositoryImpl().updateLicense(); isInitialized = true; } diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index ec1f6e80..0431c8f1 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -23,15 +23,18 @@ class KeychainHelper implements BaseStorage { @override Future get(String key) async { + var response = await DatabaseStorage.database.query(tableKeychain, where: 'key = ?', whereArgs: [key]); if (response.isEmpty) { return null; } + log('() => get keychain: $key : ${response.first['value']}'); return response.first['value'].toString(); } @override Future set(String key, T value) async { + var date = DateTime.now().toIso8601String(); await DatabaseStorage.database.insert( tableKeychain, @@ -44,6 +47,7 @@ class KeychainHelper implements BaseStorage { 'createdAt': date, }, conflictAlgorithm: ConflictAlgorithm.replace); + log('() => set keychain: $key : $value'); } @override @@ -53,7 +57,11 @@ class KeychainHelper implements BaseStorage { @override Future clearAll() async { - await DatabaseStorage.database.delete(tableKeychain); + try { + await DatabaseStorage.database.delete(tableKeychain); + } catch (e, s) { + log('() => clearAll keychain: $e', stackTrace: s); + } } diff --git a/lib/shared/helpers/storage/storage_helper.dart b/lib/shared/helpers/storage/storage_helper.dart index 9600a652..e59c39ea 100644 --- a/lib/shared/helpers/storage/storage_helper.dart +++ b/lib/shared/helpers/storage/storage_helper.dart @@ -26,7 +26,7 @@ class StorageHelper { if (isFirstRun != 'false') { await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, false); - await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); + await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 2053ede1..ae3d457a 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; @@ -138,6 +140,8 @@ class AuthenticationService { alignment: Alignment.bottomCenter, ), }; + + await StorageHelper().clean(Storage.databaseStorage); await StorageHelper().clean(Storage.secureStorage); await StorageHelper().clean(Storage.databaseStorage); context.go('/welcomePage', extra: extra); From 93ce8ab9a68b37af7f9594cb94c2906a4099e728 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Tue, 3 Dec 2024 17:48:45 -0300 Subject: [PATCH 33/75] WIP --- lib/backend/api_requests/api_calls.dart | 30 ------------------------- 1 file changed, 30 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index ca2f5d9c..c07b24de 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -58,7 +58,6 @@ class PhpGroup { static GetVehiclesByProperty getVehiclesByProperty = GetVehiclesByProperty(); static GetResidentsByProperty getResidentsByProperty = GetResidentsByProperty(); static GetOpenedVisits getOpenedVisits = GetOpenedVisits(); - static TestCall testCall = TestCall(); static GetLicense getLicense = GetLicense(); } @@ -156,37 +155,8 @@ class GetVehiclesByProperty { } static GetLicense getLicense = GetLicense(); - static TestCall testCall = TestCall(); } -class TestCall { - Future call() async { - const String accessKey = 'af7483f'; - const String usuEmail = 'email_app@exemplo.com'; - const String idDestino = '1'; - - return await ApiManager.instance.makeApiCall( - callName: 'getLicense', - apiUrl: 'https://residenceapi.fre.com.br/getLicenca.php', - callType: ApiCallType.POST, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - params: { - 'AccessKey': accessKey, - 'UsuEmail': usuEmail, - 'idDestino': idDestino, - }, - bodyType: BodyType.X_WWW_FORM_URL_ENCODED, - returnBody: true, - encodeBodyUtf8: false, - decodeUtf8: false, - cache: false, - isStreamingApi: false, - alwaysAllowBody: false, - ); - } -} class GetLicense { Future call() async { From 5ab7469601c88627cb4d2111ed567269a2633ee5 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 09:05:06 -0300 Subject: [PATCH 34/75] fix homeMenu order --- .../menu/presentation/mappers/menu_entry.dart | 171 +++++++++--------- 1 file changed, 86 insertions(+), 85 deletions(-) diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index 42b535fd..f3d0649a 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -21,86 +21,6 @@ class MenuEntry implements BaseModule { }); static List entries = [ - MenuEntry( - value: 'FRE-HUB-MESSAGES', - icon: Icons.chat_outlined, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Mensagens', - enText: 'Messages History', - ), - route: '/messageHistoryPage', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), - MenuEntry( - value: 'FRE-HUB-LIBERATIONS', - icon: Icons.how_to_reg_outlined, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Liberações', - enText: 'Liberations History', - ), - route: '/liberationHistory', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), - MenuEntry( - value: 'FRE-HUB-RESERVATIONS', - icon: Icons.event_available, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Reservas', - enText: 'Reservations', - ), - route: '/reservation', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), - MenuEntry( - value: 'FRE-HUB-ACCESS', - icon: Icons.transfer_within_a_station_outlined, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Consultar Acessos', - enText: 'Access History', - ), - route: '/acessHistoryPage', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), - MenuEntry( - value: 'FRE-HUB-PETS', - icon: Icons.pets, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', - ), - route: '/petsPage', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), - MenuEntry( - value: 'FRE-HUB-PEOPLE', - icon: Icons.groups, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pessoas na Propriedade', - enText: 'People on the Property', - ), - route: '/peopleOnThePropertyPage', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), - MenuEntry( - value: 'FRE-HUB-ORDERS', - icon: Icons.inventory_2_outlined, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', - ), - route: '/packageOrder', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), - MenuEntry( - value: 'FRE-HUB-COMPLETE-SCHEDULE', - icon: Icons.event, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Agenda Completa', - enText: 'Complete Schedule', - ), - route: '/scheduleCompleteVisitPage', - types: [MenuEntryType.Home, MenuEntryType.Drawer], - ), MenuEntry( value: 'FRE-HUB-AGE-PROV-PRESTADOR', icon: Icons.engineering_outlined, @@ -132,13 +52,33 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-QRCODE', - icon: Icons.qr_code, + value: 'FRE-HUB-COMPLETE-SCHEDULE', + icon: Icons.event, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'QRCode de Acesso', - enText: 'Access QRCode', + ptText: 'Agenda Completa', + enText: 'Complete Schedule', ), - route: '/qrCodePage', + route: '/scheduleCompleteVisitPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-ORDERS', + icon: Icons.inventory_2_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Minhas Encomendas', + enText: 'My Orders', + ), + route: '/packageOrder', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-RESERVATIONS', + icon: Icons.event_available, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Reservas', + enText: 'Reservations', + ), + route: '/reservation', types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( @@ -151,6 +91,56 @@ class MenuEntry implements BaseModule { route: '/registerVisitorPage', types: [MenuEntryType.Home, MenuEntryType.Drawer], ), + MenuEntry( + value: 'FRE-HUB-QRCODE', + icon: Icons.qr_code, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'QRCode de Acesso', + enText: 'Access QRCode', + ), + route: '/qrCodePage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-PETS', + icon: Icons.pets, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ), + route: '/petsPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-ACCESS', + icon: Icons.transfer_within_a_station_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Acessos', + enText: 'Access History', + ), + route: '/acessHistoryPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-LIBERATIONS', + icon: Icons.how_to_reg_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Liberações', + enText: 'Liberations History', + ), + route: '/liberationHistory', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), + MenuEntry( + value: 'FRE-HUB-MESSAGES', + icon: Icons.chat_outlined, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Consultar Mensagens', + enText: 'Messages History', + ), + route: '/messageHistoryPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), MenuEntry( value: 'FRE-HUB-PROPERTY', icon: Icons.home, @@ -161,6 +151,17 @@ class MenuEntry implements BaseModule { route: '/aboutProperty', types: [MenuEntryType.Home, MenuEntryType.Drawer], ), + + MenuEntry( + value: 'FRE-HUB-PEOPLE', + icon: Icons.groups, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pessoas na Propriedade', + enText: 'People on the Property', + ), + route: '/peopleOnThePropertyPage', + types: [MenuEntryType.Home, MenuEntryType.Drawer], + ), MenuEntry( value: 'FRE-HUB-SETTINGS', icon: Icons.settings, From b5c00b0d0c06a5197e7c9aee7ca2d0c88f231494 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 09:09:44 -0300 Subject: [PATCH 35/75] wip: migrations --- lib/shared/helpers/database/database_helper.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 86830d4b..a40600e6 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -41,6 +41,7 @@ class DatabaseStorage { await database.execute(createKeychainTable); await database.execute(createLicenseTable); if (version >= 2) { + await database.execute(createLicenseTable); await database.execute(updatePetsHistoryTrigger); } if (version >= 3) { From 747596e8333a6bc5d861e5d60dcaad7aa334d224 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 09:12:07 -0300 Subject: [PATCH 36/75] WIP --- lib/shared/helpers/database/database_helper.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index a40600e6..8460a47f 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -41,7 +41,6 @@ class DatabaseStorage { await database.execute(createKeychainTable); await database.execute(createLicenseTable); if (version >= 2) { - await database.execute(createLicenseTable); await database.execute(updatePetsHistoryTrigger); } if (version >= 3) { @@ -52,6 +51,7 @@ class DatabaseStorage { Future _onUpgrade(Database database, int oldVersion, int newVersion) async { log('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2 && newVersion >= 2) { + await database.execute(createLicenseTable); await database.execute(updatePetsHistoryTrigger); } if (oldVersion < 3 && newVersion >= 3) { From 88f9b1f81479bbdf1b0c2669db94fff5dff4668b Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 09:58:26 -0300 Subject: [PATCH 37/75] WIP: LocalsREpositoryImpl().update --- .../home/presentation/pages/home_page.dart | 2 +- .../locals_remote_data_source.dart | 1 - .../repositories/locals_repository_impl.dart | 3 ++- .../blocs/local_profile_bloc.dart | 8 +++---- .../repositories/menu_repository_impl.dart | 1 + .../license_remote_data_source.dart | 23 ++++++++----------- .../repositories/license_repository_impl.dart | 10 +++++--- .../helpers/database/database_helper.dart | 3 +++ 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index d1c2ad24..8f026f3e 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -35,7 +35,7 @@ class _HomePageWidgetState extends State { ], child: Builder( builder: (context) { - context.read().updateProfile(context); + // context.read().updateProfile(context); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index 42b16d9c..eecd26d9 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -71,7 +71,6 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { @override Future processLocals(BuildContext context) async { try { - await LicenseRepositoryImpl().cleanLicense(); final GetLocalsCall callback = PhpGroup.getLocalsCall; final ApiCallResponse response = await callback.call(); final bool? isError = response.jsonBody['error']; diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 39916fc1..d30f7523 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; +import 'package:hub/shared/components/molecules/modules/index.dart'; class LocalsRepositoryImpl implements LocalsRepository { final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl(); @@ -12,7 +13,7 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { - final bool response = await remoteDataSource.processLocals(context); + final bool response = await LicenseRepositoryImpl().updateLicense(); context.read().add(LocalProfileEvent()); return response; } diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index d79f115c..9abbd435 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -36,10 +36,10 @@ class LocalProfileBloc extends Bloc { emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); } - void updateProfile(BuildContext context) { - add(LocalProfileEvent()); - LocalsRepositoryImpl().update(context); - } + // void updateProfile(BuildContext context) { + // add(LocalProfileEvent()); + // LocalsRepositoryImpl().update(context); + // } } class LocalProfileComponentModel extends FlutterFlowModel { diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 7f692ccb..d786151c 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -15,6 +15,7 @@ class MenuRepositoryImpl implements MenuRepository { @override Future> generateMenuEntries(List menuOptions, EnumMenuItem item) async { + log('Generating menu entries for $item'); List entries = []; try { for (var opt in menuOptions) { diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 5835bd60..54230ed4 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -13,7 +13,7 @@ abstract class LicenseRemoteDataSource { Future fetchLicenses(bool isNewVersion); Future cleanLicense(); Future processLicense(); - Future setupLicense(Database database, bool isNewVersion); + Future setupLicense(Database database, bool isNewVersion); } class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { @@ -22,8 +22,8 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { LicenseRemoteDataSourceImpl._internal(); - final StreamController _completerController = StreamController.broadcast(); - Stream get streamCompleterController => _completerController.stream; + final StreamController completerController = StreamController.broadcast(); + Stream get streamCompleterController => completerController.stream; @override @@ -36,7 +36,8 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } @override - Future setupLicense(Database database, bool isNewVersion) async { + Future setupLicense(Database database, bool isNewVersion) async { + log('Setting up license...'); final License license = await License.getLicense(isNewVersion); final List inactiveModuleKey = license.modules @@ -63,11 +64,12 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO'); } - LicenseRepositoryImpl.license.add(true); + return true; } @override Future fetchLicenses(bool isNewVersion) async { + log('Fetching licenses...'); try { final response = await PhpGroup.getLicense(); final dynamic responseBody = response.jsonBody; @@ -83,9 +85,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } if (responseBody == []) { - await setupLicense(DatabaseStorage.database, isNewVersion); - LicenseRepositoryImpl.license.add(false); - return false; + return await setupLicense(DatabaseStorage.database, isNewVersion); } List> saveOperations = []; @@ -95,15 +95,10 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } } await Future.wait(saveOperations); - - LicenseRepositoryImpl.license.add(true); - _completerController.add(null); - return true; } catch (e, s) { log('Erro ao obter licenças: $e', stackTrace: s); - await setupLicense(DatabaseStorage.database, isNewVersion); - return false; + return await setupLicense(DatabaseStorage.database, isNewVersion); } } diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index 48cd0436..d2b2ae43 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -18,12 +18,16 @@ class LicenseRepositoryImpl implements LicenseRepository { static get stream => license.stream; Future updateLicense() async { + LicenseRepositoryImpl.license.add(false); + bool result = false; final bool isNewVersion = await localDataSource.isNewVersion(); - await remoteDataSource.setupLicense(database, isNewVersion); + result = await remoteDataSource.setupLicense(database, isNewVersion); if (isNewVersion) { - return await remoteDataSource.fetchLicenses(isNewVersion); + result = await remoteDataSource.fetchLicenses(isNewVersion); } - return false; + + LicenseRepositoryImpl.license.add(result); + return result; } diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 8460a47f..258e81d7 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -46,6 +46,9 @@ class DatabaseStorage { if (version >= 3) { await database.execute(updateDisplayTrigger); } + if (version >= 4) { + await database.execute(updatePeopleDisplayTrigger); + } } Future _onUpgrade(Database database, int oldVersion, int newVersion) async { From 243c89b636925367e204c3979bda852b06fcd48e Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 10:50:55 -0300 Subject: [PATCH 38/75] wip: cache license in build context.read --- .../home/presentation/pages/home_page.dart | 10 +++++++++- .../data_sources/locals_remote_data_source.dart | 12 ++++++------ .../repositories/locals_repository_impl.dart | 8 +++++++- .../presentation/blocs/local_profile_bloc.dart | 9 +++++---- .../local_profile/local_profile_widget.dart | 2 +- .../menu/presentation/blocs/menu_bloc.dart | 14 ++++++++------ .../menu/presentation/widgets/menu_factory.dart | 3 ++- .../data_sources/license_remote_data_source.dart | 16 ++++++++++++---- .../repositories/license_repository_impl.dart | 14 +++++++++----- lib/shared/helpers/database/database_helper.dart | 2 +- 10 files changed, 60 insertions(+), 30 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 8f026f3e..4d0a12b7 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -26,16 +26,24 @@ class _HomePageWidgetState extends State { Widget build(BuildContext context) { return MultiBlocProvider( providers: [ + BlocProvider( + create: (context) => MenuBloc( + style: MenuView.list_grid, + item: EnumMenuItem.button, + menuOptions: MenuEntry.getEntriesByType(MenuEntryType.Home), + )..add(MenuEvent()), + ), BlocProvider( create: (context) => HomeBloc()..add(HomeEvent()), ), BlocProvider( create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), ), + ], child: Builder( builder: (context) { - // context.read().updateProfile(context); + context.read().updateProfile(context); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index eecd26d9..f252201a 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -18,11 +18,11 @@ import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/snackbar_util.dart'; abstract class LocalsRemoteDataSource { - Future checkLocals(BuildContext context) async {} - Future processLocals(BuildContext context) async => false; - Future processData(BuildContext context) async => false; - Future selectLocal(BuildContext context, ApiCallResponse? response) async => false; - Future detachLocal(BuildContext context) async {} + Future checkLocals(BuildContext context); + Future processLocals(BuildContext context) ; + Future processData(BuildContext context); + Future selectLocal(BuildContext context, ApiCallResponse? response) ; + Future detachLocal(BuildContext context) ; } class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { @@ -165,7 +165,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); return false; } else { - final bool isNewVersion = await LocalUtil.updateStorageUtil(response.jsonBody); + await LocalUtil.updateStorageUtil(response.jsonBody); return await LicenseRepositoryImpl().updateLicense(); } } catch (e, s) { diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index d30f7523..e2dbd15f 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -2,10 +2,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:rxdart/rxdart.dart'; class LocalsRepositoryImpl implements LocalsRepository { final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl(); + static final license = BehaviorSubject(); + static get stream => license.stream; + @override Future validateLocal(BuildContext context) async { return await remoteDataSource.checkLocals(context); @@ -13,8 +17,10 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { - final bool response = await LicenseRepositoryImpl().updateLicense(); + LocalsRepositoryImpl.license.add(false); + final bool response = await remoteDataSource.processLocals(context); context.read().add(LocalProfileEvent()); + LocalsRepositoryImpl.license.add(response); return response; } diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index 9abbd435..754abc2f 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; +import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; @@ -36,10 +37,10 @@ class LocalProfileBloc extends Bloc { emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); } - // void updateProfile(BuildContext context) { - // add(LocalProfileEvent()); - // LocalsRepositoryImpl().update(context); - // } + void updateProfile(BuildContext context) { + context.read().add(MenuEvent()); + add(LocalProfileEvent()); + } } class LocalProfileComponentModel extends FlutterFlowModel { diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 189cb702..7153de8c 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -31,7 +31,7 @@ class _LocalProfileComponentWidgetState extends State( - stream: LicenseRepositoryImpl.stream, + stream: LocalsRepositoryImpl.stream, builder: (context, snapshot) { final textScaler = MediaQuery.textScalerOf(context); final double baseFontSize = 14.0; diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index 6866013a..14d434c5 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -34,16 +34,18 @@ class MenuBloc extends Bloc { MenuBloc({required this.style, required this.item, required this.menuOptions}) : super(MenuState()) { - on((event, emit) async { - await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); - emit(state.copyWith(menuEntries: entries)); - }); + on(_onMenuEvent); _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { add(MenuEvent()); }); - } + } + + Future _onMenuEvent(MenuEvent event, Emitter emit) async { + await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); + final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); + emit(state.copyWith(menuEntries: entries)); + } @override Future close() { diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart index 3528588d..c3c11fba 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/utils/loading_util.dart'; @@ -22,7 +23,7 @@ class Menufactory extends StatelessWidget { @override Widget build(BuildContext context) { return StreamBuilder( - stream: LicenseRepositoryImpl.stream, + stream: LocalsRepositoryImpl.stream, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: CircularProgressIndicator()); diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 54230ed4..23427808 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:developer'; import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; @@ -31,13 +32,14 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { @override Future cleanLicense() async { - LicenseRepositoryImpl.license.add(false); + LocalsRepositoryImpl.license.add(false); } @override Future setupLicense(Database database, bool isNewVersion) async { log('Setting up license...'); + try { final License license = await License.getLicense(isNewVersion); final List inactiveModuleKey = license.modules @@ -65,6 +67,10 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } return true; + } catch (e, s) { + log('Erro ao configurar licenças: $e', stackTrace: s); + return false; + } } @override @@ -85,7 +91,8 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } if (responseBody == []) { - return await setupLicense(DatabaseStorage.database, isNewVersion); + // return await setupLicense(DatabaseStorage.database, isNewVersion); + return false; } List> saveOperations = []; @@ -98,12 +105,13 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { return true; } catch (e, s) { log('Erro ao obter licenças: $e', stackTrace: s); - return await setupLicense(DatabaseStorage.database, isNewVersion); + // return await setupLicense(DatabaseStorage.database, isNewVersion); + return false; } } Future waitForSaveCompletion() async { - await LicenseRepositoryImpl.stream; + await LocalsRepositoryImpl.stream; } static bool licenseContainsKey(final String key) { diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index d2b2ae43..3ff81998 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -1,8 +1,9 @@ +import 'dart:developer'; + import 'package:hub/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart'; import 'package:hub/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart'; import 'package:hub/shared/components/molecules/modules/domain/respositories/license_repository.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; -import 'package:rxdart/rxdart.dart'; import 'package:sqflite/sqflite.dart'; typedef LicenseStatus = bool; @@ -14,31 +15,34 @@ class LicenseRepositoryImpl implements LicenseRepository { LicenseRepositoryImpl(); - static final license = BehaviorSubject(); - static get stream => license.stream; + + @override Future updateLicense() async { - LicenseRepositoryImpl.license.add(false); bool result = false; final bool isNewVersion = await localDataSource.isNewVersion(); + log('isNewVersion: $isNewVersion'); result = await remoteDataSource.setupLicense(database, isNewVersion); if (isNewVersion) { result = await remoteDataSource.fetchLicenses(isNewVersion); } - LicenseRepositoryImpl.license.add(result); + return result; } + @override Future cleanLicense() async { return await remoteDataSource.cleanLicense(); } + @override Future getLicense(String key) async { return await localDataSource.get(key); } + @override Future setLicense(String key, T value) async { return await localDataSource.set(key, value); } diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 258e81d7..a5054993 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -32,7 +32,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - await LicenseRepositoryImpl().updateLicense(); + // await LicenseRepositoryImpl().updateLicense(); isInitialized = true; } From 3244e641625de45698feadf8d09e1422192628c1 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 11:06:09 -0300 Subject: [PATCH 39/75] WIP: _processWithoutLicense --- .../modules/domain/entities/license.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 7daaac0e..da762027 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -45,8 +45,12 @@ class License { ); - static Future _proceessOldVersion(LicenseKeys key) async { + static Future _processWithoutLicense(LicenseKeys key) async { switch(key) { + case LicenseKeys.reservations: + return await _precessWpp(); + case LicenseKeys.orders: + return await _precessWpp(); case LicenseKeys.fastPass: return await _precessWpp(); case LicenseKeys.providerSchedule: @@ -137,7 +141,7 @@ class License { ), Module( key: LicenseKeys.pets.value, - display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.pets), + display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.pets), expirationDate: '', startDate: '', quantity: 0, @@ -158,21 +162,21 @@ class License { ), Module( key: LicenseKeys.providerSchedule.value, - display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.providerSchedule), + display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.providerSchedule), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.deliverySchedule.value, - display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.deliverySchedule), + display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.deliverySchedule), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.fastPass.value, - display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.fastPass), + display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.fastPass), expirationDate: '', startDate: '', quantity: 0, @@ -207,7 +211,7 @@ class License { ), Module( key: LicenseKeys.petsHistory.value, - display: isNewVersion ? ModuleStatus.active.key : await _proceessOldVersion(LicenseKeys.petsHistory), + display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.petsHistory), expirationDate: '', startDate: '', quantity: 0, From 83bc57872074e39c939b96540aac48702dd367a1 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 11:15:13 -0300 Subject: [PATCH 40/75] WIP --- lib/shared/components/molecules/drawer/drawer_widget.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/shared/components/molecules/drawer/drawer_widget.dart b/lib/shared/components/molecules/drawer/drawer_widget.dart index a022f8c8..0eac540d 100644 --- a/lib/shared/components/molecules/drawer/drawer_widget.dart +++ b/lib/shared/components/molecules/drawer/drawer_widget.dart @@ -5,6 +5,7 @@ import 'package:hub/features/home/index.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; @@ -14,7 +15,7 @@ class CustomDrawer extends StatelessWidget { @override Widget build(BuildContext context) { return StreamBuilder( - stream: LicenseRepositoryImpl.stream, + stream: LocalsRepositoryImpl.stream, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center( From c84f9f5addfb0830aa9eb732ca9ffa9674cc28b9 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 11:54:42 -0300 Subject: [PATCH 41/75] fix: process modules in license --- .../data_sources/menu_local_data_source.dart | 8 ++-- .../repositories/menu_repository_impl.dart | 2 +- .../modules/domain/entities/license.dart | 47 ++++++++++--------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index f88d1c55..84c0ffa8 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -39,7 +39,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { @override Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries) async { - if (opt.value == 'FRE-HUB-LOGOUT') { + if (opt.key == 'FRE-HUB-LOGOUT') { await addMenuEntry(item, entries, opt.icon, opt.name, () async { await AuthenticationService.signOut(navigatorKey.currentContext!); }); @@ -67,7 +67,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { break; } } catch (e) { - log('Error processing display for module ${opt.value}: $e'); + log('Error processing display for module ${opt.key}: $e'); } } @@ -78,7 +78,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final start = DateTime.tryParse(startDate); return start != null && DateTime.now().isAfter(start); } catch (e) { - log('Error processing start date for module ${opt.value}: $e'); + log('Error processing start date for module ${opt.key}: $e'); } return false; } @@ -90,7 +90,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final expiration = DateTime.tryParse(expirationDate); return expiration != null && DateTime.now().isAfter(expiration); } catch (e) { - log('Error processing expiration date for module ${opt.value}: $e'); + log('Error processing expiration date for module ${opt.key}: $e'); } return false; } diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index d786151c..545553d3 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -21,7 +21,7 @@ class MenuRepositoryImpl implements MenuRepository { for (var opt in menuOptions) { final bool isDefault = await menuDataSource.processDisplayDefault(item, opt, entries); if (isDefault) continue; - final licenseValue = await LicenseRepositoryImpl().getLicense(opt.value); + final licenseValue = await LicenseRepositoryImpl().getLicense(opt.key); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); final display = EnumDisplay.fromString(licenseMap['display']); diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index da762027..0ab0f4c0 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -45,7 +45,7 @@ class License { ); - static Future _processWithoutLicense(LicenseKeys key) async { + static Future _processWithoutModule(LicenseKeys key) async { switch(key) { case LicenseKeys.reservations: return await _precessWpp(); @@ -87,145 +87,146 @@ class License { } - - static Future getLicense(bool isNewVersion) async { + /// Returns a [License] object with the modules and their status. + /// @param isNewVersion: Indica que é sistema novo que possui modularização. + static Future getLicense(bool isNewVersionWithModule) async { return License([ Module( key: LicenseKeys.messages.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.liberations.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.reservations.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.inactive.key, + display: await _processWithoutModule(LicenseKeys.reservations), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.access.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.openedVisits.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.vehicles.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.residents.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.pets.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.pets), + display: await _processWithoutModule(LicenseKeys.pets), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.orders.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: await _processWithoutModule(LicenseKeys.orders), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.completeSchedule.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.providerSchedule.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.providerSchedule), + display: await _processWithoutModule(LicenseKeys.providerSchedule), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.deliverySchedule.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.deliverySchedule), + display: await _processWithoutModule(LicenseKeys.deliverySchedule), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.fastPass.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.fastPass), + display: await _processWithoutModule(LicenseKeys.fastPass), expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.qrCode.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.visitors.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.property.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.people.value, - display: isNewVersion ? ModuleStatus.inactive.key : ModuleStatus.active.key, + display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.petsHistory.value, - display: isNewVersion ? ModuleStatus.active.key : await _processWithoutLicense(LicenseKeys.petsHistory), + display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.settings.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, ), Module( key: LicenseKeys.logout.value, - display: isNewVersion ? ModuleStatus.active.key : ModuleStatus.active.key, + display: ModuleStatus.active.key, expirationDate: '', startDate: '', quantity: 0, From e436be9bc98b6feb41f09c372fbe9e2cd55f669c Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 13:33:55 -0300 Subject: [PATCH 42/75] wip: refactory update display trigger --- .../molecules/modules/constants/license_constants.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shared/components/molecules/modules/constants/license_constants.dart b/lib/shared/components/molecules/modules/constants/license_constants.dart index da40fef4..37ce1daf 100644 --- a/lib/shared/components/molecules/modules/constants/license_constants.dart +++ b/lib/shared/components/molecules/modules/constants/license_constants.dart @@ -28,11 +28,11 @@ String get updateDisplayTrigger => ''' CREATE TRIGGER update_display_trigger AFTER UPDATE ON $tableLicense - WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') + WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') BEGIN UPDATE $tableLicense SET display = CASE - WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') AND display = 'VISIVEL') > 0 + WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 THEN 'VISIVEL' ELSE 'INVISIVEL' END From 303f08e9eec83942ab5a8e35565a8abad1c6d64f Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 13:45:13 -0300 Subject: [PATCH 43/75] fix: vists on the property route --- .../molecules/menu/presentation/mappers/menu_entry.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index f3d0649a..c530952c 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -200,7 +200,7 @@ class MenuEntry implements BaseModule { value: 'FRE-HUB-OPENED-VISITS', icon: Icons.perm_contact_calendar, name: 'Opened Visits', - route: '/openedVisitsPage', + route: '/visitsOnThePropertyPage', types: [MenuEntryType.Property], ), MenuEntry( From 97c2180dcc1706f951cc819d6ee21c7a970e1d29 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 13:56:20 -0300 Subject: [PATCH 44/75] WiP --- .../components/molecules/modules/domain/entities/license.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 0ab0f4c0..a89b241b 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -198,7 +198,7 @@ class License { ), Module( key: LicenseKeys.property.value, - display: ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, @@ -212,7 +212,7 @@ class License { ), Module( key: LicenseKeys.petsHistory.value, - display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: await _processWithoutModule(LicenseKeys.pets), expirationDate: '', startDate: '', quantity: 0, From 6e2ccc209b9d78ecfba6eb0146eef201222b72a6 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 14:05:25 -0300 Subject: [PATCH 45/75] WIP --- .../menu/data/data_sources/menu_local_data_source.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index 84c0ffa8..f88d1c55 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -39,7 +39,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { @override Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries) async { - if (opt.key == 'FRE-HUB-LOGOUT') { + if (opt.value == 'FRE-HUB-LOGOUT') { await addMenuEntry(item, entries, opt.icon, opt.name, () async { await AuthenticationService.signOut(navigatorKey.currentContext!); }); @@ -67,7 +67,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { break; } } catch (e) { - log('Error processing display for module ${opt.key}: $e'); + log('Error processing display for module ${opt.value}: $e'); } } @@ -78,7 +78,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final start = DateTime.tryParse(startDate); return start != null && DateTime.now().isAfter(start); } catch (e) { - log('Error processing start date for module ${opt.key}: $e'); + log('Error processing start date for module ${opt.value}: $e'); } return false; } @@ -90,7 +90,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final expiration = DateTime.tryParse(expirationDate); return expiration != null && DateTime.now().isAfter(expiration); } catch (e) { - log('Error processing expiration date for module ${opt.key}: $e'); + log('Error processing expiration date for module ${opt.value}: $e'); } return false; } From d76668206a931b97363b4d0477c56ff50485eae7 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 14:11:45 -0300 Subject: [PATCH 46/75] fix labels --- .../home/presentation/pages/home_page.dart | 2 +- .../data_sources/menu_local_data_source.dart | 8 ++-- .../repositories/menu_repository_impl.dart | 14 +++--- .../domain/respositories/menu_repository.dart | 2 +- .../menu/presentation/blocs/menu_bloc.dart | 6 +-- .../menu/presentation/mappers/menu_entry.dart | 44 +++++++++---------- .../presentation/widgets/menu_factory.dart | 2 +- .../modules/domain/entities/base_module.dart | 2 +- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 4d0a12b7..20767d9f 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -30,7 +30,7 @@ class _HomePageWidgetState extends State { create: (context) => MenuBloc( style: MenuView.list_grid, item: EnumMenuItem.button, - menuOptions: MenuEntry.getEntriesByType(MenuEntryType.Home), + entries: MenuEntry.getEntriesByType(MenuEntryType.Home), )..add(MenuEvent()), ), BlocProvider( diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index f88d1c55..84c0ffa8 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -39,7 +39,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { @override Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries) async { - if (opt.value == 'FRE-HUB-LOGOUT') { + if (opt.key == 'FRE-HUB-LOGOUT') { await addMenuEntry(item, entries, opt.icon, opt.name, () async { await AuthenticationService.signOut(navigatorKey.currentContext!); }); @@ -67,7 +67,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { break; } } catch (e) { - log('Error processing display for module ${opt.value}: $e'); + log('Error processing display for module ${opt.key}: $e'); } } @@ -78,7 +78,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final start = DateTime.tryParse(startDate); return start != null && DateTime.now().isAfter(start); } catch (e) { - log('Error processing start date for module ${opt.value}: $e'); + log('Error processing start date for module ${opt.key}: $e'); } return false; } @@ -90,7 +90,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { final expiration = DateTime.tryParse(expirationDate); return expiration != null && DateTime.now().isAfter(expiration); } catch (e) { - log('Error processing expiration date for module ${opt.value}: $e'); + log('Error processing expiration date for module ${opt.key}: $e'); } return false; } diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 545553d3..1f5a0bb7 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -14,23 +14,23 @@ class MenuRepositoryImpl implements MenuRepository { @override - Future> generateMenuEntries(List menuOptions, EnumMenuItem item) async { + Future> generateMenuEntries(List menuEntries, EnumMenuItem item) async { log('Generating menu entries for $item'); List entries = []; try { - for (var opt in menuOptions) { - final bool isDefault = await menuDataSource.processDisplayDefault(item, opt, entries); + for (var entry in menuEntries) { + final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); if (isDefault) continue; - final licenseValue = await LicenseRepositoryImpl().getLicense(opt.key); + final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); final display = EnumDisplay.fromString(licenseMap['display']); final startDate = licenseMap['startDate'] ?? ''; final expirationDate = licenseMap['expirationDate'] ?? ''; - final isStarted = await menuDataSource.processStartDate(startDate, opt); - final isExpired = await menuDataSource.processExpirationDate(expirationDate, opt); + final isStarted = await menuDataSource.processStartDate(startDate, entry); + final isExpired = await menuDataSource.processExpirationDate(expirationDate, entry); if (isStarted && !isExpired) { - await menuDataSource.processDisplay(item, display, opt, entries); + await menuDataSource.processDisplay(item, display, entry, entries); } } } diff --git a/lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart b/lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart index 1abf171d..495dc332 100644 --- a/lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart +++ b/lib/shared/components/molecules/menu/domain/respositories/menu_repository.dart @@ -2,5 +2,5 @@ import 'package:hub/shared/components/molecules/menu/domain/entities/menu_item.d import 'package:hub/shared/components/molecules/menu/index.dart'; abstract class MenuRepository { - Future> generateMenuEntries(List menuOptions, EnumMenuItem item); + Future> generateMenuEntries(List menuEntries, EnumMenuItem item); } \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index 14d434c5..0dd8431e 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -29,11 +29,11 @@ class MenuState { class MenuBloc extends Bloc { final MenuView style; final EnumMenuItem item; - final List menuOptions; + final List entries; late StreamSubscription _completer; - MenuBloc({required this.style, required this.item, required this.menuOptions}) : super(MenuState()) { + MenuBloc({required this.style, required this.item, required this.entries}) : super(MenuState()) { on(_onMenuEvent); _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { @@ -43,7 +43,7 @@ class MenuBloc extends Bloc { Future _onMenuEvent(MenuEvent event, Emitter emit) async { await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - final entries = await MenuRepositoryImpl().generateMenuEntries(menuOptions, item); + final entries = await MenuRepositoryImpl().generateMenuEntries(entries, item); emit(state.copyWith(menuEntries: entries)); } diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index c530952c..6097c501 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -6,14 +6,14 @@ import 'package:hub/shared/components/molecules/modules/domain/entities/base_mod enum MenuEntryType { Home, Drawer, Property } class MenuEntry implements BaseModule { - final String value; + final String key; final IconData icon; final String name; final String route; final List types; const MenuEntry({ - required this.value, + required this.key, required this.icon, required this.name, required this.route, @@ -22,7 +22,7 @@ class MenuEntry implements BaseModule { static List entries = [ MenuEntry( - value: 'FRE-HUB-AGE-PROV-PRESTADOR', + key: 'FRE-HUB-AGE-PROV-PRESTADOR', icon: Icons.engineering_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Agendar Prestadores', @@ -32,7 +32,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-AGE-PROV-DELIVERY', + key: 'FRE-HUB-AGE-PROV-DELIVERY', icon: Icons.sports_motorsports_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Agendar Delivery', @@ -42,7 +42,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-FASTPASS', + key: 'FRE-HUB-FASTPASS', icon: Icons.attach_email_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Fast Pass', @@ -52,7 +52,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-COMPLETE-SCHEDULE', + key: 'FRE-HUB-COMPLETE-SCHEDULE', icon: Icons.event, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Agenda Completa', @@ -62,7 +62,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-ORDERS', + key: 'FRE-HUB-ORDERS', icon: Icons.inventory_2_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Minhas Encomendas', @@ -72,7 +72,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-RESERVATIONS', + key: 'FRE-HUB-RESERVATIONS', icon: Icons.event_available, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Reservas', @@ -82,7 +82,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-VISITORS', + key: 'FRE-HUB-VISITORS', icon: Icons.person_add_alt_1_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Cadastrar Visitantes', @@ -92,7 +92,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-QRCODE', + key: 'FRE-HUB-QRCODE', icon: Icons.qr_code, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'QRCode de Acesso', @@ -102,7 +102,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-PETS', + key: 'FRE-HUB-PETS', icon: Icons.pets, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Pets', @@ -112,7 +112,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-ACCESS', + key: 'FRE-HUB-ACCESS', icon: Icons.transfer_within_a_station_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Consultar Acessos', @@ -122,7 +122,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-LIBERATIONS', + key: 'FRE-HUB-LIBERATIONS', icon: Icons.how_to_reg_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Consultar Liberações', @@ -132,7 +132,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-MESSAGES', + key: 'FRE-HUB-MESSAGES', icon: Icons.chat_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Consultar Mensagens', @@ -142,7 +142,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-PROPERTY', + key: 'FRE-HUB-PROPERTY', icon: Icons.home, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Sobre a Propriedade', @@ -153,7 +153,7 @@ class MenuEntry implements BaseModule { ), MenuEntry( - value: 'FRE-HUB-PEOPLE', + key: 'FRE-HUB-PEOPLE', icon: Icons.groups, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Pessoas na Propriedade', @@ -163,7 +163,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-SETTINGS', + key: 'FRE-HUB-SETTINGS', icon: Icons.settings, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Configurações', @@ -173,7 +173,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-LOGOUT', + key: 'FRE-HUB-LOGOUT', icon: Icons.exit_to_app, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Sair', @@ -183,28 +183,28 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Drawer], ), MenuEntry( - value: 'FRE-HUB-RESIDENTS', + key: 'FRE-HUB-RESIDENTS', icon: Icons.groups, name: 'Residents', route: '/residentsOnThePropertyPage', types: [MenuEntryType.Property], ), MenuEntry( - value: 'FRE-HUB-VEHICLES', + key: 'FRE-HUB-VEHICLES', icon: Icons.directions_car, name: 'Vehicles', route: '/vehiclesOnThePropertyPage', types: [MenuEntryType.Property], ), MenuEntry( - value: 'FRE-HUB-OPENED-VISITS', + key: 'FRE-HUB-OPENED-VISITS', icon: Icons.perm_contact_calendar, name: 'Opened Visits', route: '/visitsOnThePropertyPage', types: [MenuEntryType.Property], ), MenuEntry( - value: 'FRE-HUB-PETS-HISTORY', + key: 'FRE-HUB-PETS-HISTORY', icon: Icons.pets, name: 'Pets History', route: '/petsOnThePropertyPage', diff --git a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart index c3c11fba..79bf3454 100644 --- a/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart +++ b/lib/shared/components/molecules/menu/presentation/widgets/menu_factory.dart @@ -48,7 +48,7 @@ class Menufactory extends StatelessWidget { create: (context) => MenuBloc( style: view, item: item, - menuOptions: entry, + entries: entry, )..add(MenuEvent()), child: BlocBuilder( builder: (context, state) { diff --git a/lib/shared/components/molecules/modules/domain/entities/base_module.dart b/lib/shared/components/molecules/modules/domain/entities/base_module.dart index 662fa7b2..ef2c82a8 100644 --- a/lib/shared/components/molecules/modules/domain/entities/base_module.dart +++ b/lib/shared/components/molecules/modules/domain/entities/base_module.dart @@ -5,7 +5,7 @@ import 'package:hub/flutter_flow/nav/nav.dart'; abstract class BaseModule { - String get value; + String get key; String get name; IconData get icon; String get route; From 7f05d85aa3100424d6b492e0570d8f339c3d2f0e Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 14:13:22 -0300 Subject: [PATCH 47/75] WIP --- .../menu/data/data_sources/menu_local_data_source.dart | 4 ++-- .../molecules/menu/presentation/blocs/menu_bloc.dart | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index 84c0ffa8..536eef3a 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -15,8 +15,8 @@ abstract class MenuLocalDataSource { Future addMenuEntry(EnumMenuItem item, List entries, IconData icon, String text, Function() action); Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries); Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries); - Future processStartDate(String startDate, MenuEntry opt); - Future processExpirationDate(String expirationDate, MenuEntry opt); + Future processStartDate(String startDate, MenuEntry entry); + Future processExpirationDate(String expirationDate, MenuEntry entry); } class MenuLocalDataSourceImpl implements MenuLocalDataSource { diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index 0dd8431e..20eb96ad 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -43,8 +43,8 @@ class MenuBloc extends Bloc { Future _onMenuEvent(MenuEvent event, Emitter emit) async { await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - final entries = await MenuRepositoryImpl().generateMenuEntries(entries, item); - emit(state.copyWith(menuEntries: entries)); + final List NewEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item); + emit(state.copyWith(menuEntries: NewEntries)); } @override From eb093299d20dcabb6ceec1b0ae06c70adc40f572 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 16:20:29 -0300 Subject: [PATCH 48/75] fix: forever CircularLoadingIndicator --- lib/features/home/presentation/blocs/home_bloc.dart | 1 + lib/features/home/presentation/pages/home_page.dart | 3 ++- .../data/data_sources/locals_remote_data_source.dart | 1 + .../data/repositories/locals_repository_impl.dart | 3 +++ .../locals/presentation/blocs/local_profile_bloc.dart | 5 +++++ .../widgets/local_profile/local_profile_widget.dart | 11 +++++++++-- .../menu/data/repositories/menu_repository_impl.dart | 1 + .../molecules/menu/presentation/blocs/menu_bloc.dart | 4 ++++ .../data/repositories/license_repository_impl.dart | 5 ++++- lib/shared/helpers/database/database_helper.dart | 2 +- 10 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/features/home/presentation/blocs/home_bloc.dart b/lib/features/home/presentation/blocs/home_bloc.dart index bf6e580e..0df86d3b 100644 --- a/lib/features/home/presentation/blocs/home_bloc.dart +++ b/lib/features/home/presentation/blocs/home_bloc.dart @@ -1,3 +1,4 @@ + import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 20767d9f..288ad5da 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -43,7 +43,8 @@ class _HomePageWidgetState extends State { ], child: Builder( builder: (context) { - context.read().updateProfile(context); + LocalsRepositoryImpl.license.add(true); + // context.read().updateProfile(context); return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index f252201a..2fe1c4c4 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -70,6 +70,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { @override Future processLocals(BuildContext context) async { + log('() => processLocals'); try { final GetLocalsCall callback = PhpGroup.getLocalsCall; final ApiCallResponse response = await callback.call(); diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index e2dbd15f..d848fbbc 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; @@ -17,6 +19,7 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { + log('update'); LocalsRepositoryImpl.license.add(false); final bool response = await remoteDataSource.processLocals(context); context.read().add(LocalProfileEvent()); diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index 754abc2f..4017f06e 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; @@ -32,14 +34,17 @@ class LocalProfileBloc extends Bloc { } Future _onLocalProfileEvent(LocalProfileEvent event, Emitter emit) async { + log('LocalProfileBloc: _onLocalProfileEvent'); final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); } void updateProfile(BuildContext context) { + LocalsRepositoryImpl.license.add(false); context.read().add(MenuEvent()); add(LocalProfileEvent()); + LocalsRepositoryImpl.license.add(true); } } diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 7153de8c..e31ddac1 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -38,13 +40,18 @@ class _LocalProfileComponentWidgetState extends State 20 ? 12 : scaledFontSize; - + log('LocalProfileComponentWidget: build'); + log('snapshot.connectionState: ${snapshot.connectionState}'); + log('snapshot.hasError: ${snapshot.hasError}'); + log('snapshot.hasData: ${snapshot.hasData}'); + log('snapshot.data: ${snapshot.data}'); + if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: CircularProgressIndicator()); } else if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); } else if (!snapshot.hasData || snapshot.data! == false) { - + return BlocBuilder( builder: (context, state) { return _buildDefaultLocalProfile(context, limitedFontSize); diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 1f5a0bb7..47011cf4 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -19,6 +19,7 @@ class MenuRepositoryImpl implements MenuRepository { List entries = []; try { for (var entry in menuEntries) { + log('Processing entry: ${entry.key}'); final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); if (isDefault) continue; final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index 20eb96ad..e8c10663 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'dart:developer'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -42,7 +43,10 @@ class MenuBloc extends Bloc { } Future _onMenuEvent(MenuEvent event, Emitter emit) async { + log('MenuBloc: waitForSaveCompletion'); + await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); + log('MenuBloc: _onMenuEvent'); final List NewEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item); emit(state.copyWith(menuEntries: NewEntries)); } diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index 3ff81998..e751ef60 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -19,6 +19,7 @@ class LicenseRepositoryImpl implements LicenseRepository { @override Future updateLicense() async { + log('updateLicense'); bool result = false; final bool isNewVersion = await localDataSource.isNewVersion(); log('isNewVersion: $isNewVersion'); @@ -39,7 +40,9 @@ class LicenseRepositoryImpl implements LicenseRepository { @override Future getLicense(String key) async { - return await localDataSource.get(key); + final response = await localDataSource.get(key); + log('getLicense: $key: $response'); + return response; } @override diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index a5054993..258e81d7 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -32,7 +32,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, ); - // await LicenseRepositoryImpl().updateLicense(); + await LicenseRepositoryImpl().updateLicense(); isInitialized = true; } From b8c2aab73ca70f903fb7701ff5384f0d5ea460c6 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 16:54:07 -0300 Subject: [PATCH 49/75] fix: bloc provider in homePage --- .../home/presentation/pages/home_page.dart | 54 ++++++++----------- lib/main.dart | 46 +++++++++++----- .../repositories/locals_repository_impl.dart | 5 +- .../blocs/local_profile_bloc.dart | 12 ++--- .../local_profile/local_profile_widget.dart | 15 +++--- .../repositories/menu_repository_impl.dart | 2 +- .../menu/presentation/blocs/menu_bloc.dart | 5 +- .../repositories/license_repository_impl.dart | 2 - .../helpers/storage/keychain_storage.dart | 4 +- 9 files changed, 76 insertions(+), 69 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 288ad5da..27a16dba 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -21,41 +21,31 @@ class HomePageWidget extends StatefulWidget { class _HomePageWidgetState extends State { final scaffoldKey = GlobalKey(); + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addPostFrameCallback((_) async { + await LocalsRepositoryImpl().update(context); + }); + } + @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => MenuBloc( - style: MenuView.list_grid, - item: EnumMenuItem.button, - entries: MenuEntry.getEntriesByType(MenuEntryType.Home), - )..add(MenuEvent()), - ), - BlocProvider( - create: (context) => HomeBloc()..add(HomeEvent()), - ), - BlocProvider( - create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), - ), - - ], - child: Builder( - builder: (context) { - LocalsRepositoryImpl.license.add(true); - // context.read().updateProfile(context); - return Scaffold( - key: scaffoldKey, - backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - drawerEnableOpenDragGesture: true, - drawerDragStartBehavior: DragStartBehavior.start, - drawer: CustomDrawer(), - appBar: buildAppBar(context), - body: buildPage(context), - ); - }, - ), + return Builder( + builder: (context) { + LocalsRepositoryImpl.license.add(true); + // context.read().updateProfile(context); + return Scaffold( + key: scaffoldKey, + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, + drawerEnableOpenDragGesture: true, + drawerDragStartBehavior: DragStartBehavior.start, + drawer: CustomDrawer(), + appBar: buildAppBar(context), + body: buildPage(context), + ); + }, ); } diff --git a/lib/main.dart b/lib/main.dart index 324221f9..f100c8c7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:hub/backend/notifications/notification_service.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; @@ -19,7 +20,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hub/shared/extensions/string_extensions.dart'; import 'backend/notifications/firebase_messaging_service.dart'; +import 'features/home/index.dart'; import 'initialization.dart'; +import 'shared/components/molecules/menu/index.dart'; import 'shared/components/molecules/modules/index.dart'; final GlobalKey navigatorKey = GlobalKey(); @@ -189,24 +192,43 @@ class _AppState extends State with WidgetsBindingObserver { @override void didChangeAppLifecycleState(AppLifecycleState state) async { if (state == AppLifecycleState.detached) { - await LocalsRepositoryImpl().update(context); + LocalsRepositoryImpl.license.add(false); + final response = await LocalsRepositoryImpl().update(context); + LocalsRepositoryImpl.license.add(response); await FirebaseMessagingService().updateDeviceToken(); } } @override Widget build(BuildContext context) { - return MaterialApp.router( - key: navigatorKey, - title: 'FRE ACCESS HUB', - builder: builder, - localizationsDelegates: localizationsDelegates, - locale: _locale, - supportedLocales: supportedLocales, - theme: _theme, - darkTheme: _darkTheme, - themeMode: _themeMode, - routerConfig: _router, + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => MenuBloc( + style: MenuView.list_grid, + item: EnumMenuItem.button, + entries: MenuEntry.getEntriesByType(MenuEntryType.Home), + )..add(MenuEvent()), + ), + BlocProvider( + create: (context) => HomeBloc()..add(HomeEvent()), + ), + BlocProvider( + create: (context) => LocalProfileBloc()..add(LocalProfileEvent()), + ), + ], + child: MaterialApp.router( + key: navigatorKey, + title: 'FRE ACCESS HUB', + builder: builder, + localizationsDelegates: localizationsDelegates, + locale: _locale, + supportedLocales: supportedLocales, + theme: _theme, + darkTheme: _darkTheme, + themeMode: _themeMode, + routerConfig: _router, + ), ); } } diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index d848fbbc..7d2d79fa 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -19,11 +19,10 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { - log('update'); - LocalsRepositoryImpl.license.add(false); + // LocalsRepositoryImpl.license.add(false); final bool response = await remoteDataSource.processLocals(context); context.read().add(LocalProfileEvent()); - LocalsRepositoryImpl.license.add(response); + // LocalsRepositoryImpl.license.add(response); return response; } diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index 4017f06e..db8d2a02 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -40,12 +40,12 @@ class LocalProfileBloc extends Bloc { emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); } - void updateProfile(BuildContext context) { - LocalsRepositoryImpl.license.add(false); - context.read().add(MenuEvent()); - add(LocalProfileEvent()); - LocalsRepositoryImpl.license.add(true); - } + // void updateProfile(BuildContext context) { + // LocalsRepositoryImpl.license.add(false); + // context.read().add(MenuEvent()); + // add(LocalProfileEvent()); + // LocalsRepositoryImpl.license.add(true); + // } } class LocalProfileComponentModel extends FlutterFlowModel { diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index e31ddac1..9d436de2 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -25,7 +25,9 @@ class _LocalProfileComponentWidgetState extends State 20 ? 12 : scaledFontSize; - - log('LocalProfileComponentWidget: build'); - log('snapshot.connectionState: ${snapshot.connectionState}'); - log('snapshot.hasError: ${snapshot.hasError}'); - log('snapshot.hasData: ${snapshot.hasData}'); - log('snapshot.data: ${snapshot.data}'); - if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: CircularProgressIndicator()); } else if (snapshot.hasError) { @@ -103,7 +98,9 @@ class _LocalProfileComponentWidgetState extends State entries = []; try { for (var entry in menuEntries) { - log('Processing entry: ${entry.key}'); + // log('Processing entry: ${entry.key}'); final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); if (isDefault) continue; final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index e8c10663..8c249bf9 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -3,6 +3,8 @@ import 'dart:async'; import 'dart:developer'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; @@ -43,10 +45,9 @@ class MenuBloc extends Bloc { } Future _onMenuEvent(MenuEvent event, Emitter emit) async { - log('MenuBloc: waitForSaveCompletion'); await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - log('MenuBloc: _onMenuEvent'); + final List NewEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item); emit(state.copyWith(menuEntries: NewEntries)); } diff --git a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart index e751ef60..1ef3589a 100644 --- a/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart +++ b/lib/shared/components/molecules/modules/data/repositories/license_repository_impl.dart @@ -22,7 +22,6 @@ class LicenseRepositoryImpl implements LicenseRepository { log('updateLicense'); bool result = false; final bool isNewVersion = await localDataSource.isNewVersion(); - log('isNewVersion: $isNewVersion'); result = await remoteDataSource.setupLicense(database, isNewVersion); if (isNewVersion) { result = await remoteDataSource.fetchLicenses(isNewVersion); @@ -41,7 +40,6 @@ class LicenseRepositoryImpl implements LicenseRepository { @override Future getLicense(String key) async { final response = await localDataSource.get(key); - log('getLicense: $key: $response'); return response; } diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index 0431c8f1..d662dc1a 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -28,7 +28,7 @@ class KeychainHelper implements BaseStorage { if (response.isEmpty) { return null; } - log('() => get keychain: $key : ${response.first['value']}'); + // log('() => get keychain: $key : ${response.first['value']}'); return response.first['value'].toString(); } @@ -47,7 +47,7 @@ class KeychainHelper implements BaseStorage { 'createdAt': date, }, conflictAlgorithm: ConflictAlgorithm.replace); - log('() => set keychain: $key : $value'); + // log('() => set keychain: $key : $value'); } @override From 6e100c84ce24e6ab90f238e3c9abf31fb6df1893 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 17:02:17 -0300 Subject: [PATCH 50/75] fix localprofile button --- .../local_profile/local_profile_widget.dart | 164 +++++++++--------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 9d436de2..cfcfa437 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -21,13 +21,18 @@ class LocalProfileComponentWidget extends StatefulWidget { } class _LocalProfileComponentWidgetState extends State { + bool _isLoading = false; + Future retrieveProfileInfo() async { + + setState(() {_isLoading = true;}); - Future callback() async { await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); LocalsRepositoryImpl.license.add(false); final response = await LocalsRepositoryImpl().update(context); LocalsRepositoryImpl.license.add(response); + + setState(() {_isLoading = false;}); } @override @@ -58,7 +63,7 @@ class _LocalProfileComponentWidgetState extends State( builder: (context, state) { - return _buildAsyncLocalProfile(context, state, limitedFontSize, callback); + return _buildAsyncLocalProfile(context, state, limitedFontSize); }, ); @@ -96,12 +101,7 @@ class _LocalProfileComponentWidgetState extends State Container( - decoration: BoxDecoration( - image: DecorationImage( - image: imageProvider, - fit: BoxFit.cover, + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: const AlignmentDirectional(-1.0, 0.0), + child: Padding( + padding: const EdgeInsets.all(2.0), + child: InkWell( + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: _isLoading ? null : retrieveProfileInfo, + child: ClipRRect( + borderRadius: BorderRadius.circular(200.0), + child: CachedNetworkImage( + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + ), ), ), + imageUrl: valueOrDefault('https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', 'assets/images/home.png'), + width: 80.0, + height: 80.0, + fit: BoxFit.cover, + alignment: const Alignment(0.0, 0.0), + placeholder: (context, url) => Image.asset('assets/images/home.png'), + errorListener: (_) => Image.asset('assets/images/home.png'), + errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), ), - imageUrl: valueOrDefault('https://freaccess.com.br/freaccess/Images/Clients/${state.cliUUID}.png', 'assets/images/home.png'), - width: 80.0, - height: 80.0, - fit: BoxFit.cover, - alignment: const Alignment(0.0, 0.0), - placeholder: (context, url) => Image.asset('assets/images/home.png'), - errorListener: (_) => Image.asset('assets/images/home.png'), - errorWidget: (_, __, ___) => Image.asset('assets/images/home.png'), - ), - )), - ), - ), - Expanded( - child: Tooltip( - message: valueOrDefault( - convertToUppercase(state.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', - ), + )), ), - child: Text( - valueOrDefault( + ), + Expanded( + child: Tooltip( + message: valueOrDefault( convertToUppercase(state.cliName), FFLocalizations.of(context).getVariableText( ptText: 'SEM LOCAL VINCULADO', enText: 'NO LINKED LOCAL', ), ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: FlutterFlowTheme.of(context).labelMedium.override( - fontFamily: 'Nunito', - color: FlutterFlowTheme.of(context).info, - fontSize: limitedFontSize, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + child: Text( + valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', ), + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), + ), ), ), - ), - ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), + ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), + ), ), ), ), - ), - ); - - - } + ); + + + } } From 6cd090f361e54e6481a8578f73f294bb28b81431 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 17:46:35 -0300 Subject: [PATCH 51/75] fix: requests overflow --- .../home/presentation/pages/home_page.dart | 14 ++++++++++++-- lib/flutter_flow/nav/nav.dart | 9 ++++++++- lib/flutter_flow/nav/serialization_util.dart | 4 +++- .../pets_history_screen.dart | 5 ++++- lib/pages/pets_page/pets_page_widget.dart | 5 ++++- .../menu/presentation/mappers/menu_entry.dart | 4 ++-- .../authentication/authentication_service.dart | 8 +++++--- 7 files changed, 38 insertions(+), 11 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 27a16dba..2ed1b623 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -12,7 +14,11 @@ import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; class HomePageWidget extends StatefulWidget { - const HomePageWidget({super.key}); + const HomePageWidget({ + super.key, + this.update, + }); + final Future Function(BuildContext context)? update; @override State createState() => _HomePageWidgetState(); @@ -25,7 +31,11 @@ class _HomePageWidgetState extends State { void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) async { - await LocalsRepositoryImpl().update(context); + log('update: ${widget.update == null}'); + log('update: ${widget.update}'); + if (widget.update != null) { + await widget.update!(context); + } }); } diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 11bb57dd..30aacafd 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -122,7 +122,14 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { token: token, ); }), - FFRoute(name: 'homePage', path: '/homePage', builder: (context, params) => HomePageWidget(key: UniqueKey())), + FFRoute(name: 'homePage', path: '/homePage', builder: (context, params) { + log('params: $params'); + final Future Function(BuildContext context)? update = params.getParam('update', ParamType.Function); + log('update: $update'); + + return HomePageWidget(key: UniqueKey(), update: update); + + }), FFRoute(name: 'petsOnThePropertyPage', path: '/petsOnThePropertyPage', builder: (context, params) => Scaffold(body: const PetsHistoryScreen(isApp: true))), FFRoute(name: 'vehiclesOnThePropertyPage', path: '/vehiclesOnThePropertyPage', builder: (context, params) => const VehicleOnTheProperty()), FFRoute(name: 'receptionPage', path: '/receptionPage', builder: (context, params) => const ReceptionPageWidget()), diff --git a/lib/flutter_flow/nav/serialization_util.dart b/lib/flutter_flow/nav/serialization_util.dart index 02f636c4..18018306 100644 --- a/lib/flutter_flow/nav/serialization_util.dart +++ b/lib/flutter_flow/nav/serialization_util.dart @@ -150,7 +150,7 @@ enum ParamType { FFPlace, FFUploadedFile, JSON, - + Function, DataStruct, Enum, } @@ -186,6 +186,8 @@ dynamic deserializeParam( switch (paramType) { case ParamType.int: return int.tryParse(param); + case ParamType.Function: + return param; case ParamType.double: return double.tryParse(param); case ParamType.String: diff --git a/lib/pages/pets_on_the_property_page/pets_history_screen.dart b/lib/pages/pets_on_the_property_page/pets_history_screen.dart index 5c29a948..b0663b1d 100644 --- a/lib/pages/pets_on_the_property_page/pets_history_screen.dart +++ b/lib/pages/pets_on_the_property_page/pets_history_screen.dart @@ -58,7 +58,10 @@ class _PetsHistoryScreenState extends State with TickerProvid return AppBar( backgroundColor: FlutterFlowTheme.of(context).primaryBackground, automaticallyImplyLeading: false, - title: Text(FFLocalizations.of(context).getVariableText(enText: 'Pets', ptText: 'Pets'), + title: Text(FFLocalizations.of(context).getVariableText( + ptText: 'Cadastrar Pets', + enText: 'Pets Register', + ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).primaryText, diff --git a/lib/pages/pets_page/pets_page_widget.dart b/lib/pages/pets_page/pets_page_widget.dart index 4beac680..a2d7c1f7 100644 --- a/lib/pages/pets_page/pets_page_widget.dart +++ b/lib/pages/pets_page/pets_page_widget.dart @@ -75,7 +75,10 @@ class _PetsPageWidgetState extends State with SingleTickerProvid PreferredSizeWidget _buildAppBar(BuildContext context) { return AppBarUtil( - title: 'Pets', + title: FFLocalizations.of(context).getVariableText( + ptText: 'Cadastrar Pets', + enText: 'Pets Register', + ), onBackButtonPressed: () => context.pop(), ); } diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index 6097c501..de323a54 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -105,8 +105,8 @@ class MenuEntry implements BaseModule { key: 'FRE-HUB-PETS', icon: Icons.pets, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Pets', - enText: 'Pets', + ptText: 'Cadastrar Pets', + enText: 'Pets Register' ), route: '/petsPage', types: [MenuEntryType.Home, MenuEntryType.Drawer], diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index ae3d457a..ef3e4ffb 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -1,6 +1,7 @@ import 'dart:developer'; import 'package:flutter/material.dart'; +import 'package:hub/features/home/presentation/pages/home_page.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; @@ -10,6 +11,7 @@ import 'package:hub/shared/utils/snackbar_util.dart'; import '../../../backend/api_requests/api_calls.dart'; import '../../../flutter_flow/flutter_flow_util.dart'; import '../../../flutter_flow/random_data_util.dart'; +import '../../components/molecules/locals/data/index.dart'; import '../../utils/device_util.dart'; import '../../utils/dialog_util.dart'; import '../../utils/log_util.dart'; @@ -30,11 +32,11 @@ class AuthenticationService { await StorageHelper().set(SecureStorageKey.haveLocal.value, false); context.go('/receptionPage'); } else { - await StorageHelper().set(SecureStorageKey.haveLocal.value, true); - context.go('/homePage'); + await StorageHelper().set(SecureStorageKey.isLogged.value, true); + context.go('/homePage', extra: {'update': LocalsRepositoryImpl().update}); } - await StorageHelper().set(SecureStorageKey.isLogged.value, true); + } static Future signIn( From c6840638c77b46db5ffe8057dfa445d8862503ed Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 17:47:56 -0300 Subject: [PATCH 52/75] fix: twice exception onLogin --- .../authentication_service.dart | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index ef3e4ffb..ce753550 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -18,25 +18,28 @@ import '../../utils/log_util.dart'; class AuthenticationService { static Future login(BuildContext context) async { - final GetLocalsCall callback = PhpGroup.getLocalsCall; + try { + final GetLocalsCall callback = PhpGroup.getLocalsCall; + final response = await callback.call(); - final response = await callback.call(); + if (response.jsonBody['error']) { + await DialogUtil.errorDefault(context); + return; + } - if (response.jsonBody['error']) { + List locals = response.jsonBody['locais'] ?? []; + + if (locals.isEmpty) { + await StorageHelper().set(SecureStorageKey.haveLocal.value, false); + context.go('/receptionPage'); + } else { + await StorageHelper().set(SecureStorageKey.isLogged.value, true); + context.go('/homePage', extra: {'update': LocalsRepositoryImpl().update}); + } + } catch (e, s) { await DialogUtil.errorDefault(context); - return; + LogUtil.requestAPIFailed('getLocals.php', '', "Get Locals", e, s); } - List locals = response.jsonBody['locais'] ?? []; - - if (locals.isEmpty) { - await StorageHelper().set(SecureStorageKey.haveLocal.value, false); - context.go('/receptionPage'); - } else { - await StorageHelper().set(SecureStorageKey.isLogged.value, true); - context.go('/homePage', extra: {'update': LocalsRepositoryImpl().update}); - } - - } static Future signIn( @@ -86,7 +89,6 @@ class AuthenticationService { await DialogUtil.errorDefault(context); } else { await DialogUtil.error(context, response.jsonBody['error_msg'].toString()); - await DialogUtil.error(context, response.jsonBody['error_msg'].toString()); } } } From 758ee5148e296bea3c91b3ab331ebf34aece1ac9 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 17:52:22 -0300 Subject: [PATCH 53/75] WIP --- .../home/presentation/pages/home_page.dart | 2 -- .../menu/presentation/mappers/menu_entry.dart | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 2ed1b623..2d64565d 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -31,8 +31,6 @@ class _HomePageWidgetState extends State { void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) async { - log('update: ${widget.update == null}'); - log('update: ${widget.update}'); if (widget.update != null) { await widget.update!(context); } diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index de323a54..87875b39 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -69,7 +69,7 @@ class MenuEntry implements BaseModule { enText: 'My Orders', ), route: '/packageOrder', - types: [MenuEntryType.Home, MenuEntryType.Drawer], + types: [MenuEntryType.Home, MenuEntryType.Drawer, MenuEntryType.Property], ), MenuEntry( key: 'FRE-HUB-RESERVATIONS', @@ -185,28 +185,40 @@ class MenuEntry implements BaseModule { MenuEntry( key: 'FRE-HUB-RESIDENTS', icon: Icons.groups, - name: 'Residents', + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ), route: '/residentsOnThePropertyPage', types: [MenuEntryType.Property], ), MenuEntry( key: 'FRE-HUB-VEHICLES', icon: Icons.directions_car, - name: 'Vehicles', + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Veículos na Propriedade', + enText: 'Vehicles on the Property', + ), route: '/vehiclesOnThePropertyPage', types: [MenuEntryType.Property], ), MenuEntry( key: 'FRE-HUB-OPENED-VISITS', icon: Icons.perm_contact_calendar, - name: 'Opened Visits', + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Visitas Abertas', + enText: 'Opened Visits', + ), route: '/visitsOnThePropertyPage', types: [MenuEntryType.Property], ), MenuEntry( key: 'FRE-HUB-PETS-HISTORY', icon: Icons.pets, - name: 'Pets History', + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Histórico de Pets', + enText: 'Pets History', + ), route: '/petsOnThePropertyPage', types: [MenuEntryType.Property], ), From 4925433c92b022a050337d5e24a7e45a6d309276 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Thu, 5 Dec 2024 17:12:34 -0300 Subject: [PATCH 54/75] WIP: backup --- ..._arrow_linked_locals_component_widget.dart | 2 + lib/flutter_flow/custom_functions.dart | 2 +- .../pets_history_screen.dart | 4 +- .../locals_remote_data_source.dart | 13 +-- .../repositories/locals_repository_impl.dart | 15 +++- .../blocs/local_profile_bloc.dart | 11 ++- .../local_profile/local_profile_widget.dart | 64 ++++++++++---- .../molecules/locals/utils/local_util.dart | 7 +- .../data_sources/menu_local_data_source.dart | 11 +-- .../repositories/menu_repository_impl.dart | 35 +++++++- .../menu/presentation/mappers/menu_entry.dart | 88 +++++++++---------- .../modules/constants/license_constants.dart | 13 +-- .../license_local_data_source.dart | 33 ++++--- .../license_remote_data_source.dart | 28 +++--- .../modules/domain/entities/license.dart | 6 +- .../helpers/database/database_helper.dart | 23 ++--- lib/shared/helpers/storage/base_storage.dart | 3 + 17 files changed, 224 insertions(+), 134 deletions(-) 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 8d781daa..58be572b 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 @@ -106,6 +106,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState extends State> stringToMap(String v) async { throw FormatException('Invalid key-value pair: $part of $v'); } final key = keyValue[0].trim(); - final value = keyValue.length > 1 ? keyValue[1].trim() : ''; + final value = keyValue.sublist(1).join(':').trim(); // Join the remaining parts to handle DateTime correctly return MapEntry(key, value); }), )); diff --git a/lib/pages/pets_on_the_property_page/pets_history_screen.dart b/lib/pages/pets_on_the_property_page/pets_history_screen.dart index b0663b1d..b32ba509 100644 --- a/lib/pages/pets_on_the_property_page/pets_history_screen.dart +++ b/lib/pages/pets_on_the_property_page/pets_history_screen.dart @@ -59,8 +59,8 @@ class _PetsHistoryScreenState extends State with TickerProvid backgroundColor: FlutterFlowTheme.of(context).primaryBackground, automaticallyImplyLeading: false, title: Text(FFLocalizations.of(context).getVariableText( - ptText: 'Cadastrar Pets', - enText: 'Pets Register', + ptText: 'Pets', + enText: 'Pets', ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Nunito', diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index 2fe1c4c4..ea9fa7a9 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -46,7 +46,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return; } @@ -86,7 +86,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return false; } @@ -137,7 +137,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Error getting locals, verify your connection', ptText: 'Erro ao obter locais, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); return false; } } @@ -154,7 +154,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Verify your connection', ptText: 'Verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return false; } @@ -163,7 +163,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { final GetLocalsCall callback = PhpGroup.getLocalsCall; response = await callback.call(); final String errorMsg = response.jsonBody['error_msg'] ?? 'Local indisponível'; - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, response)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, response)); return false; } else { await LocalUtil.updateStorageUtil(response.jsonBody); @@ -175,7 +175,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { enText: 'Error getting data, verify your connection', ptText: 'Erro ao obter dados, verifique sua conexão', ); - await DialogUtil.error(context, errorMsg).whenComplete(() => selectLocal(context, null)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context, null)); return false; } } @@ -212,6 +212,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { await PhpGroup.resopndeVinculo.call(tarefa: 'I').then((value) async { if (value.jsonBody['error'] == false) { await StorageHelper().set(KeychainStorageKey.clientName.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); context.pop(); context.go( diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 7d2d79fa..1c8580ad 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -4,6 +4,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; import 'package:rxdart/rxdart.dart'; class LocalsRepositoryImpl implements LocalsRepository { @@ -19,10 +22,16 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { - // LocalsRepositoryImpl.license.add(false); - final bool response = await remoteDataSource.processLocals(context); + bool response = false; + while (!response) { + response = await remoteDataSource.processLocals(context); + if (!response) { + await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); + const String errorMsg = 'Erro ao atualizar locais'; + await DialogUtil.error(context, errorMsg); + } + } context.read().add(LocalProfileEvent()); - // LocalsRepositoryImpl.license.add(response); return response; } diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index db8d2a02..95faea30 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -16,13 +16,15 @@ class LocalProfileEvent { class LocalProfileState { final String cliName; final String cliUUID; + final String ownerName; - LocalProfileState({this.cliName = '', this.cliUUID = ''}); + LocalProfileState({this.cliName = '', this.cliUUID = '', this.ownerName = ''}); - LocalProfileState copyWith({String? cliName, String? cliUUID}) { + LocalProfileState copyWith({String? cliName, String? ownerName, String? cliUUID}) { return LocalProfileState( cliName: cliName ?? this.cliName, + ownerName: ownerName ?? this.ownerName, cliUUID: cliUUID ?? this.cliUUID, ); } @@ -36,8 +38,9 @@ class LocalProfileBloc extends Bloc { Future _onLocalProfileEvent(LocalProfileEvent event, Emitter emit) async { log('LocalProfileBloc: _onLocalProfileEvent'); final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + final ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? ''; final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; - emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); + emit(state.copyWith(cliName: cliName, cliUUID: cliUUID, ownerName: ownerName)); } // void updateProfile(BuildContext context) { @@ -51,6 +54,7 @@ class LocalProfileBloc extends Bloc { class LocalProfileComponentModel extends FlutterFlowModel { String cliName = ''; String cliUUID = ''; + String ownerName = ''; VoidCallback? setStateCallback; @override @@ -60,6 +64,7 @@ class LocalProfileComponentModel extends FlutterFlowModel getData() async { cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? ''; cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; setStateCallback?.call(); } diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index cfcfa437..297a7d0d 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -211,33 +211,61 @@ class _LocalProfileComponentWidgetState extends State( - convertToUppercase(state.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', - ), - ), - child: Text( - valueOrDefault( - convertToUppercase(state.cliName), - FFLocalizations.of(context).getVariableText( - ptText: 'SEM LOCAL VINCULADO', - enText: 'NO LINKED LOCAL', + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Tooltip( + message: valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + ), + child: Text( + valueOrDefault( + convertToUppercase(state.cliName), + FFLocalizations.of(context).getVariableText( + ptText: 'SEM LOCAL VINCULADO', + enText: 'NO LINKED LOCAL', + ), + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).info, + fontSize: limitedFontSize, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), ), ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: FlutterFlowTheme.of(context).labelMedium.override( + Tooltip( + message: valueOrDefault( + ' '+state.ownerName, + '' + ), + child: Text( + valueOrDefault( + state.ownerName.length > 30 ? '${state.ownerName.substring(0, 20)}...' : state.ownerName, + '' + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: FlutterFlowTheme.of(context).labelMedium.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).info, fontSize: limitedFontSize, letterSpacing: 0.0, fontWeight: FontWeight.w500, useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), ), - ), + ), + ], ), ), ].divide(const SizedBox(width: 20.0)).addToStart(const SizedBox(width: 20.0)).addToEnd(const SizedBox(width: 20.0)), diff --git a/lib/shared/components/molecules/locals/utils/local_util.dart b/lib/shared/components/molecules/locals/utils/local_util.dart index 8c6395a5..8fe8350d 100644 --- a/lib/shared/components/molecules/locals/utils/local_util.dart +++ b/lib/shared/components/molecules/locals/utils/local_util.dart @@ -36,7 +36,7 @@ class LocalUtil { await DialogUtil.warning(context, errorMsg); return; } - await DialogUtil.error(context, errorMsg).whenComplete(() async => await LocalsRemoteDataSourceImpl().selectLocal(context, null)); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await LocalsRemoteDataSourceImpl().selectLocal(context, null)); } static Future handleUnavailable(BuildContext context, List locals) async { @@ -45,11 +45,15 @@ class LocalUtil { await StorageHelper().set(KeychainStorageKey.clientUUID.value, locals[0]['CLI_ID']); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID']); await StorageHelper().set(KeychainStorageKey.clientName.value, locals[0]['CLI_NOME']); + await StorageHelper().set(KeychainStorageKey.ownerName.value, locals[0]['CLU_OWNER_DSC']); + var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, ''); await StorageHelper().set(KeychainStorageKey.clientName.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); + return false; } if (response.jsonBody['error'] == false) return await LocalsRemoteDataSourceImpl().processData(context).then((value) => value); @@ -66,6 +70,7 @@ class LocalUtil { await StorageHelper().set(KeychainStorageKey.clientUUID.value, local['CLI_ID']); await StorageHelper().set(KeychainStorageKey.ownerUUID.value, local['CLU_OWNER_ID']); await StorageHelper().set(KeychainStorageKey.clientName.value, local['CLI_NOME']); + await StorageHelper().set(KeychainStorageKey.ownerName.value, local['CLU_OWNER_DSC']); await StorageHelper().set(KeychainStorageKey.userName.value, local['USU_NOME']); return await LocalsRemoteDataSourceImpl().processData(context); } diff --git a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart index 536eef3a..113df0e4 100644 --- a/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart +++ b/lib/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart @@ -14,7 +14,7 @@ import '../../../modules/domain/entities/index.dart'; abstract class MenuLocalDataSource { Future addMenuEntry(EnumMenuItem item, List entries, IconData icon, String text, Function() action); Future processDisplayDefault(EnumMenuItem item, MenuEntry opt, List entries); - Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries); + Future handleMenu(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries); Future processStartDate(String startDate, MenuEntry entry); Future processExpirationDate(String expirationDate, MenuEntry entry); } @@ -50,7 +50,7 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { } @override - Future processDisplay(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries) async { + Future handleMenu(EnumMenuItem item, EnumDisplay display, MenuEntry opt, List entries) async { try { switch (display.value) { case 'VISIVEL': @@ -75,13 +75,14 @@ class MenuLocalDataSourceImpl implements MenuLocalDataSource { Future processStartDate(String startDate, MenuEntry opt) async { try { if (startDate.isEmpty) return true; - final start = DateTime.tryParse(startDate); - return start != null && DateTime.now().isAfter(start); + final start = DateTime.tryParse(startDate); + if (start == null) return false; + return DateTime.now().isAfter(start); } catch (e) { log('Error processing start date for module ${opt.key}: $e'); } return false; - } + } @override Future processExpirationDate(String expirationDate, MenuEntry opt) async { diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 36ca3e67..3f2c2f6f 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -1,12 +1,17 @@ +import 'dart:convert'; import 'dart:developer'; import 'package:hub/flutter_flow/custom_functions.dart'; +import 'package:hub/main.dart'; import 'package:hub/shared/components/molecules/menu/data/data_sources/menu_local_data_source.dart'; import 'package:hub/shared/components/molecules/menu/domain/respositories/menu_repository.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/extensions/string_extensions.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; class MenuRepositoryImpl implements MenuRepository { @@ -17,21 +22,31 @@ class MenuRepositoryImpl implements MenuRepository { Future> generateMenuEntries(List menuEntries, EnumMenuItem item) async { log('Generating menu entries for $item'); List entries = []; + final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean()); + try { for (var entry in menuEntries) { - // log('Processing entry: ${entry.key}'); + log('Processing entry: ${entry.key}'); final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); if (isDefault) continue; final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); - final display = EnumDisplay.fromString(licenseMap['display']); + final display = await processDisplay(licenseMap, isNewVersion); final startDate = licenseMap['startDate'] ?? ''; final expirationDate = licenseMap['expirationDate'] ?? ''; final isStarted = await menuDataSource.processStartDate(startDate, entry); final isExpired = await menuDataSource.processExpirationDate(expirationDate, entry); if (isStarted && !isExpired) { - await menuDataSource.processDisplay(item, display, entry, entries); + await menuDataSource.handleMenu(item, display, entry, entries); + } + if (isExpired) { + log('Entry ${entry.key} is expired'); + await menuDataSource.handleMenu(item, EnumDisplay.inactive, entry, entries); + } + if (!isStarted) { + log('Entry ${entry.key} is not started'); + await menuDataSource.handleMenu(item, EnumDisplay.inactive, entry, entries); } } } @@ -41,7 +56,21 @@ class MenuRepositoryImpl implements MenuRepository { return entries; } + Future processDisplay(Map module, bool isNewVersion) async { + const keysToCheck = [ + LicenseKeys.residents, + LicenseKeys.vehicles, + LicenseKeys.openedVisits + ]; + if (isNewVersion && keysToCheck.any((key) => module['key'] == key.value)) { + final displayValue = module['display'] == EnumDisplay.active ? 'VISIVEL' : 'INVISIVEL'; + await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-ABOUT-PROPERTY'], displayValue); + return EnumDisplay.fromString(displayValue); + } + + return EnumDisplay.fromString(module['display']); + } } \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart index 87875b39..02b59717 100644 --- a/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart +++ b/lib/shared/components/molecules/menu/presentation/mappers/menu_entry.dart @@ -22,7 +22,7 @@ class MenuEntry implements BaseModule { static List entries = [ MenuEntry( - key: 'FRE-HUB-AGE-PROV-PRESTADOR', + key: 'FRE-HUB-AGE-PROV-PREST', icon: Icons.engineering_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Agendar Prestadores', @@ -61,12 +61,52 @@ class MenuEntry implements BaseModule { route: '/scheduleCompleteVisitPage', types: [MenuEntryType.Home, MenuEntryType.Drawer], ), + MenuEntry( + key: 'FRE-HUB-RESIDENTS', + icon: Icons.groups, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Moradores', + enText: 'Residents', + ), + route: '/residentsOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + key: 'FRE-HUB-VEHICLES', + icon: Icons.directions_car, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Veículos', + enText: 'Vehicles', + ), + route: '/vehiclesOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + key: 'FRE-HUB-OPENED-VISITS', + icon: Icons.perm_contact_calendar, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Visitas Abertas', + enText: 'Opened Visits', + ), + route: '/visitsOnThePropertyPage', + types: [MenuEntryType.Property], + ), + MenuEntry( + key: 'FRE-HUB-PETS-HISTORY', + icon: Icons.pets, + name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( + ptText: 'Pets', + enText: 'Pets', + ), + route: '/petsOnThePropertyPage', + types: [MenuEntryType.Property], + ), MenuEntry( key: 'FRE-HUB-ORDERS', icon: Icons.inventory_2_outlined, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Minhas Encomendas', - enText: 'My Orders', + ptText: 'Encomendas', + enText: 'Orders', ), route: '/packageOrder', types: [MenuEntryType.Home, MenuEntryType.Drawer, MenuEntryType.Property], @@ -142,7 +182,7 @@ class MenuEntry implements BaseModule { types: [MenuEntryType.Home, MenuEntryType.Drawer], ), MenuEntry( - key: 'FRE-HUB-PROPERTY', + key: 'FRE-HUB-ABOUT-PROPERTY', icon: Icons.home, name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( ptText: 'Sobre a Propriedade', @@ -182,46 +222,6 @@ class MenuEntry implements BaseModule { route: '/WelcomePage', types: [MenuEntryType.Drawer], ), - MenuEntry( - key: 'FRE-HUB-RESIDENTS', - icon: Icons.groups, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Moradores', - enText: 'Residents', - ), - route: '/residentsOnThePropertyPage', - types: [MenuEntryType.Property], - ), - MenuEntry( - key: 'FRE-HUB-VEHICLES', - icon: Icons.directions_car, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Veículos na Propriedade', - enText: 'Vehicles on the Property', - ), - route: '/vehiclesOnThePropertyPage', - types: [MenuEntryType.Property], - ), - MenuEntry( - key: 'FRE-HUB-OPENED-VISITS', - icon: Icons.perm_contact_calendar, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Visitas Abertas', - enText: 'Opened Visits', - ), - route: '/visitsOnThePropertyPage', - types: [MenuEntryType.Property], - ), - MenuEntry( - key: 'FRE-HUB-PETS-HISTORY', - icon: Icons.pets, - name: FFLocalizations.of(navigatorKey.currentContext!).getVariableText( - ptText: 'Histórico de Pets', - enText: 'Pets History', - ), - route: '/petsOnThePropertyPage', - types: [MenuEntryType.Property], - ), ]; static List getEntriesByType(MenuEntryType type) { diff --git a/lib/shared/components/molecules/modules/constants/license_constants.dart b/lib/shared/components/molecules/modules/constants/license_constants.dart index 37ce1daf..9f12dd9a 100644 --- a/lib/shared/components/molecules/modules/constants/license_constants.dart +++ b/lib/shared/components/molecules/modules/constants/license_constants.dart @@ -27,15 +27,16 @@ String get updateDisplayTrigger => ''' CREATE TRIGGER update_display_trigger - AFTER UPDATE ON $tableLicense + AFTER INSERT ON $tableLicense WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') BEGIN UPDATE $tableLicense - SET display = CASE - WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 - THEN 'VISIVEL' - ELSE 'INVISIVEL' - END + SET display = + CASE + WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 + THEN 'VISIVEL' + ELSE 'INVISIVEL' + END WHERE key = 'FRE-HUB-ABOUT-PROPERTY'; END; '''; diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 138e114f..65291d10 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -1,4 +1,6 @@ +import 'dart:developer'; + import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; @@ -28,17 +30,17 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { } @override - Future setDisplayByKey(final List key, final String display) async { - if (key.isEmpty) return; - for (var element in key) { - if (element != null) { - await set(element, { - 'display': display, - 'expirationDate': '', - 'startDate': '', - 'quantity': '', - }); - } + Future setDisplayByKey(final List keys, final String display) async { + if (keys.isEmpty) return; + final validKeys = keys.where((key) => key.isNotEmpty).toList(); + for (var key in validKeys) { + log('Setting display: $key : $display'); + await set(key, { + 'display': display, + 'expirationDate': '', + 'startDate': '', + 'quantity': '', + }); } } @@ -55,13 +57,20 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { if (response.isEmpty) { return null; } - return response.first.toString(); + + log('Getting StartDate: ${response.toString()}'); + + return response.toString(); } @override Future set(String key, T value) async { value as Map; + if (value.isEmpty) return; + if (key == 'null') return; + + log('Setting: ${value['key']} : ${value['display']}'); await DatabaseStorage.database.insert( tableLicense, { diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index 23427808..bd0cee47 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -46,26 +46,26 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { .where((module) => module.display == ModuleStatus.inactive.key) .map((module) => module.key) .toList(); + log('Módulos inativos: $inactiveModuleKey'); final List activeModuleKey = license.modules .where((module) => module.display == ModuleStatus.active.key) .map((module) => module.key) .toList(); + log('Módulos ativos: $activeModuleKey'); final List disabledModuleKey = license.modules .where((module) => module.display == ModuleStatus.disabled.key) .map((module) => module.key) .toList(); + log('Módulos desabilitados: $disabledModuleKey'); await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL'); await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL'); - if (isNewVersion == true) { - await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'VISIVEL'); - await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-PROPERTY'], 'VISIVEL'); - } else { - await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO'); - } - + await LicenseLocalDataSourceImpl().setDisplayByKey(disabledModuleKey, 'DESABILITADO'); + + + return true; } catch (e, s) { log('Erro ao configurar licenças: $e', stackTrace: s); @@ -92,16 +92,21 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { if (responseBody == []) { // return await setupLicense(DatabaseStorage.database, isNewVersion); - return false; + return true; } + log('Valores: ${LicenseKeys.values.map((e) => e.value).toList()}'); List> saveOperations = []; for (var element in responseBody) { + log('Elemento: ${element['key']}'); if (licenseContainsKey(element['key'])) { + log('Salvando licença: ${element['key']}'); saveOperations.add(_saveModule(element)); } } await Future.wait(saveOperations); + final String? v = await LicenseRepositoryImpl().getLicense(LicenseKeys.property.value); + log('Licenças obtidas: $v'); return true; } catch (e, s) { log('Erro ao obter licenças: $e', stackTrace: s); @@ -115,11 +120,14 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } static bool licenseContainsKey(final String key) { - return LicenseKeys.values.map((e) => e.value).contains(key); + log('licenseContainsKey: $key'); + + return LicenseKeys.values.map((e) => e.value).toList().contains(key); } static Future _saveModule(final dynamic body) async { + log('Salvando módulo: ${body['key']}'); if (body is! Map) return; - await LicenseLocalDataSourceImpl().set(body['key'], body); + await LicenseRepositoryImpl().setLicense(body['key'], body); } } diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index a89b241b..66ed8bd2 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -18,9 +18,9 @@ enum LicenseKeys { pets('FRE-HUB-PETS'), orders('FRE-HUB-ORDERS'), completeSchedule('FRE-HUB-COMPLETE-SCHEDULE'), - providerSchedule('FRE-HUB-AGE-PROV-PRESTADOR'), + providerSchedule('FRE-HUB-AGE-PROV-PREST'), deliverySchedule('FRE-HUB-AGE-PROV-DELIVERY'), - property('FRE-HUB-PROPERTY'), + property('FRE-HUB-ABOUT-PROPERTY'), fastPass('FRE-HUB-FASTPASS'), visitors('FRE-HUB-VISITORS'), qrCode('FRE-HUB-QRCODE'), @@ -198,7 +198,7 @@ class License { ), Module( key: LicenseKeys.property.value, - display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index 258e81d7..bd8f1e2d 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -7,7 +7,7 @@ import 'dart:developer'; class DatabaseStorage { static final String _dbName = 'database.db'; - static final int _dbVersion = 4; + static final int _dbVersion = 2; static final DatabaseStorage instance = DatabaseStorage._internal(); factory DatabaseStorage() => instance; @@ -42,11 +42,6 @@ class DatabaseStorage { await database.execute(createLicenseTable); if (version >= 2) { await database.execute(updatePetsHistoryTrigger); - } - if (version >= 3) { - await database.execute(updateDisplayTrigger); - } - if (version >= 4) { await database.execute(updatePeopleDisplayTrigger); } } @@ -56,24 +51,18 @@ class DatabaseStorage { if (oldVersion < 2 && newVersion >= 2) { await database.execute(createLicenseTable); await database.execute(updatePetsHistoryTrigger); - } - if (oldVersion < 3 && newVersion >= 3) { - await database.execute(updateDisplayTrigger); - } - if (oldVersion < 4 && newVersion >= 4) { await database.execute(updatePeopleDisplayTrigger); } + + + } Future _onDowngrade(Database database, int oldVersion, int newVersion) async { log('Downgrading database from version $oldVersion to $newVersion...'); - if (oldVersion >= 4 && newVersion < 4) { - await database.execute(dropPeopleDisplayTrigger); - } - if (oldVersion >= 3 && newVersion < 3) { - await database.execute(dropDisplayTrigger); - } if (oldVersion >= 2 && newVersion < 2) { + await database.execute(deleteLicenseTable); + await database.execute(dropPeopleDisplayTrigger); await database.execute(dropPetsHistoryTrigger); } } diff --git a/lib/shared/helpers/storage/base_storage.dart b/lib/shared/helpers/storage/base_storage.dart index fa1d47c7..f63582ec 100644 --- a/lib/shared/helpers/storage/base_storage.dart +++ b/lib/shared/helpers/storage/base_storage.dart @@ -80,6 +80,7 @@ enum KeychainStorageKey { status, userName, clientUUID, + ownerName, ownerUUID, clientName, petAmount, @@ -115,6 +116,8 @@ extension KeychainStorageKeyExtension on KeychainStorageKey { return 'fre_ownerUUID'; case KeychainStorageKey.clientName: return 'fre_cliName'; + case KeychainStorageKey.ownerName: + return 'fre_ownerName'; case KeychainStorageKey.petAmount: return 'fre_petAmountRegister'; case KeychainStorageKey.whatsapp: From 3080eac50bff0c675ca7854d415bad1afe1a6ddf Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 10:00:41 -0300 Subject: [PATCH 55/75] WIP --- .../order_filter_modal_model.dart | 2 +- .../order_filter_modal_widget.dart | 11 ++- .../home/presentation/pages/home_page.dart | 5 +- lib/flutter_flow/nav/nav.dart | 3 - lib/main.dart | 4 ++ .../package_order_page.dart | 11 ++- .../repositories/locals_repository_impl.dart | 31 +++++++-- .../blocs/local_profile_bloc.dart | 1 - .../repositories/menu_repository_impl.dart | 22 +++--- .../menu/presentation/blocs/menu_bloc.dart | 17 ++--- .../modules/constants/license_constants.dart | 61 +++++++++++----- .../license_local_data_source.dart | 20 ++---- .../license_remote_data_source.dart | 13 +--- .../modules/domain/entities/license.dart | 2 +- lib/shared/constants/keychain_constants.dart | 2 +- .../helpers/database/database_helper.dart | 69 +++++++++++++------ .../helpers/storage/keychain_storage.dart | 3 + .../helpers/storage/storage_helper.dart | 3 + .../authentication_service.dart | 6 +- 19 files changed, 175 insertions(+), 111 deletions(-) diff --git a/lib/components/molecular_components/order_filter_modal/order_filter_modal_model.dart b/lib/components/molecular_components/order_filter_modal/order_filter_modal_model.dart index 79eefd3c..ec888c47 100644 --- a/lib/components/molecular_components/order_filter_modal/order_filter_modal_model.dart +++ b/lib/components/molecular_components/order_filter_modal/order_filter_modal_model.dart @@ -25,4 +25,4 @@ class OrderFilterModalModel extends FlutterFlowModel { textFieldFocusNode?.dispose(); textController?.dispose(); } -} +} \ No newline at end of file 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 4c74c366..1835eb3c 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,7 +4,6 @@ import 'package:hub/components/molecular_components/order_filter_modal/order_fil import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; // ignore: unused_import import 'package:hub/shared/utils/limited_text_size.dart'; @@ -29,22 +28,22 @@ class _OrderFilterModalWidgetState extends State { late Map selected; final List> adresseeTypeOptions = [ { - 'title': FFLocalizations.of(StorageHelper().context!).getVariableText(enText: 'Resident', ptText: 'Morador'), + 'title': FFLocalizations.of(navigatorKey.currentContext!).getVariableText(enText: 'Resident', ptText: 'Morador'), 'value': 'MOR' }, { - 'title': FFLocalizations.of(StorageHelper().context!).getVariableText(enText: 'Property', ptText: 'Propriedade'), + 'title': FFLocalizations.of(navigatorKey.currentContext!).getVariableText(enText: 'Property', ptText: 'Propriedade'), 'value': 'PRO' }, ]; final List> statusOptions = [ { - 'title': FFLocalizations.of(StorageHelper().context!) + 'title': FFLocalizations.of(navigatorKey.currentContext!) .getVariableText(ptText: 'Aguardando Retirada', enText: 'Waiting for Pickup'), 'value': 'notPickedUp' }, { - 'title': FFLocalizations.of(StorageHelper().context!).getVariableText(ptText: 'Retirado', enText: 'Picked Up'), + 'title': FFLocalizations.of(navigatorKey.currentContext!).getVariableText(ptText: 'Retirado', enText: 'Picked Up'), 'value': 'pickedUp' }, ]; @@ -232,4 +231,4 @@ class _OrderFilterModalWidgetState extends State { ), ); } -} +} \ No newline at end of file diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 2d64565d..dd567508 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -42,8 +42,11 @@ class _HomePageWidgetState extends State { Widget build(BuildContext context) { return Builder( builder: (context) { + // LocalsRepositoryImpl.license.add(false); + // context.read().add(LocalProfileEvent()); + // context.read().add(MenuEvent()); LocalsRepositoryImpl.license.add(true); - // context.read().updateProfile(context); + return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 30aacafd..a62e5d2a 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -123,10 +123,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { ); }), FFRoute(name: 'homePage', path: '/homePage', builder: (context, params) { - log('params: $params'); final Future Function(BuildContext context)? update = params.getParam('update', ParamType.Function); - log('update: $update'); - return HomePageWidget(key: UniqueKey(), update: update); }), diff --git a/lib/main.dart b/lib/main.dart index f100c8c7..220796a2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -192,11 +192,15 @@ class _AppState extends State with WidgetsBindingObserver { @override void didChangeAppLifecycleState(AppLifecycleState state) async { if (state == AppLifecycleState.detached) { + final isLogged = await StorageHelper().get(SecureStorageKey.isLogged.value); + log('isLogged: $isLogged'); + if (isLogged.toBoolean()) { LocalsRepositoryImpl.license.add(false); final response = await LocalsRepositoryImpl().update(context); LocalsRepositoryImpl.license.add(response); await FirebaseMessagingService().updateDeviceToken(); } + } } @override diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index 0df4e591..b63c5186 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -36,11 +36,11 @@ class _PackageOrderPage extends State { List _orderList = []; final Map filter = { - 'adresseeType': 'PRO', + 'adresseeType': '.*', 'status': 'notPickedUp', }; - String _adresseeType = 'PRO'; + String _adresseeType = '.*'; String _status = 'notPickedUp'; late BehaviorSubject> _selectedTypeSubject; @@ -64,7 +64,7 @@ class _PackageOrderPage extends State { } Future initDatabase() async { - cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value) ?? ''); } @override @@ -224,7 +224,7 @@ class _PackageOrderPage extends State { return AppBar( backgroundColor: FlutterFlowTheme.of(context).primaryBackground, automaticallyImplyLeading: false, - title: Text(FFLocalizations.of(context).getVariableText(enText: 'Orders', ptText: 'Encomendas'), + title: Text(FFLocalizations.of(context).getVariableText(enText: 'My Orders', ptText: 'Minhas Encomendas'), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).primaryText, @@ -412,9 +412,8 @@ class _PackageOrderPage extends State { @override Widget build(BuildContext context) { return Scaffold( - backgroundColor: FlutterFlowTheme.of(context).primaryBackground, appBar: _appBar(context), body: _appBody(context), ); } -} +} \ No newline at end of file diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 1c8580ad..dd426587 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -3,6 +3,7 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; +import 'package:hub/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; @@ -23,18 +24,34 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { bool response = false; - while (!response) { - response = await remoteDataSource.processLocals(context); - if (!response) { - await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); - const String errorMsg = 'Erro ao atualizar locais'; - await DialogUtil.error(context, errorMsg); + try { + while (!response) { + response = await remoteDataSource.processLocals(context); + if (!response) { + await _handleUpdateError(context); + } } + await _notifyBlocs(context); + } catch (e) { + log('Error updating locals: $e'); + await _handleUpdateError(context); } - context.read().add(LocalProfileEvent()); return response; } + Future _handleUpdateError(BuildContext context) async { + await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); + const String errorMsg = 'Erro ao atualizar locais'; + await DialogUtil.error(context, errorMsg); + } + + Future _notifyBlocs(BuildContext context) async { + LocalsRepositoryImpl.license.add(false); + context.read().add(LocalProfileEvent()); + context.read().add(MenuEvent()); + LocalsRepositoryImpl.license.add(true); + } + @override Future unlinkLocal(BuildContext context) { return remoteDataSource.detachLocal(context); diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index 95faea30..e05375c5 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -36,7 +36,6 @@ class LocalProfileBloc extends Bloc { } Future _onLocalProfileEvent(LocalProfileEvent event, Emitter emit) async { - log('LocalProfileBloc: _onLocalProfileEvent'); final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; final ownerName = (await StorageHelper().get(KeychainStorageKey.ownerName.value)) ?? ''; final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 3f2c2f6f..02cb24e5 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -22,17 +22,16 @@ class MenuRepositoryImpl implements MenuRepository { Future> generateMenuEntries(List menuEntries, EnumMenuItem item) async { log('Generating menu entries for $item'); List entries = []; - final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean()); + // final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean()); try { for (var entry in menuEntries) { - log('Processing entry: ${entry.key}'); final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); if (isDefault) continue; final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); if (licenseValue != null) { final licenseMap = await stringToMap(licenseValue); - final display = await processDisplay(licenseMap, isNewVersion); + final display = EnumDisplay.fromString(licenseMap['display']); final startDate = licenseMap['startDate'] ?? ''; final expirationDate = licenseMap['expirationDate'] ?? ''; final isStarted = await menuDataSource.processStartDate(startDate, entry); @@ -57,13 +56,9 @@ class MenuRepositoryImpl implements MenuRepository { } Future processDisplay(Map module, bool isNewVersion) async { - const keysToCheck = [ - LicenseKeys.residents, - LicenseKeys.vehicles, - LicenseKeys.openedVisits - ]; - if (isNewVersion && keysToCheck.any((key) => module['key'] == key.value)) { + + if (await _shouldUpdateDisplay(module, isNewVersion)) { final displayValue = module['display'] == EnumDisplay.active ? 'VISIVEL' : 'INVISIVEL'; await LicenseLocalDataSourceImpl().setDisplayByKey(['FRE-HUB-ABOUT-PROPERTY'], displayValue); return EnumDisplay.fromString(displayValue); @@ -72,5 +67,14 @@ class MenuRepositoryImpl implements MenuRepository { return EnumDisplay.fromString(module['display']); } + Future _shouldUpdateDisplay(Map module, bool isNewVersion) async { + const keysToCheck = [ + LicenseKeys.residents, + LicenseKeys.vehicles, + LicenseKeys.openedVisits + ]; + return isNewVersion && keysToCheck.any((key) => module['key'] == key.value); + } + } \ No newline at end of file diff --git a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart index 8c249bf9..ed513784 100644 --- a/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart +++ b/lib/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart @@ -33,24 +33,21 @@ class MenuBloc extends Bloc { final MenuView style; final EnumMenuItem item; final List entries; - late StreamSubscription _completer; - + late StreamSubscription _completer; MenuBloc({required this.style, required this.item, required this.entries}) : super(MenuState()) { on(_onMenuEvent); - - _completer = LicenseRemoteDataSourceImpl().streamCompleterController.listen((_) { + _completer = LocalsRepositoryImpl.license.stream.listen((v) { add(MenuEvent()); }); - } + } - Future _onMenuEvent(MenuEvent event, Emitter emit) async { - + Future _onMenuEvent(MenuEvent event, Emitter emit) async { await LicenseRemoteDataSourceImpl().waitForSaveCompletion(); - final List NewEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item); - emit(state.copyWith(menuEntries: NewEntries)); - } + final List newEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item); + emit(state.copyWith(menuEntries: newEntries)); + } @override Future close() { diff --git a/lib/shared/components/molecules/modules/constants/license_constants.dart b/lib/shared/components/molecules/modules/constants/license_constants.dart index 9f12dd9a..6a4a2fcc 100644 --- a/lib/shared/components/molecules/modules/constants/license_constants.dart +++ b/lib/shared/components/molecules/modules/constants/license_constants.dart @@ -1,7 +1,8 @@ const String tableLicense = 'license'; - String get createLicenseTable => ''' + class LicenseConstants { + static String get createLicenseTable => ''' CREATE TABLE IF NOT EXISTS $tableLicense ( key TEXT UNIQUE, display TEXT, @@ -11,9 +12,9 @@ ); '''; - String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;'; + static String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;'; - String get updatePetsHistoryTrigger => ''' + static String get updatePetsHistoryTrigger => ''' CREATE TRIGGER update_fre_hub_pets_history AFTER INSERT ON $tableLicense WHEN NEW.key = 'FRE-HUB-PETS' @@ -23,15 +24,35 @@ END; '''; - String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;'; + static String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;'; - String get updateDisplayTrigger => ''' + static String get updateDisplayTrigger => ''' CREATE TRIGGER update_display_trigger + AFTER UPDATE ON $tableLicense + WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') + BEGIN + INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) + VALUES ( + 'FRE-HUB-ABOUT-PROPERTY', + CASE + WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 + THEN 'VISIVEL' + ELSE 'INVISIVEL' + END, + NULL, NULL, NULL + ); + END; + '''; + + static String get dropUpdateDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;'; + + static String get insertDisplayTrigger => ''' + CREATE TRIGGER insert_display_trigger AFTER INSERT ON $tableLicense WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') BEGIN UPDATE $tableLicense - SET display = + SET display = CASE WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 THEN 'VISIVEL' @@ -41,17 +62,23 @@ END; '''; - String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;'; + static String get dropInsertDisplayTrigger => 'DROP TRIGGER IF EXISTS insert_display_trigger;'; - String get updatePeopleDisplayTrigger => ''' - CREATE TRIGGER update_people_display_trigger - AFTER UPDATE ON $tableLicense - WHEN NEW.key = 'FRE-HUB-ABOUT-PROPERTY' AND NEW.display = 'VISIVEL' - BEGIN - UPDATE $tableLicense - SET display = 'INVISIVEL' - WHERE key = 'FRE-HUB-PEOPLE'; - END; + static String get updatePeopleDisplayTrigger => ''' + CREATE TRIGGER update_people_display_trigger + AFTER UPDATE ON $tableLicense + WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') + BEGIN + UPDATE $tableLicense + SET display = + CASE + WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS') AND display = 'VISIVEL') > 0 + THEN 'VISIVEL' + ELSE 'INVISIVEL' + END + WHERE key = 'FRE-HUB-ABOUT-PROPERTY'; + END; '''; - String get dropPeopleDisplayTrigger => 'DROP TRIGGER IF EXISTS update_people_display_trigger;'; \ No newline at end of file + static String get dropPeopleDisplayTrigger => 'DROP TRIGGER IF EXISTS update_people_display_trigger;'; + } \ No newline at end of file diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 65291d10..42e5bac7 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -34,7 +34,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { if (keys.isEmpty) return; final validKeys = keys.where((key) => key.isNotEmpty).toList(); for (var key in validKeys) { - log('Setting display: $key : $display'); await set(key, { 'display': display, 'expirationDate': '', @@ -58,7 +57,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { return null; } - log('Getting StartDate: ${response.toString()}'); return response.toString(); } @@ -68,19 +66,11 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { value as Map; if (value.isEmpty) return; if (key == 'null') return; - - log('Setting: ${value['key']} : ${value['display']}'); - await DatabaseStorage.database.insert( - tableLicense, - { - 'key': key, - 'display': value['display'], - 'expirationDate': value['expirationDate'], - 'startDate': value['startDate'], - 'quantity': value['quantity'], - }, - conflictAlgorithm: ConflictAlgorithm.replace); + await DatabaseStorage.database.rawInsert( + 'INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity) VALUES (?, ?, ?, ?, ?)', + [key, value['display'], value['expirationDate'], value['startDate'], value['quantity']], + ); return; } @@ -92,5 +82,7 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { @override Future clear() async { await DatabaseStorage.database.delete(tableLicense); + await DatabaseStorage.database.rawDelete( + 'DELETE FROM sqlite_sequence WHERE name = "$tableLicense"'); } } diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart index bd0cee47..5513c507 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_remote_data_source.dart @@ -23,8 +23,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { LicenseRemoteDataSourceImpl._internal(); - final StreamController completerController = StreamController.broadcast(); - Stream get streamCompleterController => completerController.stream; + @override @@ -46,19 +45,16 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { .where((module) => module.display == ModuleStatus.inactive.key) .map((module) => module.key) .toList(); - log('Módulos inativos: $inactiveModuleKey'); final List activeModuleKey = license.modules .where((module) => module.display == ModuleStatus.active.key) .map((module) => module.key) .toList(); - log('Módulos ativos: $activeModuleKey'); final List disabledModuleKey = license.modules .where((module) => module.display == ModuleStatus.disabled.key) .map((module) => module.key) .toList(); - log('Módulos desabilitados: $disabledModuleKey'); await LicenseLocalDataSourceImpl().setDisplayByKey(inactiveModuleKey, 'INVISIVEL'); await LicenseLocalDataSourceImpl().setDisplayByKey(activeModuleKey, 'VISIVEL'); @@ -95,18 +91,13 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { return true; } - log('Valores: ${LicenseKeys.values.map((e) => e.value).toList()}'); List> saveOperations = []; for (var element in responseBody) { - log('Elemento: ${element['key']}'); if (licenseContainsKey(element['key'])) { - log('Salvando licença: ${element['key']}'); saveOperations.add(_saveModule(element)); } } await Future.wait(saveOperations); - final String? v = await LicenseRepositoryImpl().getLicense(LicenseKeys.property.value); - log('Licenças obtidas: $v'); return true; } catch (e, s) { log('Erro ao obter licenças: $e', stackTrace: s); @@ -120,13 +111,11 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { } static bool licenseContainsKey(final String key) { - log('licenseContainsKey: $key'); return LicenseKeys.values.map((e) => e.value).toList().contains(key); } static Future _saveModule(final dynamic body) async { - log('Salvando módulo: ${body['key']}'); if (body is! Map) return; await LicenseRepositoryImpl().setLicense(body['key'], body); } diff --git a/lib/shared/components/molecules/modules/domain/entities/license.dart b/lib/shared/components/molecules/modules/domain/entities/license.dart index 66ed8bd2..d643e322 100644 --- a/lib/shared/components/molecules/modules/domain/entities/license.dart +++ b/lib/shared/components/molecules/modules/domain/entities/license.dart @@ -198,7 +198,7 @@ class License { ), Module( key: LicenseKeys.property.value, - display: isNewVersionWithModule ? ModuleStatus.inactive.key : ModuleStatus.inactive.key, + display: isNewVersionWithModule ? ModuleStatus.active.key : ModuleStatus.inactive.key, expirationDate: '', startDate: '', quantity: 0, diff --git a/lib/shared/constants/keychain_constants.dart b/lib/shared/constants/keychain_constants.dart index 4a44fcfb..0aac6594 100644 --- a/lib/shared/constants/keychain_constants.dart +++ b/lib/shared/constants/keychain_constants.dart @@ -1,7 +1,7 @@ const String tableKeychain = 'keychain'; String get createKeychainTable => ''' - CREATE TABLE $tableKeychain ( + CREATE TABLE IF NOT EXISTS $tableKeychain ( key TEXT UNIQUE, value TEXT, type TEXT, diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index bd8f1e2d..dec8a983 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -6,8 +6,8 @@ import 'package:path/path.dart'; import 'dart:developer'; class DatabaseStorage { - static final String _dbName = 'database.db'; - static final int _dbVersion = 2; + static const String _dbName = 'database.db'; + static const int _dbVersion = 2; static final DatabaseStorage instance = DatabaseStorage._internal(); factory DatabaseStorage() => instance; @@ -21,49 +21,76 @@ class DatabaseStorage { return _database!; } - bool isInitialized = false; + static bool isInitialized = false; Future init() async { if (isInitialized) return; + _database = await openDatabase( join(await getDatabasesPath(), _dbName), version: _dbVersion, onCreate: _onCreate, onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, + onOpen: _onOpen, + onConfigure: _onConfigure, + singleInstance: true, ); await LicenseRepositoryImpl().updateLicense(); isInitialized = true; } + Future _onConfigure(Database database) async { + print('Configuring database...'); + } + + Future _onOpen(Database database) async { + print('Opening database...'); + await _executePragmas(database); + } + Future _onCreate(Database database, int version) async { - log('Creating database...'); - await database.execute(createKeychainTable); - await database.execute(createLicenseTable); - if (version >= 2) { - await database.execute(updatePetsHistoryTrigger); - await database.execute(updatePeopleDisplayTrigger); - } + print('Creating database...'); + await _createTables(database, version); } Future _onUpgrade(Database database, int oldVersion, int newVersion) async { - log('Upgrading database from version $oldVersion to $newVersion...'); + print('Upgrading database from version $oldVersion to $newVersion...'); if (oldVersion < 2 && newVersion >= 2) { - await database.execute(createLicenseTable); - await database.execute(updatePetsHistoryTrigger); - await database.execute(updatePeopleDisplayTrigger); + await _createTables(database, newVersion); } - - - } Future _onDowngrade(Database database, int oldVersion, int newVersion) async { - log('Downgrading database from version $oldVersion to $newVersion...'); + print('Downgrading database from version $oldVersion to $newVersion...'); if (oldVersion >= 2 && newVersion < 2) { - await database.execute(deleteLicenseTable); - await database.execute(dropPeopleDisplayTrigger); - await database.execute(dropPetsHistoryTrigger); + await _dropTables(database); } } + + Future _executePragmas(Database database) async { + // await database.execute('PRAGMA journal_mode = WAL;'); + await database.execute('PRAGMA synchronous = NORMAL;'); + await database.execute('PRAGMA temp_store = MEMORY;'); + await database.execute('PRAGMA foreign_keys = ON;'); + } + + Future _createTables(Database database, int version) async { + await database.execute(createKeychainTable); + await database.execute(LicenseConstants.createLicenseTable); + if (version >= 2) { + await database.execute(LicenseConstants.updatePetsHistoryTrigger); + await database.execute(LicenseConstants.updateDisplayTrigger); + await database.execute(LicenseConstants.insertDisplayTrigger); + await database.execute(LicenseConstants.updatePeopleDisplayTrigger); + } + } + + Future _dropTables(Database database) async { + await database.execute(LicenseConstants.deleteLicenseTable); + await database.execute(LicenseConstants.dropPeopleDisplayTrigger); + await database.execute(LicenseConstants.dropInsertDisplayTrigger); + await database.execute(LicenseConstants.dropUpdateDisplayTrigger); + await database.execute(LicenseConstants.dropPetsHistoryTrigger); + } } diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index d662dc1a..4328c11f 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -59,6 +59,9 @@ class KeychainHelper implements BaseStorage { Future clearAll() async { try { await DatabaseStorage.database.delete(tableKeychain); + await DatabaseStorage.database.rawDelete( + 'DELETE FROM sqlite_sequence WHERE name = "$tableKeychain"'); + } catch (e, s) { log('() => clearAll keychain: $e', stackTrace: s); } diff --git a/lib/shared/helpers/storage/storage_helper.dart b/lib/shared/helpers/storage/storage_helper.dart index e59c39ea..c157698f 100644 --- a/lib/shared/helpers/storage/storage_helper.dart +++ b/lib/shared/helpers/storage/storage_helper.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/cupertino.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/keychain_storage.dart'; @@ -25,6 +27,7 @@ class StorageHelper { String? isFirstRun = await SharedPreferencesStorage.instance.get(SharedPreferencesKey.isFirstRun.value); if (isFirstRun != 'false') { + log('First run'); await SharedPreferencesStorage.instance.set(SharedPreferencesKey.isFirstRun.value, false); await SecureStorage.instance.set(SecureStorageKey.isLogged.value, false); } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index ce753550..2977d9a8 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -3,6 +3,8 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:hub/features/home/presentation/pages/home_page.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/components/molecules/modules/data/repositories/license_repository_impl.dart'; +import 'package:hub/shared/helpers/database/database_helper.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; @@ -147,7 +149,9 @@ class AuthenticationService { await StorageHelper().clean(Storage.databaseStorage); await StorageHelper().clean(Storage.secureStorage); - await StorageHelper().clean(Storage.databaseStorage); + await LicenseRepositoryImpl().cleanLicense(); + DatabaseStorage.isInitialized = false; + await StorageHelper().init(); context.go('/welcomePage', extra: extra); } From 9797d8d811b84f1dbdc304e8c117059cc72f02db Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 10:01:10 -0300 Subject: [PATCH 56/75] WIP --- .../molecules/menu/data/repositories/menu_repository_impl.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart index 02cb24e5..2a05bb85 100644 --- a/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart +++ b/lib/shared/components/molecules/menu/data/repositories/menu_repository_impl.dart @@ -20,7 +20,6 @@ class MenuRepositoryImpl implements MenuRepository { @override Future> generateMenuEntries(List menuEntries, EnumMenuItem item) async { - log('Generating menu entries for $item'); List entries = []; // final bool isNewVersion = await StorageHelper().get(KeychainStorageKey.isNewVersion.value).then((v) => v.toBoolean()); From b28ca12482f647f7b06335e0453f61226b9e5680 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 11:16:32 -0300 Subject: [PATCH 57/75] WIP --- devtools_options.yaml | 1 + .../home/presentation/pages/home_page.dart | 42 ++++++++++++++++++- lib/main.dart | 18 +------- .../locals_local_data_source.dart | 19 ++++++++- .../repositories/locals_repository_impl.dart | 32 +++++++++----- .../blocs/local_profile_bloc.dart | 6 +++ .../local_profile/local_profile_widget.dart | 9 +--- .../license_remote_data_source.dart | 11 ++--- 8 files changed, 97 insertions(+), 41 deletions(-) diff --git a/devtools_options.yaml b/devtools_options.yaml index fa0b357c..2bc8e05f 100644 --- a/devtools_options.yaml +++ b/devtools_options.yaml @@ -1,3 +1,4 @@ description: This file stores settings for Dart & Flutter DevTools. documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states extensions: + - provider: true \ No newline at end of file diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index dd567508..a31df8ef 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -4,6 +4,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/notifications/firebase_messaging_service.dart'; import 'package:hub/features/home/index.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; @@ -12,6 +13,9 @@ import 'package:hub/shared/components/molecules/drawer/index.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/extensions/string_extensions.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; class HomePageWidget extends StatefulWidget { const HomePageWidget({ @@ -24,12 +28,13 @@ class HomePageWidget extends StatefulWidget { State createState() => _HomePageWidgetState(); } -class _HomePageWidgetState extends State { +class _HomePageWidgetState extends State with WidgetsBindingObserver { final scaffoldKey = GlobalKey(); @override void initState() { super.initState(); + WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addPostFrameCallback((_) async { if (widget.update != null) { await widget.update!(context); @@ -37,6 +42,41 @@ class _HomePageWidgetState extends State { }); } + @override + void dispose() { + WidgetsBinding.instance.removeObserver(this); + super.dispose(); + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) async { + Future execute() async { + final isLogged = await StorageHelper().get(SecureStorageKey.isLogged.value); + log('isLogged: $isLogged'); + if (isLogged.toBoolean()) { + WidgetsBinding.instance.addPostFrameCallback((_) async { + await LocalsRepositoryImpl().update(context); + await FirebaseMessagingService().updateDeviceToken(); + }); + } + } + if (state == AppLifecycleState.detached) { + print('AppLifecycleState.detached'); + } + if (state == AppLifecycleState.resumed) { + print('AppLifecycleState.resumed'); + } + if (state == AppLifecycleState.inactive) { + print('AppLifecycleState.inactive'); + } + if (state == AppLifecycleState.paused) { + print('AppLifecycleState.paused'); + } + if (state == AppLifecycleState.hidden) { + print('AppLifecycleState.hidden'); + } + } + @override Widget build(BuildContext context) { diff --git a/lib/main.dart b/lib/main.dart index 220796a2..8ba07637 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -60,7 +60,7 @@ class App extends StatefulWidget { static _AppState of(BuildContext context) => context.findAncestorStateOfType<_AppState>()!; } -class _AppState extends State with WidgetsBindingObserver { +class _AppState extends State { Locale? _locale = FFLocalizations.getStoredLocale(); ThemeMode _themeMode = FlutterFlowTheme.themeMode; late AppStateNotifier _appStateNotifier; @@ -169,7 +169,7 @@ class _AppState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); - WidgetsBinding.instance.addObserver(this); + FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); _appStateNotifier = AppStateNotifier.instance; @@ -185,23 +185,9 @@ class _AppState extends State with WidgetsBindingObserver { @override void dispose() { - WidgetsBinding.instance.removeObserver(this); super.dispose(); } - @override - void didChangeAppLifecycleState(AppLifecycleState state) async { - if (state == AppLifecycleState.detached) { - final isLogged = await StorageHelper().get(SecureStorageKey.isLogged.value); - log('isLogged: $isLogged'); - if (isLogged.toBoolean()) { - LocalsRepositoryImpl.license.add(false); - final response = await LocalsRepositoryImpl().update(context); - LocalsRepositoryImpl.license.add(response); - await FirebaseMessagingService().updateDeviceToken(); - } - } - } @override Widget build(BuildContext context) { diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart index 47f65ad7..e8718025 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart @@ -1,3 +1,18 @@ -abstract class LocalsLocalDataSource {} +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; -class LocalsLocalDataSourceImpl {} +abstract class LocalsLocalDataSource { + Future unlinkLocal(); +} + +class LocalsLocalDataSourceImpl { + + Future unlinkLocal() async { + await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerUUID.value, ''); + await StorageHelper().set(KeychainStorageKey.clientName.value, ''); + await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); + } + +} diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index dd426587..97c254c3 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -12,6 +12,7 @@ import 'package:rxdart/rxdart.dart'; class LocalsRepositoryImpl implements LocalsRepository { final LocalsRemoteDataSource remoteDataSource = LocalsRemoteDataSourceImpl(); + final LocalsLocalDataSourceImpl localDataSource = LocalsLocalDataSourceImpl(); static final license = BehaviorSubject(); static get stream => license.stream; @@ -23,19 +24,30 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { + LocalsRepositoryImpl.license.add(false); + final bool response = await _handleReponse(context); + LocalsRepositoryImpl.license.add(response); + return response; + } + + Future select(BuildContext context) async { + await localDataSource.unlinkLocal(); + await update(context); + } + + Future _handleReponse(BuildContext context) async { bool response = false; - try { - while (!response) { + while (!response) { + try { response = await remoteDataSource.processLocals(context); if (!response) { await _handleUpdateError(context); } - } - await _notifyBlocs(context); - } catch (e) { - log('Error updating locals: $e'); - await _handleUpdateError(context); - } + } catch (e , s) { + log('Error updating locals: $e', stackTrace: s); + await _handleUpdateError(context); + } + } return response; } @@ -46,10 +58,10 @@ class LocalsRepositoryImpl implements LocalsRepository { } Future _notifyBlocs(BuildContext context) async { - LocalsRepositoryImpl.license.add(false); + context.read().add(LocalProfileEvent()); context.read().add(MenuEvent()); - LocalsRepositoryImpl.license.add(true); + } @override diff --git a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart index e05375c5..d19459a1 100644 --- a/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart +++ b/lib/shared/components/molecules/locals/presentation/blocs/local_profile_bloc.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:developer'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -31,8 +32,13 @@ class LocalProfileState { } class LocalProfileBloc extends Bloc { + late StreamSubscription _completer; + LocalProfileBloc() : super(LocalProfileState()) { on(_onLocalProfileEvent); + _completer = LocalsRepositoryImpl.license.stream.listen((v) { + add(LocalProfileEvent()); + }); } Future _onLocalProfileEvent(LocalProfileEvent event, Emitter emit) async { diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 297a7d0d..83760caa 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -26,13 +26,8 @@ class _LocalProfileComponentWidgetState extends State) { + + if (responseBody == []) { + return true; + } + else if (response.jsonBody is! List) { late final String error; if (response.jsonBody is Map) error = response.jsonBody['error_msg']; @@ -86,10 +90,7 @@ class LicenseRemoteDataSourceImpl implements LicenseRemoteDataSource { throw Exception('Erro ao consultar licenças: $error'); } - if (responseBody == []) { - // return await setupLicense(DatabaseStorage.database, isNewVersion); - return true; - } + List> saveOperations = []; for (var element in responseBody) { From 6e1d04d9789e856f3657d6853d7b2149e193d2de Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 11:40:53 -0300 Subject: [PATCH 58/75] =?UTF-8?q?fix:=20fechar=20e=20reabrir=20o=20app=20d?= =?UTF-8?q?urante=20a=20sele=C3=A7=C3=A3o=20de=20locais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/presentation/pages/home_page.dart | 42 ++----------------- .../repositories/locals_repository_impl.dart | 12 ++++++ pubspec.lock | 32 +++++++------- pubspec.yaml | 4 +- 4 files changed, 34 insertions(+), 56 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index a31df8ef..066d994f 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -1,21 +1,15 @@ -import 'dart:developer'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/notifications/firebase_messaging_service.dart'; -import 'package:hub/features/home/index.dart'; + import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/shared/components/molecules/drawer/index.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/menu/index.dart'; -import 'package:hub/shared/components/molecules/modules/index.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/extensions/string_extensions.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; + class HomePageWidget extends StatefulWidget { const HomePageWidget({ @@ -36,6 +30,7 @@ class _HomePageWidgetState extends State with WidgetsBindingObse super.initState(); WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addPostFrameCallback((_) async { + await LocalsRepositoryImpl().check(context); if (widget.update != null) { await widget.update!(context); } @@ -48,36 +43,7 @@ class _HomePageWidgetState extends State with WidgetsBindingObse super.dispose(); } - @override - void didChangeAppLifecycleState(AppLifecycleState state) async { - Future execute() async { - final isLogged = await StorageHelper().get(SecureStorageKey.isLogged.value); - log('isLogged: $isLogged'); - if (isLogged.toBoolean()) { - WidgetsBinding.instance.addPostFrameCallback((_) async { - await LocalsRepositoryImpl().update(context); - await FirebaseMessagingService().updateDeviceToken(); - }); - } - } - if (state == AppLifecycleState.detached) { - print('AppLifecycleState.detached'); - } - if (state == AppLifecycleState.resumed) { - print('AppLifecycleState.resumed'); - } - if (state == AppLifecycleState.inactive) { - print('AppLifecycleState.inactive'); - } - if (state == AppLifecycleState.paused) { - print('AppLifecycleState.paused'); - } - if (state == AppLifecycleState.hidden) { - print('AppLifecycleState.hidden'); - } - } - - + @override Widget build(BuildContext context) { return Builder( diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 97c254c3..9c0a71eb 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -2,6 +2,7 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/notifications/firebase_messaging_service.dart'; import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/menu/presentation/blocs/menu_bloc.dart'; import 'package:hub/shared/components/molecules/modules/index.dart'; @@ -34,6 +35,17 @@ class LocalsRepositoryImpl implements LocalsRepository { await localDataSource.unlinkLocal(); await update(context); } + + Future check(BuildContext context) async { + final String? cliUUID = await StorageHelper().get(KeychainStorageKey.clientUUID.value); + final String? ownerUUID = await StorageHelper().get(KeychainStorageKey.ownerUUID.value); + final bool haveCli = cliUUID != null && cliUUID.isNotEmpty; + final bool haveOwner = ownerUUID != null && ownerUUID.isNotEmpty; + if (!haveCli && !haveOwner) { + await update(context); + await FirebaseMessagingService().updateDeviceToken(); + } + } Future _handleReponse(BuildContext context) async { bool response = false; diff --git a/pubspec.lock b/pubspec.lock index b40d3b0b..3dc25f42 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -466,10 +466,10 @@ packages: dependency: transitive description: name: firebase_core_platform_interface - sha256: e30da58198a6d4b49d5bce4e852f985c32cb10db329ebef9473db2b9f09ce810 + sha256: b94b217e3ad745e784960603d33d99471621ecca151c99c670869b76e50ad2a6 url: "https://pub.dev" source: hosted - version: "5.3.0" + version: "5.3.1" firebase_core_web: dependency: transitive description: @@ -535,10 +535,10 @@ packages: dependency: "direct main" description: name: flutter_animate - sha256: "7c8a6594a9252dad30cc2ef16e33270b6248c4dedc3b3d06c86c4f3f4dc05ae5" + sha256: "7befe2d3252728afb77aecaaea1dec88a89d35b9b1d2eea6d04479e8af9117b5" url: "https://pub.dev" source: hosted - version: "4.5.0" + version: "4.5.2" flutter_bloc: dependency: "direct main" description: @@ -615,10 +615,10 @@ packages: dependency: "direct dev" description: name: flutter_launcher_icons - sha256: "619817c4b65b322b5104b6bb6dfe6cda62d9729bd7ad4303ecc8b4e690a67a77" + sha256: "31cd0885738e87c72d6f055564d37fabcdacee743b396b78c7636c169cac64f5" url: "https://pub.dev" source: hosted - version: "0.14.1" + version: "0.14.2" flutter_lints: dependency: "direct dev" description: @@ -798,10 +798,10 @@ packages: dependency: "direct main" description: name: go_router - sha256: "8660b74171fafae4aa8202100fa2e55349e078281dadc73a241eb8e758534d9d" + sha256: "2fd11229f59e23e967b0775df8d5948a519cd7e1e8b6e849729e010587b46539" url: "https://pub.dev" source: hosted - version: "14.6.1" + version: "14.6.2" google_fonts: dependency: "direct main" description: @@ -1206,10 +1206,10 @@ packages: dependency: "direct main" description: name: path_provider_foundation - sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16 + sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.1" path_provider_linux: dependency: transitive description: @@ -1430,10 +1430,10 @@ packages: dependency: "direct main" description: name: shared_preferences_android - sha256: "3b9febd815c9ca29c9e3520d50ec32f49157711e143b7a4ca039eb87e8ade5ab" + sha256: "7f172d1b06de5da47b6264c2692ee2ead20bbbc246690427cdb4fc301cd0c549" url: "https://pub.dev" source: hosted - version: "2.3.3" + version: "2.3.4" shared_preferences_foundation: dependency: "direct main" description: @@ -1675,10 +1675,10 @@ packages: dependency: "direct main" description: name: url_launcher_ios - sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e + sha256: "16a513b6c12bb419304e72ea0ae2ab4fed569920d1c7cb850263fe3acc824626" url: "https://pub.dev" source: hosted - version: "6.3.1" + version: "6.3.2" url_launcher_linux: dependency: transitive description: @@ -1691,10 +1691,10 @@ packages: dependency: transitive description: name: url_launcher_macos - sha256: "769549c999acdb42b8bcfa7c43d72bf79a382ca7441ab18a808e101149daf672" + sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2" url: "https://pub.dev" source: hosted - version: "3.2.1" + version: "3.2.2" url_launcher_platform_interface: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 229bf883..9d2540c4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,7 @@ dependencies: file_picker: ^8.0.7 # flutter_expandable_fab: ^2.1.0 firebase_analytics: ^11.3.0 - flutter_animate: 4.5.0 + flutter_animate: ^4.5.2 # flutter_cache_manager: ^3.4.1 # flutter_plugin_android_lifecycle: ^2.0.23 share_plus: ^10.0.0 @@ -66,7 +66,7 @@ dependencies: path_provider: ^2.1.4 path_provider_android: ^2.2.12 google_mlkit_face_detection: ^0.12.0 - path_provider_foundation: 2.4.0 + path_provider_foundation: ^2.4.1 path_provider_platform_interface: 2.1.2 percent_indicator: ^4.2.3 plugin_platform_interface: 2.1.8 From b84b05d2e521b0019086dd6878a3f1390ef17399 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 13:11:54 -0300 Subject: [PATCH 59/75] WIP --- .../_template_/data/data_sources/index.dart | 0 lib/features/_template_/data/index.dart | 3 + .../_template_/data/models/index.dart | 0 .../_template_/data/repositories/index.dart | 0 .../_template_/domain/entities/index.dart | 0 lib/features/_template_/domain/index.dart | 3 + .../domain/respositories/index.dart | 0 .../_template_/domain/usecases/index.dart | 0 lib/features/_template_/index.dart | 3 + .../_template_/presentation/blocs/index.dart | 0 .../_template_/presentation/index.dart | 3 + .../_template_/presentation/pages/index.dart | 0 .../presentation/widgets/index.dart | 0 .../history/data/data_sources/index.dart | 0 lib/features/history/data/index.dart | 3 + lib/features/history/data/models/index.dart | 0 .../history/data/repositories/index.dart | 0 .../history/domain/entities/index.dart | 0 lib/features/history/domain/index.dart | 3 + .../history/domain/respositories/index.dart | 0 .../history/domain/usecases/index.dart | 0 lib/features/history/index.dart | 3 + .../blocs/history_bloc_template.dart | 117 +++++++++ .../history/presentation/blocs/index.dart | 2 + .../blocs/provisional_history_bloc.dart | 0 lib/features/history/presentation/index.dart | 3 + .../pages/access_history_page.dart | 106 ++++++++ .../pages/history_page_template.dart | 211 ++++++++++++++++ .../history/presentation/pages/index.dart | 2 + .../pages/provisional_history_page.dart | 105 ++++++++ .../presentation/widgets/filter_modal.dart | 229 ++++++++++++++++++ .../history/presentation/widgets/index.dart | 1 + 32 files changed, 797 insertions(+) create mode 100644 lib/features/_template_/data/data_sources/index.dart create mode 100644 lib/features/_template_/data/index.dart create mode 100644 lib/features/_template_/data/models/index.dart create mode 100644 lib/features/_template_/data/repositories/index.dart create mode 100644 lib/features/_template_/domain/entities/index.dart create mode 100644 lib/features/_template_/domain/index.dart create mode 100644 lib/features/_template_/domain/respositories/index.dart create mode 100644 lib/features/_template_/domain/usecases/index.dart create mode 100644 lib/features/_template_/index.dart create mode 100644 lib/features/_template_/presentation/blocs/index.dart create mode 100644 lib/features/_template_/presentation/index.dart create mode 100644 lib/features/_template_/presentation/pages/index.dart create mode 100644 lib/features/_template_/presentation/widgets/index.dart create mode 100644 lib/features/history/data/data_sources/index.dart create mode 100644 lib/features/history/data/index.dart create mode 100644 lib/features/history/data/models/index.dart create mode 100644 lib/features/history/data/repositories/index.dart create mode 100644 lib/features/history/domain/entities/index.dart create mode 100644 lib/features/history/domain/index.dart create mode 100644 lib/features/history/domain/respositories/index.dart create mode 100644 lib/features/history/domain/usecases/index.dart create mode 100644 lib/features/history/index.dart create mode 100644 lib/features/history/presentation/blocs/history_bloc_template.dart create mode 100644 lib/features/history/presentation/blocs/index.dart create mode 100644 lib/features/history/presentation/blocs/provisional_history_bloc.dart create mode 100644 lib/features/history/presentation/index.dart create mode 100644 lib/features/history/presentation/pages/access_history_page.dart create mode 100644 lib/features/history/presentation/pages/history_page_template.dart create mode 100644 lib/features/history/presentation/pages/index.dart create mode 100644 lib/features/history/presentation/pages/provisional_history_page.dart create mode 100644 lib/features/history/presentation/widgets/filter_modal.dart create mode 100644 lib/features/history/presentation/widgets/index.dart diff --git a/lib/features/_template_/data/data_sources/index.dart b/lib/features/_template_/data/data_sources/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/data/index.dart b/lib/features/_template_/data/index.dart new file mode 100644 index 00000000..186dfac9 --- /dev/null +++ b/lib/features/_template_/data/index.dart @@ -0,0 +1,3 @@ +export 'data_sources/index.dart'; +export 'repositories/index.dart'; +export 'models/index.dart'; diff --git a/lib/features/_template_/data/models/index.dart b/lib/features/_template_/data/models/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/data/repositories/index.dart b/lib/features/_template_/data/repositories/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/domain/entities/index.dart b/lib/features/_template_/domain/entities/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/domain/index.dart b/lib/features/_template_/domain/index.dart new file mode 100644 index 00000000..00b76d59 --- /dev/null +++ b/lib/features/_template_/domain/index.dart @@ -0,0 +1,3 @@ +export 'entities/index.dart'; +export 'respositories/index.dart'; +export 'usecases/index.dart'; diff --git a/lib/features/_template_/domain/respositories/index.dart b/lib/features/_template_/domain/respositories/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/domain/usecases/index.dart b/lib/features/_template_/domain/usecases/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/index.dart b/lib/features/_template_/index.dart new file mode 100644 index 00000000..aa560630 --- /dev/null +++ b/lib/features/_template_/index.dart @@ -0,0 +1,3 @@ +export 'data/index.dart'; +export 'domain/index.dart'; +export 'presentation/index.dart'; diff --git a/lib/features/_template_/presentation/blocs/index.dart b/lib/features/_template_/presentation/blocs/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/presentation/index.dart b/lib/features/_template_/presentation/index.dart new file mode 100644 index 00000000..48b6447a --- /dev/null +++ b/lib/features/_template_/presentation/index.dart @@ -0,0 +1,3 @@ +export 'blocs/index.dart'; +export 'pages/index.dart'; +export 'widgets/index.dart'; diff --git a/lib/features/_template_/presentation/pages/index.dart b/lib/features/_template_/presentation/pages/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/_template_/presentation/widgets/index.dart b/lib/features/_template_/presentation/widgets/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/data/data_sources/index.dart b/lib/features/history/data/data_sources/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/data/index.dart b/lib/features/history/data/index.dart new file mode 100644 index 00000000..186dfac9 --- /dev/null +++ b/lib/features/history/data/index.dart @@ -0,0 +1,3 @@ +export 'data_sources/index.dart'; +export 'repositories/index.dart'; +export 'models/index.dart'; diff --git a/lib/features/history/data/models/index.dart b/lib/features/history/data/models/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/data/repositories/index.dart b/lib/features/history/data/repositories/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/domain/entities/index.dart b/lib/features/history/domain/entities/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/domain/index.dart b/lib/features/history/domain/index.dart new file mode 100644 index 00000000..00b76d59 --- /dev/null +++ b/lib/features/history/domain/index.dart @@ -0,0 +1,3 @@ +export 'entities/index.dart'; +export 'respositories/index.dart'; +export 'usecases/index.dart'; diff --git a/lib/features/history/domain/respositories/index.dart b/lib/features/history/domain/respositories/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/domain/usecases/index.dart b/lib/features/history/domain/usecases/index.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/index.dart b/lib/features/history/index.dart new file mode 100644 index 00000000..aa560630 --- /dev/null +++ b/lib/features/history/index.dart @@ -0,0 +1,3 @@ +export 'data/index.dart'; +export 'domain/index.dart'; +export 'presentation/index.dart'; diff --git a/lib/features/history/presentation/blocs/history_bloc_template.dart b/lib/features/history/presentation/blocs/history_bloc_template.dart new file mode 100644 index 00000000..60dfe00f --- /dev/null +++ b/lib/features/history/presentation/blocs/history_bloc_template.dart @@ -0,0 +1,117 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/api_requests/api_manager.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/log_util.dart'; + +class HistoryBloc extends Bloc { + final ScrollController scrollController = ScrollController(); + final Future Function(int pageSize, int pageNumber, Map opt) fetchHistoryService; + final bool Function(dynamic item, Map opt)? filterLogic; + + HistoryBloc(Map opt, this.fetchHistoryService, {this.filterLogic}) : super(HistoryState(opt: opt)) { + scrollController.addListener(_onScroll); + on(_onUpdateHistory); + on(_onFetchHistory); + add(FetchHistoryEvent()); + } + + void _onScroll() { + if (scrollController.position.atEdge && scrollController.position.pixels != 0) { + add(FetchHistoryEvent()); + } + } + + Future _onUpdateHistory(UpdateHistoryEvent event, Emitter emit) async { + emit(state.copyWith(opt: event.newOpt, historyWrap: [], pageNumber: 1)); + add(FetchHistoryEvent()); + } + + Future _onFetchHistory(FetchHistoryEvent event, Emitter emit) async { + if (state.loading) return; + emit(state.copyWith(loading: true)); + try { + var response = await fetchHistoryService(state.pageSize, state.pageNumber, state.opt); + + final List history = response.jsonBody['acessos'] ?? []; + List filteredHistory = history.where((item) { + if (filterLogic != null) { + return filterLogic!(item, state.opt); + } else { + return true; // Default to no filtering if no logic is provided + } + }).toList(); + + if (filteredHistory.isNotEmpty) { + emit(state.copyWith( + historyWrap: [...state.historyWrap, ...filteredHistory], + hasData: true, + loading: false, + pageNumber: state.pageNumber + 1, + )); + } else { + emit(state.copyWith(hasData: false, loading: false)); + } + } catch (e, s) { + await DialogUtil.errorDefault(navigatorKey.currentContext!); + LogUtil.requestAPIFailed('processRequest', "", "Fetch History", e, s); + emit(state.copyWith(hasData: false, loading: false, error: e.toString())); + } + } + + @override +Future close() { + scrollController.dispose(); + return super.close(); + } +} + +class HistoryState { + final Map opt; + final List historyWrap; + final bool hasData; + final bool loading; + final int pageNumber; + final int pageSize; + final String? error; + + HistoryState({ + required this.opt, + this.historyWrap = const [], + this.hasData = false, + this.loading = false, + this.pageNumber = 1, + this.pageSize = 10, + this.error, + }); + + HistoryState copyWith({ + Map? opt, + List? historyWrap, + bool? hasData, + bool? loading, + int? pageNumber, + int? pageSize, + String? error, + }) { + return HistoryState( + opt: opt ?? this.opt, + historyWrap: historyWrap ?? this.historyWrap, + hasData: hasData ?? this.hasData, + loading: loading ?? this.loading, + pageNumber: pageNumber ?? this.pageNumber, + pageSize: pageSize ?? this.pageSize, + error: error ?? this.error, + ); + } +} + +abstract class HistoryEvent {} + +class UpdateHistoryEvent extends HistoryEvent { + final Map newOpt; + UpdateHistoryEvent(this.newOpt); +} + +class FetchHistoryEvent extends HistoryEvent {} \ No newline at end of file diff --git a/lib/features/history/presentation/blocs/index.dart b/lib/features/history/presentation/blocs/index.dart new file mode 100644 index 00000000..83ccc77f --- /dev/null +++ b/lib/features/history/presentation/blocs/index.dart @@ -0,0 +1,2 @@ +export 'history_bloc_template.dart'; +export 'provisional_history_bloc.dart'; diff --git a/lib/features/history/presentation/blocs/provisional_history_bloc.dart b/lib/features/history/presentation/blocs/provisional_history_bloc.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/features/history/presentation/index.dart b/lib/features/history/presentation/index.dart new file mode 100644 index 00000000..48b6447a --- /dev/null +++ b/lib/features/history/presentation/index.dart @@ -0,0 +1,3 @@ +export 'blocs/index.dart'; +export 'pages/index.dart'; +export 'widgets/index.dart'; diff --git a/lib/features/history/presentation/pages/access_history_page.dart b/lib/features/history/presentation/pages/access_history_page.dart new file mode 100644 index 00000000..ac031632 --- /dev/null +++ b/lib/features/history/presentation/pages/access_history_page.dart @@ -0,0 +1,106 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/components/molecular_components/message_opt_modal/opt_modal_widget.dart'; +import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; +import 'package:hub/features/history/index.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + +class AcessCubit extends Cubit { + AcessCubit() : super('Provisional'); + + Future fetchCliUUID() async { + final cliUUID = await StorageHelper().get(KeychainStorageKey.clientUUID.value); + emit(cliUUID); + } + + Future fetchHistoryService(int pageSize, int pageNumber, Map opt) async { + return await PhpGroup.getAccessCall.call( + pageSize: pageSize.toString(), + pageNumber: pageNumber.toString(), + pesTipo: opt['personType'] != 'E' && opt['personType'] != 'O' ? 'T' : opt['personType'], + ); + } + + bool filterLogic(dynamic item, Map opt) { + final personTypeMatches = opt['personType'] == '.*' || item["PES_TIPO"].toString() == opt['personType']; + return personTypeMatches; + } +} + +class AccessHistoryPage extends StatelessWidget { + final Map opt = { + 'personType': '.*', + 'accessType': '.*', + 'search': '.*', + }; + + final String appBarTitle = 'Histórico Provisório'; + final String noHistoryMessage = 'Nenhum histórico encontrado!'; + final String errorMessage = 'Falha ao realizar operação!'; + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => AcessCubit()..fetchCliUUID(), + child: HistoryPageTemplate( + opt: opt, + fetchHistoryService: (pageSize, pageNumber, opt) => context.read().fetchHistoryService(pageSize, pageNumber, opt), + cardBuilder: cardBuilder, + appBarTitle: appBarTitle, + noHistoryMessage: noHistoryMessage, + errorMessage: errorMessage, + isLeading: true, + isFilter: true, + filterLogic: (item, opt) => context.read().filterLogic(item, opt), + ), + ); + } + + Widget cardBuilder(BuildContext context, dynamic historyItem) { + final cliUUID = context.watch().state; + final String imagePath = 'https://freaccess.com.br/freaccess/getImage.php?cliID=${cliUUID}&atividade=getFoto&Documento=${historyItem['PES_ID'] ?? ''}&tipo=${historyItem['PES_TIPO'] ?? ''}'; + final Map labelsHashMap = { + FFLocalizations.of(context).getVariableText(ptText: 'Nome:', enText: 'Name:'): historyItem['PES_NOME'] ?? '', + FFLocalizations.of(context).getVariableText(ptText: 'Acesso:', enText: 'Access:'): historyItem['ACE_DATAHORA'] ?? '', + FFLocalizations.of(context).getVariableText(ptText: 'Setor', enText: 'Sector'): historyItem['SET_DESCRICAO'] ?? '', + }; + + final statusHashMap = [ + _getPersonTypeStatus(context, historyItem['PES_TIPO']), + _getAccessTypeStatus(context, historyItem['ACE_TIPO']), + ]; + + return CardItemTemplateComponentWidget( + imagePath: imagePath, + labelsHashMap: labelsHashMap, + statusHashMap: statusHashMap, + onTapCardItemAction: () async {}, + ); + } + + Map _getPersonTypeStatus(BuildContext context, String? personType) { + switch (personType) { + case 'O': + return {FFLocalizations.of(context).getVariableText(ptText: 'Morador', enText: 'Resident'): FlutterFlowTheme.of(context).alternate2}; + case 'E': + return {FFLocalizations.of(context).getVariableText(ptText: 'Visitante', enText: 'Visitor'): FlutterFlowTheme.of(context).alternate2}; + default: + return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).alternate2}; + } + } + + Map _getAccessTypeStatus(BuildContext context, String? accessType) { + switch (accessType) { + case '0': + return {FFLocalizations.of(context).getVariableText(ptText: 'Entrada', enText: 'Entrance'): FlutterFlowTheme.of(context).success}; + case '1': + return {FFLocalizations.of(context).getVariableText(ptText: 'Saída', enText: 'Exit'): FlutterFlowTheme.of(context).error}; + default: + return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).warning}; + } + } +} \ No newline at end of file diff --git a/lib/features/history/presentation/pages/history_page_template.dart b/lib/features/history/presentation/pages/history_page_template.dart new file mode 100644 index 00000000..884d6bc9 --- /dev/null +++ b/lib/features/history/presentation/pages/history_page_template.dart @@ -0,0 +1,211 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:hub/features/history/index.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/backend/api_requests/api_manager.dart'; +import 'package:hub/features/history/presentation/widgets/filter_modal.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/log_util.dart'; +import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; + +class HistoryPageTemplate extends StatelessWidget { + final Map opt; + final Future Function(int pageSize, int pageNumber, Map opt) fetchHistoryService; + final Widget Function(BuildContext context, dynamic historyItem) cardBuilder; + final String appBarTitle; + final String noHistoryMessage; + final String errorMessage; + final bool isLeading; + final bool isFilter; + final bool Function(dynamic item, Map opt)? filterLogic; + + const HistoryPageTemplate({ + Key? key, + required this.opt, + required this.fetchHistoryService, + required this.cardBuilder, + this.appBarTitle = 'History', + this.noHistoryMessage = 'No history found!', + this.errorMessage = 'Failed to perform operation!', + this.isLeading = true, + this.isFilter = false, + this.filterLogic, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => HistoryBloc(opt, fetchHistoryService, filterLogic: filterLogic), + child: HistoryPageView( + cardBuilder: cardBuilder, + appBarTitle: appBarTitle, + noHistoryMessage: noHistoryMessage, + errorMessage: errorMessage, + isLeading: isLeading, + isFilter: isFilter, + ), + ); + } +} + +class HistoryPageView extends StatelessWidget { + final Widget Function(BuildContext context, dynamic historyItem) cardBuilder; + final String appBarTitle; + final String noHistoryMessage; + final String errorMessage; + final bool isLeading; + final bool isFilter; + + const HistoryPageView({ + Key? key, + required this.cardBuilder, + required this.appBarTitle, + required this.noHistoryMessage, + required this.errorMessage, + this.isLeading = false, + this.isFilter = false, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + final theme = FlutterFlowTheme.of(context); + return Scaffold( + key: GlobalKey(), + backgroundColor: theme.primaryBackground, + appBar: _buildAppBar(context, theme), + body: _buildBody(context), + ); + } + + PreferredSizeWidget _buildAppBar(BuildContext context, FlutterFlowTheme theme) { + return AppBar( + backgroundColor: theme.primaryBackground, + automaticallyImplyLeading: false, + leading: isLeading ? _buildBackButton(context, theme) : null, + title: _buildTitle(context, theme), + centerTitle: true, + elevation: 0.0, + actions: [ + if (isFilter) _buildFilterButton(context), + ], + ); + } + + Widget _buildBackButton(BuildContext context, FlutterFlowTheme theme) { + return FlutterFlowIconButton( + borderColor: Colors.transparent, + borderRadius: 30.0, + borderWidth: 1.0, + buttonSize: 60.0, + icon: Icon( + Icons.keyboard_arrow_left, + color: theme.primaryText, + size: 30.0, + ), + onPressed: () => Navigator.of(context).pop(), + ); + } + + Widget _buildTitle(BuildContext context, FlutterFlowTheme theme) { + return Text( + appBarTitle, + style: theme.headlineMedium.override( + fontFamily: theme.headlineMediumFamily, + color: theme.primaryText, + fontSize: 16.0, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey(theme.headlineMediumFamily), + ), + ); + } + + Widget _buildFilterButton(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(0, 0, 10, 0), + child: IconButton( + icon: const Icon(Icons.filter_list), + onPressed: () async { + final Map? selectedFilter = await showModalBottomSheet>( + isScrollControlled: true, + backgroundColor: Colors.transparent, + context: context, + builder: (BuildContext bottomSheetContext) { + return GestureDetector( + onTap: () => Navigator.of(bottomSheetContext).pop(), + child: Container( + color: Colors.transparent, + child: GestureDetector( + onTap: () {}, + child: FilterModalWidget( + defaultSelections: { + 'personType': context.read().state.opt['personType'] == '.*' ? ['E', 'O'] : [context.read().state.opt['personType']], + 'search': '.*', + }, + filterOptions: { + 'personType': [ + {'title': FFLocalizations.of(context).getVariableText(ptText: 'Visitante', enText: 'Visitor'), 'value': 'E',}, + {'title': FFLocalizations.of(context).getVariableText(ptText: 'Morador', enText: 'Resident'), 'value': 'O',}, + + ], + }, + filterTitles: { + 'personType': 'Person Type', + }, + ), + ), + ), + ); + }, + ); + + if (selectedFilter != null) { + context.read().add(UpdateHistoryEvent(selectedFilter)); + } + }, + ), + ), + ], + ); + } + + Widget _buildBody(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + if (state.loading && state.historyWrap.isEmpty) { + return Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + FlutterFlowTheme.of(context).primary, + ), + ), + ); + } else if (state.error != null) { + return Center( + child: Text(errorMessage), + ); + } else if (state.historyWrap.isEmpty) { + return Center( + child: Text(noHistoryMessage), + ); + } else { + return ListView.builder( + shrinkWrap: true, + physics: const BouncingScrollPhysics(), + controller: context.read().scrollController, + itemCount: state.historyWrap.length, + itemBuilder: (context, index) { + final historyItem = state.historyWrap[index]; + return cardBuilder(context, historyItem); + }, + ); + } + }, + ); + } +} \ No newline at end of file diff --git a/lib/features/history/presentation/pages/index.dart b/lib/features/history/presentation/pages/index.dart new file mode 100644 index 00000000..5b174ec8 --- /dev/null +++ b/lib/features/history/presentation/pages/index.dart @@ -0,0 +1,2 @@ +export 'history_page_template.dart'; +export 'provisional_history_page.dart'; diff --git a/lib/features/history/presentation/pages/provisional_history_page.dart b/lib/features/history/presentation/pages/provisional_history_page.dart new file mode 100644 index 00000000..4c58dcb0 --- /dev/null +++ b/lib/features/history/presentation/pages/provisional_history_page.dart @@ -0,0 +1,105 @@ +import 'dart:developer'; + +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:hub/backend/api_requests/api_calls.dart'; +import 'package:hub/components/molecular_components/message_opt_modal/opt_modal_widget.dart'; +import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; +import 'package:hub/features/history/index.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/internationalization.dart'; +import 'package:hub/shared/helpers/storage/base_storage.dart'; +import 'package:hub/shared/helpers/storage/storage_helper.dart'; + +class ProvisionalCubit extends Cubit { + ProvisionalCubit() : super('Provisional'); + + Future fetchCliUUID() async { + final cliUUID = await StorageHelper().get(KeychainStorageKey.clientUUID.value); + emit(cliUUID); + } + + Future fetchHistoryService(int pageSize, int pageNumber, Map status) async { + return await PhpGroup.getProvSchedules(pageNumber.toString()); + } + + bool filterLogic(dynamic item, Map opt) { + final personTypeMatches = opt['personType'] == '.*' || item["PES_TIPO"].toString() == opt['personType']; + return personTypeMatches; + } +} + +class ProvisionalHistoryPage extends StatelessWidget { + final Map opt = { + 'personType': '.*', + 'accessType': '.*', + 'search': '.*', + }; + + final String appBarTitle = 'Histórico Provisório'; + final String noHistoryMessage = 'Nenhum histórico encontrado!'; + final String errorMessage = 'Falha ao realizar operação!'; + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => ProvisionalCubit()..fetchCliUUID(), + child: HistoryPageTemplate( + opt: opt, + fetchHistoryService: (pageSize, pageNumber, opt) => context.read().fetchHistoryService(pageSize, pageNumber, opt), + cardBuilder: cardBuilder, + appBarTitle: appBarTitle, + noHistoryMessage: noHistoryMessage, + errorMessage: errorMessage, + isLeading: true, + isFilter: false, + filterLogic: (item, opt) => context.read().filterLogic(item, opt), + ), + ); + } + + Widget cardBuilder(BuildContext context, dynamic historyItem) { + log('historyItem: $historyItem'); + final cliUUID = context.watch().state; + final String imagePath = 'https://freaccess.com.br/freaccess/getImage.php?cliID=${cliUUID}&atividade=getFoto&Documento=${historyItem['PES_ID'] ?? ''}&tipo=${historyItem['PES_TIPO'] ?? ''}'; + final Map labelsHashMap = { + FFLocalizations.of(context).getVariableText(ptText: 'Nome:', enText: 'Name:'): historyItem['PES_NOME'] ?? '', + FFLocalizations.of(context).getVariableText(ptText: 'Acesso:', enText: 'Access:'): historyItem['ACE_DATAHORA'] ?? '', + FFLocalizations.of(context).getVariableText(ptText: 'Setor', enText: 'Sector'): historyItem['SET_DESCRICAO'] ?? '', + }; + + final statusHashMap = [ + _getPersonTypeStatus(context, historyItem['PES_TIPO']), + _getAccessTypeStatus(context, historyItem['ACE_TIPO']), + ]; + + return CardItemTemplateComponentWidget( + imagePath: imagePath, + labelsHashMap: labelsHashMap, + statusHashMap: statusHashMap, + onTapCardItemAction: () async {}, + ); + } + + Map _getPersonTypeStatus(BuildContext context, String? personType) { + switch (personType) { + case 'O': + return {FFLocalizations.of(context).getVariableText(ptText: 'Morador', enText: 'Resident'): FlutterFlowTheme.of(context).alternate2}; + case 'E': + return {FFLocalizations.of(context).getVariableText(ptText: 'Visitante', enText: 'Visitor'): FlutterFlowTheme.of(context).alternate2}; + default: + return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).alternate2}; + } + } + + Map _getAccessTypeStatus(BuildContext context, String? accessType) { + switch (accessType) { + case '0': + return {FFLocalizations.of(context).getVariableText(ptText: 'Entrada', enText: 'Entrance'): FlutterFlowTheme.of(context).success}; + case '1': + return {FFLocalizations.of(context).getVariableText(ptText: 'Saída', enText: 'Exit'): FlutterFlowTheme.of(context).error}; + default: + return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).warning}; + } + } +} \ No newline at end of file diff --git a/lib/features/history/presentation/widgets/filter_modal.dart b/lib/features/history/presentation/widgets/filter_modal.dart new file mode 100644 index 00000000..c44a545b --- /dev/null +++ b/lib/features/history/presentation/widgets/filter_modal.dart @@ -0,0 +1,229 @@ +import 'package:flutter/material.dart'; + +import '/flutter_flow/flutter_flow_util.dart'; +import '/flutter_flow/form_field_controller.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/shared/utils/limited_text_size.dart'; + + + +class FilterModal extends FlutterFlowModel { + FocusNode? textFieldFocusNode; + TextEditingController? textController; + String? Function(BuildContext, String?)? textControllerValidator; + bool? checkboxValue1; + bool? checkboxValue2; + FormFieldController>? checkboxGroupValueController; + List? get checkboxGroupValues => checkboxGroupValueController?.value; + set checkboxGroupValues(List? v) => checkboxGroupValueController?.value = v; + + @override + void initState(BuildContext context) {} + + @override + void dispose() { + textFieldFocusNode?.dispose(); + textController?.dispose(); + } +} + +class FilterModalWidget extends StatefulWidget { + final Map defaultSelections; + final Map>> filterOptions; + final Map filterTitles; + + const FilterModalWidget({ + super.key, + required this.defaultSelections, + required this.filterOptions, + required this.filterTitles, + }); + + @override + _FilterModalWidgetState createState() => _FilterModalWidgetState(); +} + +class _FilterModalWidgetState extends State { + late FilterModal _model; + late Map selected; + + @override + void setState(VoidCallback callback) { + super.setState(callback); + _model.onUpdate(); + } + + @override + void initState() { + super.initState(); + + _model = createModel(context, () => FilterModal()); + + _model.textController ??= TextEditingController(); + _model.textFieldFocusNode ??= FocusNode(); + + selected = widget.defaultSelections; + } + + void _applyFilter() { + Map filterResult = { + 'search': _model.textController?.text == '' ? '.*' : _model.textController!.text.toLowerCase(), + }; + + widget.filterOptions.forEach((key, options) { + filterResult[key] = selected[key]!.isEmpty || selected[key]!.length > 1 + ? '.*' + : selected[key]!.first; + }); + + context.pop(filterResult); + } + + Widget _buildCheckboxListTile(String key, List> options, double fontsize) { + double limitedInputFontSize = LimitedFontSizeUtil.getInputFontSize(context); + return Column( + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsetsDirectional.fromSTEB(0.0, 3.0, 0.0, 0.0), + child: Text( + widget.filterTitles[key]!, + textAlign: TextAlign.left, + style: FlutterFlowTheme.of(context).bodyMedium.override( + fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, + fontSize: limitedInputFontSize, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).bodyMediumFamily), + color: FlutterFlowTheme.of(context).primaryText, + ), + ), + ), + ], + ), + ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: options.length, + itemBuilder: (context, index) { + final option = options[index]; + return CheckboxListTile( + title: Text( + option['title']!, + style: FlutterFlowTheme.of(context).bodyMedium.override( + fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, + letterSpacing: 0.0, + fontSize: limitedInputFontSize, + useGoogleFonts: GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).bodyMediumFamily), + color: FlutterFlowTheme.of(context).primaryText, + ), + ), + dense: true, + value: selected[key]!.contains(option['value']), + onChanged: (bool? value) { + setState(() { + if (value == true) { + if (!selected[key]!.contains(option['value'])) { + selected[key]!.add(option['value']); + } + } else { + selected[key]!.remove(option['value']); + } + }); + }, + activeColor: FlutterFlowTheme.of(context).primary, + checkColor: FlutterFlowTheme.of(context).info, + checkboxShape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(100), + ), + enableFeedback: true, + side: BorderSide( + width: 5, + color: FlutterFlowTheme.of(context).secondaryText, + ), + controlAffinity: ListTileControlAffinity.leading, + ); + }, + ), + ], + ); + } + + @override + Widget build(BuildContext context) { + double screenWidth = MediaQuery.of(context).size.width; + + return Center( + child: Container( + width: screenWidth - (screenWidth * 0.35), + height: 250, + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primaryBackground, + borderRadius: BorderRadius.circular(24.0), + ), + child: Padding( + padding: const EdgeInsets.all(4.0), + child: Column( + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsetsDirectional.fromSTEB(10.0, 10.0, 0.0, 10.0), + child: Text( + FFLocalizations.of(context).getText('yfj9pd6k'), + style: FlutterFlowTheme.of(context).headlineMedium.override( + fontFamily: FlutterFlowTheme.of(context).headlineMediumFamily, + color: FlutterFlowTheme.of(context).primaryText, + fontSize: LimitedFontSizeUtil.getHeaderFontSize(context), + letterSpacing: 0.0, + fontWeight: FontWeight.bold, + useGoogleFonts: + GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).headlineMediumFamily), + ), + ), + ), + ], + ), + Expanded( + child: SingleChildScrollView( + child: Container( + padding: const EdgeInsets.all(10), + child: Column( + mainAxisSize: MainAxisSize.min, + children: widget.filterOptions.keys.map((key) { + return _buildCheckboxListTile(key, widget.filterOptions[key]!, 14); + }).toList(), + ), + ), + ), + ), + ElevatedButton( + onPressed: _applyFilter, + style: ElevatedButton.styleFrom( + foregroundColor: FlutterFlowTheme.of(context).info, + backgroundColor: FlutterFlowTheme.of(context).primary, + ), + child: Text(FFLocalizations.of(context).getText('88kshkph'), + style: FlutterFlowTheme.of(context).bodyMedium.override( + fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, + color: FlutterFlowTheme.of(context).info, + fontSize: LimitedFontSizeUtil.getInputFontSize(context), + letterSpacing: 0.0, + fontWeight: FontWeight.bold, + useGoogleFonts: + GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).bodyMediumFamily), + )), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/features/history/presentation/widgets/index.dart b/lib/features/history/presentation/widgets/index.dart new file mode 100644 index 00000000..2191ab0c --- /dev/null +++ b/lib/features/history/presentation/widgets/index.dart @@ -0,0 +1 @@ +export 'filter_modal.dart'; From 5d6629797a23f833493249eae6f7f7faf9a250fb Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 13:26:07 -0300 Subject: [PATCH 60/75] fix: encomendas labels and filters --- lib/pages/package_order_page/package_order_page.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index b63c5186..569cf698 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -36,11 +36,11 @@ class _PackageOrderPage extends State { List _orderList = []; final Map filter = { - 'adresseeType': '.*', + 'adresseeType': 'PRO', 'status': 'notPickedUp', }; - String _adresseeType = '.*'; + String _adresseeType = 'PRO'; String _status = 'notPickedUp'; late BehaviorSubject> _selectedTypeSubject; @@ -224,7 +224,7 @@ class _PackageOrderPage extends State { return AppBar( backgroundColor: FlutterFlowTheme.of(context).primaryBackground, automaticallyImplyLeading: false, - title: Text(FFLocalizations.of(context).getVariableText(enText: 'My Orders', ptText: 'Minhas Encomendas'), + title: Text(FFLocalizations.of(context).getVariableText(enText: 'Orders', ptText: 'Encomendas'), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: 'Nunito', color: FlutterFlowTheme.of(context).primaryText, From 4ca6f759d07d78f837a557c888b756372cd33e84 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 13:38:17 -0300 Subject: [PATCH 61/75] WIP --- lib/backend/api_requests/api_calls.dart | 37 +++++++++++++++++++ .../pages/provisional_history_page.dart | 2 +- lib/flutter_flow/nav/nav.dart | 3 +- lib/main.dart | 3 +- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index c07b24de..aea6aa68 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -59,6 +59,43 @@ class PhpGroup { static GetResidentsByProperty getResidentsByProperty = GetResidentsByProperty(); static GetOpenedVisits getOpenedVisits = GetOpenedVisits(); static GetLicense getLicense = GetLicense(); + static GetProvSchedules getProvSchedules = GetProvSchedules(); +} + +class GetProvSchedules { + Future call(final String page) async { + // final String baseUrl = PhpGroup.getBaseUrl(); + // final String devUUID = (await StorageHelper().g(KeychainStorageKey.devUUID.value)) ?? ''; + // final String userUUID = (await StorageHelper().g(KeychainStorageKey.userUUID.value)) ?? ''; + // final String cliID = (await StorageHelper().g(KeychainStorageKey.clientUUID.value)) ?? ''; + // const String atividade = 'getProvSchedules'; + // const String pageSize = '10'; + final String baseUrl = 'http://localhost:3000'; + return await ApiManager.instance.makeApiCall( + callName: 'getProvSchedules', + apiUrl: '$baseUrl/getAgendamentoProv.php', + callType: ApiCallType.POST, + headers: {'Content-Type': 'application/x-www-form-urlencoded'}, + params: { + "proId": "8", + "status": "AT", + "page": page, + "pageSize": "10" + // 'devUUID': devUUID, + // 'userUUID': userUUID, + // 'cliID': cliID, + // 'atividade': atividade, + // 'page': page, + // 'pageSize': pageSize, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + alwaysAllowBody: false, + ); + } } class GetOpenedVisits { diff --git a/lib/features/history/presentation/pages/provisional_history_page.dart b/lib/features/history/presentation/pages/provisional_history_page.dart index 4c58dcb0..70220c77 100644 --- a/lib/features/history/presentation/pages/provisional_history_page.dart +++ b/lib/features/history/presentation/pages/provisional_history_page.dart @@ -53,7 +53,7 @@ class ProvisionalHistoryPage extends StatelessWidget { errorMessage: errorMessage, isLeading: true, isFilter: false, - filterLogic: (item, opt) => context.read().filterLogic(item, opt), + filterLogic: null, ), ); } diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index a62e5d2a..d07173be 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:hub/backend/schema/util/schema_util.dart'; +import 'package:hub/features/history/presentation/pages/provisional_history_page.dart'; import 'package:hub/features/home/index.dart'; import 'package:hub/features/property/index.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; @@ -130,7 +131,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { FFRoute(name: 'petsOnThePropertyPage', path: '/petsOnThePropertyPage', builder: (context, params) => Scaffold(body: const PetsHistoryScreen(isApp: true))), FFRoute(name: 'vehiclesOnThePropertyPage', path: '/vehiclesOnThePropertyPage', builder: (context, params) => const VehicleOnTheProperty()), FFRoute(name: 'receptionPage', path: '/receptionPage', builder: (context, params) => const ReceptionPageWidget()), - FFRoute(name: 'messageHistoryPage', path: '/messageHistoryPage', builder: (context, params) => const MessageHistoryPageWidget()), + FFRoute(name: 'messageHistoryPage', path: '/messageHistoryPage', builder: (context, params) => ProvisionalHistoryPage()), FFRoute(name: 'registerVisitorPage', path: '/registerVisitorPage', builder: (context, params) => const RegisterVisitorPageWidget()), FFRoute(name: 'scheduleCompleteVisitPage', path: '/scheduleCompleteVisitPage', builder: (context, params) => const ScheduleCompleteVisitPageWidget()), FFRoute(name: 'deliverySchedule', path: '/deliverySchedule', builder: (context, params) => const DeliverySchedule()), diff --git a/lib/main.dart b/lib/main.dart index 8ba07637..9b72ba47 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -169,8 +169,7 @@ class _AppState extends State { @override void initState() { super.initState(); - - + FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); _appStateNotifier = AppStateNotifier.instance; _router = createRouter(_appStateNotifier); From cea8328f04c059624738a7612a16966572549116 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 13:41:05 -0300 Subject: [PATCH 62/75] fix: orders backgroundColor --- lib/pages/package_order_page/package_order_page.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pages/package_order_page/package_order_page.dart b/lib/pages/package_order_page/package_order_page.dart index 569cf698..980c5c0b 100644 --- a/lib/pages/package_order_page/package_order_page.dart +++ b/lib/pages/package_order_page/package_order_page.dart @@ -412,6 +412,7 @@ class _PackageOrderPage extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: FlutterFlowTheme.of(context).primaryBackground, appBar: _appBar(context), body: _appBody(context), ); From eae3792abe8dbaa64f6a259d59357b3e7b062059 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 14:42:08 -0300 Subject: [PATCH 63/75] fix: unlink locals - select locals --- .../repositories/locals_repository_impl.dart | 5 +++-- .../molecules/locals/utils/local_util.dart | 1 + .../license_local_data_source.dart | 3 +-- .../helpers/database/database_helper.dart | 11 +++++----- lib/shared/helpers/storage/base_storage.dart | 3 +++ .../helpers/storage/keychain_storage.dart | 3 +-- .../helpers/storage/secure_storage.dart | 20 +++++++++++++++++-- .../authentication_service.dart | 4 ++++ 8 files changed, 36 insertions(+), 14 deletions(-) diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 9c0a71eb..93a8aa27 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -77,7 +77,8 @@ class LocalsRepositoryImpl implements LocalsRepository { } @override - Future unlinkLocal(BuildContext context) { - return remoteDataSource.detachLocal(context); + Future unlinkLocal(BuildContext context) async { + await remoteDataSource.detachLocal(context); + await select(context); } } diff --git a/lib/shared/components/molecules/locals/utils/local_util.dart b/lib/shared/components/molecules/locals/utils/local_util.dart index 8fe8350d..9aaa7772 100644 --- a/lib/shared/components/molecules/locals/utils/local_util.dart +++ b/lib/shared/components/molecules/locals/utils/local_util.dart @@ -90,6 +90,7 @@ class LocalUtil { await StorageHelper().set(KeychainStorageKey.petAmount.value, jsonBody['petAmountRegister']?.toString().isEmpty ?? true ? '0' : jsonBody['petAmountRegister'].toString()); await StorageHelper().set(KeychainStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'] ?? ''); + await StorageHelper().set(KeychainStorageKey.userEmail.value, jsonBody['visitado']['VDO_EMAIL'] ?? ''); final bool isNewVersion = jsonBody['newVersion'] ?? false; await StorageHelper().set(KeychainStorageKey.isNewVersion.value, isNewVersion); diff --git a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart index 42e5bac7..ff502e5f 100644 --- a/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart +++ b/lib/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart @@ -82,7 +82,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource { @override Future clear() async { await DatabaseStorage.database.delete(tableLicense); - await DatabaseStorage.database.rawDelete( - 'DELETE FROM sqlite_sequence WHERE name = "$tableLicense"'); + } } diff --git a/lib/shared/helpers/database/database_helper.dart b/lib/shared/helpers/database/database_helper.dart index dec8a983..1fe11f02 100644 --- a/lib/shared/helpers/database/database_helper.dart +++ b/lib/shared/helpers/database/database_helper.dart @@ -33,8 +33,7 @@ class DatabaseStorage { onUpgrade: _onUpgrade, onDowngrade: _onDowngrade, onOpen: _onOpen, - onConfigure: _onConfigure, - singleInstance: true, + onConfigure: _onConfigure, ); await LicenseRepositoryImpl().updateLicense(); isInitialized = true; @@ -62,7 +61,7 @@ class DatabaseStorage { } Future _onDowngrade(Database database, int oldVersion, int newVersion) async { - print('Downgrading database from version $oldVersion to $newVersion...'); + print('Downgrading database from version $oldVersion to $newVersion...'); if (oldVersion >= 2 && newVersion < 2) { await _dropTables(database); } @@ -70,9 +69,9 @@ class DatabaseStorage { Future _executePragmas(Database database) async { // await database.execute('PRAGMA journal_mode = WAL;'); - await database.execute('PRAGMA synchronous = NORMAL;'); - await database.execute('PRAGMA temp_store = MEMORY;'); - await database.execute('PRAGMA foreign_keys = ON;'); + // await database.execute('PRAGMA synchronous = NORMAL;'); + // await database.execute('PRAGMA temp_store = MEMORY;'); + // await database.execute('PRAGMA foreign_keys = ON;'); } Future _createTables(Database database, int version) async { diff --git a/lib/shared/helpers/storage/base_storage.dart b/lib/shared/helpers/storage/base_storage.dart index f63582ec..27892246 100644 --- a/lib/shared/helpers/storage/base_storage.dart +++ b/lib/shared/helpers/storage/base_storage.dart @@ -79,6 +79,7 @@ enum KeychainStorageKey { userDevUUID, status, userName, + userEmail, clientUUID, ownerName, ownerUUID, @@ -100,6 +101,8 @@ enum KeychainStorageKey { extension KeychainStorageKeyExtension on KeychainStorageKey { String get value { switch (this) { + case KeychainStorageKey.userEmail: + return 'fre_userEmail'; case KeychainStorageKey.devUUID: return 'fre_devUUID'; case KeychainStorageKey.userUUID: diff --git a/lib/shared/helpers/storage/keychain_storage.dart b/lib/shared/helpers/storage/keychain_storage.dart index 4328c11f..b86cb7f9 100644 --- a/lib/shared/helpers/storage/keychain_storage.dart +++ b/lib/shared/helpers/storage/keychain_storage.dart @@ -59,8 +59,7 @@ class KeychainHelper implements BaseStorage { Future clearAll() async { try { await DatabaseStorage.database.delete(tableKeychain); - await DatabaseStorage.database.rawDelete( - 'DELETE FROM sqlite_sequence WHERE name = "$tableKeychain"'); + } catch (e, s) { log('() => clearAll keychain: $e', stackTrace: s); diff --git a/lib/shared/helpers/storage/secure_storage.dart b/lib/shared/helpers/storage/secure_storage.dart index 59125aa2..e1138229 100644 --- a/lib/shared/helpers/storage/secure_storage.dart +++ b/lib/shared/helpers/storage/secure_storage.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; @@ -23,7 +25,12 @@ class SecureStorage implements BaseStorage { @override Future set(String key, T value) async { - await _secureStorage.write(key: key, value: value.toString()); + log('Setting value: $value'); + try { + await _secureStorage.write(key: key, value: value.toString()); + } catch (e, s) { + log('Error setting value: $e', stackTrace: s); + } } @override @@ -33,6 +40,15 @@ class SecureStorage implements BaseStorage { @override Future clearAll() async { - await _secureStorage.deleteAll(); + log('Clearing SecureStorage'); + try{ + await _secureStorage.deleteAll( + aOptions: AndroidOptions(), + iOptions: IOSOptions(), + ); + } catch (e, s) { + log('Error clearing all: $e', stackTrace: s); + } + } } diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 2977d9a8..522382bc 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -1,6 +1,7 @@ import 'dart:developer'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/features/home/presentation/pages/home_page.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/shared/components/molecules/modules/data/repositories/license_repository_impl.dart'; @@ -14,6 +15,8 @@ import '../../../backend/api_requests/api_calls.dart'; import '../../../flutter_flow/flutter_flow_util.dart'; import '../../../flutter_flow/random_data_util.dart'; import '../../components/molecules/locals/data/index.dart'; +import '../../components/molecules/locals/index.dart'; +import '../../components/molecules/menu/index.dart'; import '../../utils/device_util.dart'; import '../../utils/dialog_util.dart'; import '../../utils/log_util.dart'; @@ -152,6 +155,7 @@ class AuthenticationService { await LicenseRepositoryImpl().cleanLicense(); DatabaseStorage.isInitialized = false; await StorageHelper().init(); + context.go('/welcomePage', extra: extra); } From 92a8986a7ee649a4921052bf6ff49f28a2ee9382 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 14:45:51 -0300 Subject: [PATCH 64/75] WIP --- .../history/data/data_sources/index.dart | 0 lib/features/history/data/index.dart | 3 - lib/features/history/data/models/index.dart | 0 .../history/data/repositories/index.dart | 0 .../history/domain/entities/index.dart | 0 lib/features/history/domain/index.dart | 3 - .../history/domain/respositories/index.dart | 0 .../history/domain/usecases/index.dart | 0 lib/features/history/index.dart | 3 - .../blocs/history_bloc_template.dart | 117 --------- .../history/presentation/blocs/index.dart | 2 - .../blocs/provisional_history_bloc.dart | 0 lib/features/history/presentation/index.dart | 3 - .../pages/access_history_page.dart | 106 -------- .../pages/history_page_template.dart | 211 ---------------- .../history/presentation/pages/index.dart | 2 - .../pages/provisional_history_page.dart | 105 -------- .../presentation/widgets/filter_modal.dart | 229 ------------------ .../history/presentation/widgets/index.dart | 1 - lib/flutter_flow/nav/nav.dart | 3 +- 20 files changed, 1 insertion(+), 787 deletions(-) delete mode 100644 lib/features/history/data/data_sources/index.dart delete mode 100644 lib/features/history/data/index.dart delete mode 100644 lib/features/history/data/models/index.dart delete mode 100644 lib/features/history/data/repositories/index.dart delete mode 100644 lib/features/history/domain/entities/index.dart delete mode 100644 lib/features/history/domain/index.dart delete mode 100644 lib/features/history/domain/respositories/index.dart delete mode 100644 lib/features/history/domain/usecases/index.dart delete mode 100644 lib/features/history/index.dart delete mode 100644 lib/features/history/presentation/blocs/history_bloc_template.dart delete mode 100644 lib/features/history/presentation/blocs/index.dart delete mode 100644 lib/features/history/presentation/blocs/provisional_history_bloc.dart delete mode 100644 lib/features/history/presentation/index.dart delete mode 100644 lib/features/history/presentation/pages/access_history_page.dart delete mode 100644 lib/features/history/presentation/pages/history_page_template.dart delete mode 100644 lib/features/history/presentation/pages/index.dart delete mode 100644 lib/features/history/presentation/pages/provisional_history_page.dart delete mode 100644 lib/features/history/presentation/widgets/filter_modal.dart delete mode 100644 lib/features/history/presentation/widgets/index.dart diff --git a/lib/features/history/data/data_sources/index.dart b/lib/features/history/data/data_sources/index.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/history/data/index.dart b/lib/features/history/data/index.dart deleted file mode 100644 index 186dfac9..00000000 --- a/lib/features/history/data/index.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'data_sources/index.dart'; -export 'repositories/index.dart'; -export 'models/index.dart'; diff --git a/lib/features/history/data/models/index.dart b/lib/features/history/data/models/index.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/history/data/repositories/index.dart b/lib/features/history/data/repositories/index.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/history/domain/entities/index.dart b/lib/features/history/domain/entities/index.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/history/domain/index.dart b/lib/features/history/domain/index.dart deleted file mode 100644 index 00b76d59..00000000 --- a/lib/features/history/domain/index.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'entities/index.dart'; -export 'respositories/index.dart'; -export 'usecases/index.dart'; diff --git a/lib/features/history/domain/respositories/index.dart b/lib/features/history/domain/respositories/index.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/history/domain/usecases/index.dart b/lib/features/history/domain/usecases/index.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/history/index.dart b/lib/features/history/index.dart deleted file mode 100644 index aa560630..00000000 --- a/lib/features/history/index.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'data/index.dart'; -export 'domain/index.dart'; -export 'presentation/index.dart'; diff --git a/lib/features/history/presentation/blocs/history_bloc_template.dart b/lib/features/history/presentation/blocs/history_bloc_template.dart deleted file mode 100644 index 60dfe00f..00000000 --- a/lib/features/history/presentation/blocs/history_bloc_template.dart +++ /dev/null @@ -1,117 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/api_requests/api_manager.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/utils/dialog_util.dart'; -import 'package:hub/shared/utils/log_util.dart'; - -class HistoryBloc extends Bloc { - final ScrollController scrollController = ScrollController(); - final Future Function(int pageSize, int pageNumber, Map opt) fetchHistoryService; - final bool Function(dynamic item, Map opt)? filterLogic; - - HistoryBloc(Map opt, this.fetchHistoryService, {this.filterLogic}) : super(HistoryState(opt: opt)) { - scrollController.addListener(_onScroll); - on(_onUpdateHistory); - on(_onFetchHistory); - add(FetchHistoryEvent()); - } - - void _onScroll() { - if (scrollController.position.atEdge && scrollController.position.pixels != 0) { - add(FetchHistoryEvent()); - } - } - - Future _onUpdateHistory(UpdateHistoryEvent event, Emitter emit) async { - emit(state.copyWith(opt: event.newOpt, historyWrap: [], pageNumber: 1)); - add(FetchHistoryEvent()); - } - - Future _onFetchHistory(FetchHistoryEvent event, Emitter emit) async { - if (state.loading) return; - emit(state.copyWith(loading: true)); - try { - var response = await fetchHistoryService(state.pageSize, state.pageNumber, state.opt); - - final List history = response.jsonBody['acessos'] ?? []; - List filteredHistory = history.where((item) { - if (filterLogic != null) { - return filterLogic!(item, state.opt); - } else { - return true; // Default to no filtering if no logic is provided - } - }).toList(); - - if (filteredHistory.isNotEmpty) { - emit(state.copyWith( - historyWrap: [...state.historyWrap, ...filteredHistory], - hasData: true, - loading: false, - pageNumber: state.pageNumber + 1, - )); - } else { - emit(state.copyWith(hasData: false, loading: false)); - } - } catch (e, s) { - await DialogUtil.errorDefault(navigatorKey.currentContext!); - LogUtil.requestAPIFailed('processRequest', "", "Fetch History", e, s); - emit(state.copyWith(hasData: false, loading: false, error: e.toString())); - } - } - - @override -Future close() { - scrollController.dispose(); - return super.close(); - } -} - -class HistoryState { - final Map opt; - final List historyWrap; - final bool hasData; - final bool loading; - final int pageNumber; - final int pageSize; - final String? error; - - HistoryState({ - required this.opt, - this.historyWrap = const [], - this.hasData = false, - this.loading = false, - this.pageNumber = 1, - this.pageSize = 10, - this.error, - }); - - HistoryState copyWith({ - Map? opt, - List? historyWrap, - bool? hasData, - bool? loading, - int? pageNumber, - int? pageSize, - String? error, - }) { - return HistoryState( - opt: opt ?? this.opt, - historyWrap: historyWrap ?? this.historyWrap, - hasData: hasData ?? this.hasData, - loading: loading ?? this.loading, - pageNumber: pageNumber ?? this.pageNumber, - pageSize: pageSize ?? this.pageSize, - error: error ?? this.error, - ); - } -} - -abstract class HistoryEvent {} - -class UpdateHistoryEvent extends HistoryEvent { - final Map newOpt; - UpdateHistoryEvent(this.newOpt); -} - -class FetchHistoryEvent extends HistoryEvent {} \ No newline at end of file diff --git a/lib/features/history/presentation/blocs/index.dart b/lib/features/history/presentation/blocs/index.dart deleted file mode 100644 index 83ccc77f..00000000 --- a/lib/features/history/presentation/blocs/index.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'history_bloc_template.dart'; -export 'provisional_history_bloc.dart'; diff --git a/lib/features/history/presentation/blocs/provisional_history_bloc.dart b/lib/features/history/presentation/blocs/provisional_history_bloc.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/history/presentation/index.dart b/lib/features/history/presentation/index.dart deleted file mode 100644 index 48b6447a..00000000 --- a/lib/features/history/presentation/index.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'blocs/index.dart'; -export 'pages/index.dart'; -export 'widgets/index.dart'; diff --git a/lib/features/history/presentation/pages/access_history_page.dart b/lib/features/history/presentation/pages/access_history_page.dart deleted file mode 100644 index ac031632..00000000 --- a/lib/features/history/presentation/pages/access_history_page.dart +++ /dev/null @@ -1,106 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/components/molecular_components/message_opt_modal/opt_modal_widget.dart'; -import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; -import 'package:hub/features/history/index.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; - -class AcessCubit extends Cubit { - AcessCubit() : super('Provisional'); - - Future fetchCliUUID() async { - final cliUUID = await StorageHelper().get(KeychainStorageKey.clientUUID.value); - emit(cliUUID); - } - - Future fetchHistoryService(int pageSize, int pageNumber, Map opt) async { - return await PhpGroup.getAccessCall.call( - pageSize: pageSize.toString(), - pageNumber: pageNumber.toString(), - pesTipo: opt['personType'] != 'E' && opt['personType'] != 'O' ? 'T' : opt['personType'], - ); - } - - bool filterLogic(dynamic item, Map opt) { - final personTypeMatches = opt['personType'] == '.*' || item["PES_TIPO"].toString() == opt['personType']; - return personTypeMatches; - } -} - -class AccessHistoryPage extends StatelessWidget { - final Map opt = { - 'personType': '.*', - 'accessType': '.*', - 'search': '.*', - }; - - final String appBarTitle = 'Histórico Provisório'; - final String noHistoryMessage = 'Nenhum histórico encontrado!'; - final String errorMessage = 'Falha ao realizar operação!'; - - @override - Widget build(BuildContext context) { - return BlocProvider( - create: (context) => AcessCubit()..fetchCliUUID(), - child: HistoryPageTemplate( - opt: opt, - fetchHistoryService: (pageSize, pageNumber, opt) => context.read().fetchHistoryService(pageSize, pageNumber, opt), - cardBuilder: cardBuilder, - appBarTitle: appBarTitle, - noHistoryMessage: noHistoryMessage, - errorMessage: errorMessage, - isLeading: true, - isFilter: true, - filterLogic: (item, opt) => context.read().filterLogic(item, opt), - ), - ); - } - - Widget cardBuilder(BuildContext context, dynamic historyItem) { - final cliUUID = context.watch().state; - final String imagePath = 'https://freaccess.com.br/freaccess/getImage.php?cliID=${cliUUID}&atividade=getFoto&Documento=${historyItem['PES_ID'] ?? ''}&tipo=${historyItem['PES_TIPO'] ?? ''}'; - final Map labelsHashMap = { - FFLocalizations.of(context).getVariableText(ptText: 'Nome:', enText: 'Name:'): historyItem['PES_NOME'] ?? '', - FFLocalizations.of(context).getVariableText(ptText: 'Acesso:', enText: 'Access:'): historyItem['ACE_DATAHORA'] ?? '', - FFLocalizations.of(context).getVariableText(ptText: 'Setor', enText: 'Sector'): historyItem['SET_DESCRICAO'] ?? '', - }; - - final statusHashMap = [ - _getPersonTypeStatus(context, historyItem['PES_TIPO']), - _getAccessTypeStatus(context, historyItem['ACE_TIPO']), - ]; - - return CardItemTemplateComponentWidget( - imagePath: imagePath, - labelsHashMap: labelsHashMap, - statusHashMap: statusHashMap, - onTapCardItemAction: () async {}, - ); - } - - Map _getPersonTypeStatus(BuildContext context, String? personType) { - switch (personType) { - case 'O': - return {FFLocalizations.of(context).getVariableText(ptText: 'Morador', enText: 'Resident'): FlutterFlowTheme.of(context).alternate2}; - case 'E': - return {FFLocalizations.of(context).getVariableText(ptText: 'Visitante', enText: 'Visitor'): FlutterFlowTheme.of(context).alternate2}; - default: - return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).alternate2}; - } - } - - Map _getAccessTypeStatus(BuildContext context, String? accessType) { - switch (accessType) { - case '0': - return {FFLocalizations.of(context).getVariableText(ptText: 'Entrada', enText: 'Entrance'): FlutterFlowTheme.of(context).success}; - case '1': - return {FFLocalizations.of(context).getVariableText(ptText: 'Saída', enText: 'Exit'): FlutterFlowTheme.of(context).error}; - default: - return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).warning}; - } - } -} \ No newline at end of file diff --git a/lib/features/history/presentation/pages/history_page_template.dart b/lib/features/history/presentation/pages/history_page_template.dart deleted file mode 100644 index 884d6bc9..00000000 --- a/lib/features/history/presentation/pages/history_page_template.dart +++ /dev/null @@ -1,211 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/features/history/index.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/backend/api_requests/api_manager.dart'; -import 'package:hub/features/history/presentation/widgets/filter_modal.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/shared/utils/dialog_util.dart'; -import 'package:hub/shared/utils/log_util.dart'; -import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; - -class HistoryPageTemplate extends StatelessWidget { - final Map opt; - final Future Function(int pageSize, int pageNumber, Map opt) fetchHistoryService; - final Widget Function(BuildContext context, dynamic historyItem) cardBuilder; - final String appBarTitle; - final String noHistoryMessage; - final String errorMessage; - final bool isLeading; - final bool isFilter; - final bool Function(dynamic item, Map opt)? filterLogic; - - const HistoryPageTemplate({ - Key? key, - required this.opt, - required this.fetchHistoryService, - required this.cardBuilder, - this.appBarTitle = 'History', - this.noHistoryMessage = 'No history found!', - this.errorMessage = 'Failed to perform operation!', - this.isLeading = true, - this.isFilter = false, - this.filterLogic, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return BlocProvider( - create: (context) => HistoryBloc(opt, fetchHistoryService, filterLogic: filterLogic), - child: HistoryPageView( - cardBuilder: cardBuilder, - appBarTitle: appBarTitle, - noHistoryMessage: noHistoryMessage, - errorMessage: errorMessage, - isLeading: isLeading, - isFilter: isFilter, - ), - ); - } -} - -class HistoryPageView extends StatelessWidget { - final Widget Function(BuildContext context, dynamic historyItem) cardBuilder; - final String appBarTitle; - final String noHistoryMessage; - final String errorMessage; - final bool isLeading; - final bool isFilter; - - const HistoryPageView({ - Key? key, - required this.cardBuilder, - required this.appBarTitle, - required this.noHistoryMessage, - required this.errorMessage, - this.isLeading = false, - this.isFilter = false, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - final theme = FlutterFlowTheme.of(context); - return Scaffold( - key: GlobalKey(), - backgroundColor: theme.primaryBackground, - appBar: _buildAppBar(context, theme), - body: _buildBody(context), - ); - } - - PreferredSizeWidget _buildAppBar(BuildContext context, FlutterFlowTheme theme) { - return AppBar( - backgroundColor: theme.primaryBackground, - automaticallyImplyLeading: false, - leading: isLeading ? _buildBackButton(context, theme) : null, - title: _buildTitle(context, theme), - centerTitle: true, - elevation: 0.0, - actions: [ - if (isFilter) _buildFilterButton(context), - ], - ); - } - - Widget _buildBackButton(BuildContext context, FlutterFlowTheme theme) { - return FlutterFlowIconButton( - borderColor: Colors.transparent, - borderRadius: 30.0, - borderWidth: 1.0, - buttonSize: 60.0, - icon: Icon( - Icons.keyboard_arrow_left, - color: theme.primaryText, - size: 30.0, - ), - onPressed: () => Navigator.of(context).pop(), - ); - } - - Widget _buildTitle(BuildContext context, FlutterFlowTheme theme) { - return Text( - appBarTitle, - style: theme.headlineMedium.override( - fontFamily: theme.headlineMediumFamily, - color: theme.primaryText, - fontSize: 16.0, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey(theme.headlineMediumFamily), - ), - ); - } - - Widget _buildFilterButton(BuildContext context) { - return Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(0, 0, 10, 0), - child: IconButton( - icon: const Icon(Icons.filter_list), - onPressed: () async { - final Map? selectedFilter = await showModalBottomSheet>( - isScrollControlled: true, - backgroundColor: Colors.transparent, - context: context, - builder: (BuildContext bottomSheetContext) { - return GestureDetector( - onTap: () => Navigator.of(bottomSheetContext).pop(), - child: Container( - color: Colors.transparent, - child: GestureDetector( - onTap: () {}, - child: FilterModalWidget( - defaultSelections: { - 'personType': context.read().state.opt['personType'] == '.*' ? ['E', 'O'] : [context.read().state.opt['personType']], - 'search': '.*', - }, - filterOptions: { - 'personType': [ - {'title': FFLocalizations.of(context).getVariableText(ptText: 'Visitante', enText: 'Visitor'), 'value': 'E',}, - {'title': FFLocalizations.of(context).getVariableText(ptText: 'Morador', enText: 'Resident'), 'value': 'O',}, - - ], - }, - filterTitles: { - 'personType': 'Person Type', - }, - ), - ), - ), - ); - }, - ); - - if (selectedFilter != null) { - context.read().add(UpdateHistoryEvent(selectedFilter)); - } - }, - ), - ), - ], - ); - } - - Widget _buildBody(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - if (state.loading && state.historyWrap.isEmpty) { - return Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - FlutterFlowTheme.of(context).primary, - ), - ), - ); - } else if (state.error != null) { - return Center( - child: Text(errorMessage), - ); - } else if (state.historyWrap.isEmpty) { - return Center( - child: Text(noHistoryMessage), - ); - } else { - return ListView.builder( - shrinkWrap: true, - physics: const BouncingScrollPhysics(), - controller: context.read().scrollController, - itemCount: state.historyWrap.length, - itemBuilder: (context, index) { - final historyItem = state.historyWrap[index]; - return cardBuilder(context, historyItem); - }, - ); - } - }, - ); - } -} \ No newline at end of file diff --git a/lib/features/history/presentation/pages/index.dart b/lib/features/history/presentation/pages/index.dart deleted file mode 100644 index 5b174ec8..00000000 --- a/lib/features/history/presentation/pages/index.dart +++ /dev/null @@ -1,2 +0,0 @@ -export 'history_page_template.dart'; -export 'provisional_history_page.dart'; diff --git a/lib/features/history/presentation/pages/provisional_history_page.dart b/lib/features/history/presentation/pages/provisional_history_page.dart deleted file mode 100644 index 70220c77..00000000 --- a/lib/features/history/presentation/pages/provisional_history_page.dart +++ /dev/null @@ -1,105 +0,0 @@ -import 'dart:developer'; - -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hub/backend/api_requests/api_calls.dart'; -import 'package:hub/components/molecular_components/message_opt_modal/opt_modal_widget.dart'; -import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; -import 'package:hub/features/history/index.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/internationalization.dart'; -import 'package:hub/shared/helpers/storage/base_storage.dart'; -import 'package:hub/shared/helpers/storage/storage_helper.dart'; - -class ProvisionalCubit extends Cubit { - ProvisionalCubit() : super('Provisional'); - - Future fetchCliUUID() async { - final cliUUID = await StorageHelper().get(KeychainStorageKey.clientUUID.value); - emit(cliUUID); - } - - Future fetchHistoryService(int pageSize, int pageNumber, Map status) async { - return await PhpGroup.getProvSchedules(pageNumber.toString()); - } - - bool filterLogic(dynamic item, Map opt) { - final personTypeMatches = opt['personType'] == '.*' || item["PES_TIPO"].toString() == opt['personType']; - return personTypeMatches; - } -} - -class ProvisionalHistoryPage extends StatelessWidget { - final Map opt = { - 'personType': '.*', - 'accessType': '.*', - 'search': '.*', - }; - - final String appBarTitle = 'Histórico Provisório'; - final String noHistoryMessage = 'Nenhum histórico encontrado!'; - final String errorMessage = 'Falha ao realizar operação!'; - - @override - Widget build(BuildContext context) { - return BlocProvider( - create: (context) => ProvisionalCubit()..fetchCliUUID(), - child: HistoryPageTemplate( - opt: opt, - fetchHistoryService: (pageSize, pageNumber, opt) => context.read().fetchHistoryService(pageSize, pageNumber, opt), - cardBuilder: cardBuilder, - appBarTitle: appBarTitle, - noHistoryMessage: noHistoryMessage, - errorMessage: errorMessage, - isLeading: true, - isFilter: false, - filterLogic: null, - ), - ); - } - - Widget cardBuilder(BuildContext context, dynamic historyItem) { - log('historyItem: $historyItem'); - final cliUUID = context.watch().state; - final String imagePath = 'https://freaccess.com.br/freaccess/getImage.php?cliID=${cliUUID}&atividade=getFoto&Documento=${historyItem['PES_ID'] ?? ''}&tipo=${historyItem['PES_TIPO'] ?? ''}'; - final Map labelsHashMap = { - FFLocalizations.of(context).getVariableText(ptText: 'Nome:', enText: 'Name:'): historyItem['PES_NOME'] ?? '', - FFLocalizations.of(context).getVariableText(ptText: 'Acesso:', enText: 'Access:'): historyItem['ACE_DATAHORA'] ?? '', - FFLocalizations.of(context).getVariableText(ptText: 'Setor', enText: 'Sector'): historyItem['SET_DESCRICAO'] ?? '', - }; - - final statusHashMap = [ - _getPersonTypeStatus(context, historyItem['PES_TIPO']), - _getAccessTypeStatus(context, historyItem['ACE_TIPO']), - ]; - - return CardItemTemplateComponentWidget( - imagePath: imagePath, - labelsHashMap: labelsHashMap, - statusHashMap: statusHashMap, - onTapCardItemAction: () async {}, - ); - } - - Map _getPersonTypeStatus(BuildContext context, String? personType) { - switch (personType) { - case 'O': - return {FFLocalizations.of(context).getVariableText(ptText: 'Morador', enText: 'Resident'): FlutterFlowTheme.of(context).alternate2}; - case 'E': - return {FFLocalizations.of(context).getVariableText(ptText: 'Visitante', enText: 'Visitor'): FlutterFlowTheme.of(context).alternate2}; - default: - return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).alternate2}; - } - } - - Map _getAccessTypeStatus(BuildContext context, String? accessType) { - switch (accessType) { - case '0': - return {FFLocalizations.of(context).getVariableText(ptText: 'Entrada', enText: 'Entrance'): FlutterFlowTheme.of(context).success}; - case '1': - return {FFLocalizations.of(context).getVariableText(ptText: 'Saída', enText: 'Exit'): FlutterFlowTheme.of(context).error}; - default: - return {FFLocalizations.of(context).getVariableText(ptText: 'Desconhecido', enText: 'Unknown'): FlutterFlowTheme.of(context).warning}; - } - } -} \ No newline at end of file diff --git a/lib/features/history/presentation/widgets/filter_modal.dart b/lib/features/history/presentation/widgets/filter_modal.dart deleted file mode 100644 index c44a545b..00000000 --- a/lib/features/history/presentation/widgets/filter_modal.dart +++ /dev/null @@ -1,229 +0,0 @@ -import 'package:flutter/material.dart'; - -import '/flutter_flow/flutter_flow_util.dart'; -import '/flutter_flow/form_field_controller.dart'; -import 'package:google_fonts/google_fonts.dart'; -import 'package:hub/flutter_flow/flutter_flow_theme.dart'; -import 'package:hub/flutter_flow/nav/nav.dart'; -import 'package:hub/shared/utils/limited_text_size.dart'; - - - -class FilterModal extends FlutterFlowModel { - FocusNode? textFieldFocusNode; - TextEditingController? textController; - String? Function(BuildContext, String?)? textControllerValidator; - bool? checkboxValue1; - bool? checkboxValue2; - FormFieldController>? checkboxGroupValueController; - List? get checkboxGroupValues => checkboxGroupValueController?.value; - set checkboxGroupValues(List? v) => checkboxGroupValueController?.value = v; - - @override - void initState(BuildContext context) {} - - @override - void dispose() { - textFieldFocusNode?.dispose(); - textController?.dispose(); - } -} - -class FilterModalWidget extends StatefulWidget { - final Map defaultSelections; - final Map>> filterOptions; - final Map filterTitles; - - const FilterModalWidget({ - super.key, - required this.defaultSelections, - required this.filterOptions, - required this.filterTitles, - }); - - @override - _FilterModalWidgetState createState() => _FilterModalWidgetState(); -} - -class _FilterModalWidgetState extends State { - late FilterModal _model; - late Map selected; - - @override - void setState(VoidCallback callback) { - super.setState(callback); - _model.onUpdate(); - } - - @override - void initState() { - super.initState(); - - _model = createModel(context, () => FilterModal()); - - _model.textController ??= TextEditingController(); - _model.textFieldFocusNode ??= FocusNode(); - - selected = widget.defaultSelections; - } - - void _applyFilter() { - Map filterResult = { - 'search': _model.textController?.text == '' ? '.*' : _model.textController!.text.toLowerCase(), - }; - - widget.filterOptions.forEach((key, options) { - filterResult[key] = selected[key]!.isEmpty || selected[key]!.length > 1 - ? '.*' - : selected[key]!.first; - }); - - context.pop(filterResult); - } - - Widget _buildCheckboxListTile(String key, List> options, double fontsize) { - double limitedInputFontSize = LimitedFontSizeUtil.getInputFontSize(context); - return Column( - children: [ - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(0.0, 3.0, 0.0, 0.0), - child: Text( - widget.filterTitles[key]!, - textAlign: TextAlign.left, - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, - fontSize: limitedInputFontSize, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).bodyMediumFamily), - color: FlutterFlowTheme.of(context).primaryText, - ), - ), - ), - ], - ), - ListView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemCount: options.length, - itemBuilder: (context, index) { - final option = options[index]; - return CheckboxListTile( - title: Text( - option['title']!, - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, - letterSpacing: 0.0, - fontSize: limitedInputFontSize, - useGoogleFonts: GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).bodyMediumFamily), - color: FlutterFlowTheme.of(context).primaryText, - ), - ), - dense: true, - value: selected[key]!.contains(option['value']), - onChanged: (bool? value) { - setState(() { - if (value == true) { - if (!selected[key]!.contains(option['value'])) { - selected[key]!.add(option['value']); - } - } else { - selected[key]!.remove(option['value']); - } - }); - }, - activeColor: FlutterFlowTheme.of(context).primary, - checkColor: FlutterFlowTheme.of(context).info, - checkboxShape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100), - ), - enableFeedback: true, - side: BorderSide( - width: 5, - color: FlutterFlowTheme.of(context).secondaryText, - ), - controlAffinity: ListTileControlAffinity.leading, - ); - }, - ), - ], - ); - } - - @override - Widget build(BuildContext context) { - double screenWidth = MediaQuery.of(context).size.width; - - return Center( - child: Container( - width: screenWidth - (screenWidth * 0.35), - height: 250, - decoration: BoxDecoration( - color: FlutterFlowTheme.of(context).primaryBackground, - borderRadius: BorderRadius.circular(24.0), - ), - child: Padding( - padding: const EdgeInsets.all(4.0), - child: Column( - children: [ - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(10.0, 10.0, 0.0, 10.0), - child: Text( - FFLocalizations.of(context).getText('yfj9pd6k'), - style: FlutterFlowTheme.of(context).headlineMedium.override( - fontFamily: FlutterFlowTheme.of(context).headlineMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - fontSize: LimitedFontSizeUtil.getHeaderFontSize(context), - letterSpacing: 0.0, - fontWeight: FontWeight.bold, - useGoogleFonts: - GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).headlineMediumFamily), - ), - ), - ), - ], - ), - Expanded( - child: SingleChildScrollView( - child: Container( - padding: const EdgeInsets.all(10), - child: Column( - mainAxisSize: MainAxisSize.min, - children: widget.filterOptions.keys.map((key) { - return _buildCheckboxListTile(key, widget.filterOptions[key]!, 14); - }).toList(), - ), - ), - ), - ), - ElevatedButton( - onPressed: _applyFilter, - style: ElevatedButton.styleFrom( - foregroundColor: FlutterFlowTheme.of(context).info, - backgroundColor: FlutterFlowTheme.of(context).primary, - ), - child: Text(FFLocalizations.of(context).getText('88kshkph'), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, - color: FlutterFlowTheme.of(context).info, - fontSize: LimitedFontSizeUtil.getInputFontSize(context), - letterSpacing: 0.0, - fontWeight: FontWeight.bold, - useGoogleFonts: - GoogleFonts.asMap().containsKey(FlutterFlowTheme.of(context).bodyMediumFamily), - )), - ), - ], - ), - ), - ), - ); - } -} diff --git a/lib/features/history/presentation/widgets/index.dart b/lib/features/history/presentation/widgets/index.dart deleted file mode 100644 index 2191ab0c..00000000 --- a/lib/features/history/presentation/widgets/index.dart +++ /dev/null @@ -1 +0,0 @@ -export 'filter_modal.dart'; diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index d07173be..a62e5d2a 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:hub/backend/schema/util/schema_util.dart'; -import 'package:hub/features/history/presentation/pages/provisional_history_page.dart'; import 'package:hub/features/home/index.dart'; import 'package:hub/features/property/index.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; @@ -131,7 +130,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { FFRoute(name: 'petsOnThePropertyPage', path: '/petsOnThePropertyPage', builder: (context, params) => Scaffold(body: const PetsHistoryScreen(isApp: true))), FFRoute(name: 'vehiclesOnThePropertyPage', path: '/vehiclesOnThePropertyPage', builder: (context, params) => const VehicleOnTheProperty()), FFRoute(name: 'receptionPage', path: '/receptionPage', builder: (context, params) => const ReceptionPageWidget()), - FFRoute(name: 'messageHistoryPage', path: '/messageHistoryPage', builder: (context, params) => ProvisionalHistoryPage()), + FFRoute(name: 'messageHistoryPage', path: '/messageHistoryPage', builder: (context, params) => const MessageHistoryPageWidget()), FFRoute(name: 'registerVisitorPage', path: '/registerVisitorPage', builder: (context, params) => const RegisterVisitorPageWidget()), FFRoute(name: 'scheduleCompleteVisitPage', path: '/scheduleCompleteVisitPage', builder: (context, params) => const ScheduleCompleteVisitPageWidget()), FFRoute(name: 'deliverySchedule', path: '/deliverySchedule', builder: (context, params) => const DeliverySchedule()), From d787f8e89c19c356165c4884fb4c0ba9eba3316d Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 15:04:21 -0300 Subject: [PATCH 65/75] fix: homeBloc state managment --- .../home/presentation/blocs/home_bloc.dart | 40 ++++++++++++------- .../local_profile/local_profile_widget.dart | 4 +- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/features/home/presentation/blocs/home_bloc.dart b/lib/features/home/presentation/blocs/home_bloc.dart index 0df86d3b..5829df5f 100644 --- a/lib/features/home/presentation/blocs/home_bloc.dart +++ b/lib/features/home/presentation/blocs/home_bloc.dart @@ -1,26 +1,38 @@ +import 'dart:async'; + import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; +import '../../../../shared/components/molecules/locals/index.dart'; import 'index.dart'; class HomeBloc extends Bloc { + late StreamSubscription _completer; + HomeBloc() : super(HomeState()) { - on((event, emit) async { - final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; - final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; - final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; - final userName = (await StorageHelper().get(KeychainStorageKey.userName.value)) ?? ''; - final userEmail = (await StorageHelper().get(SecureStorageKey.email.value)) ?? ''; - - emit(state.copyWith( - devUUID: devUUID, - userUUID: userUUID, - cliUUID: cliUUID, - userName: userName, - userEmail: userEmail, - )); + on(_onHomeEvent); + _completer = LocalsRepositoryImpl.license.stream.listen((v) { + add(HomeEvent()); }); + } + + Future _onHomeEvent(HomeEvent event, Emitter emit) async { + final devUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value)) ?? ''; + final userUUID = (await StorageHelper().get(KeychainStorageKey.userUUID.value)) ?? ''; + final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + final userName = (await StorageHelper().get(KeychainStorageKey.userName.value)) ?? ''; + final userEmail = (await StorageHelper().get(SecureStorageKey.email.value)) ?? ''; + + emit(state.copyWith( + devUUID: devUUID, + userUUID: userUUID, + cliUUID: cliUUID, + userName: userName, + userEmail: userEmail, + )); } } + + diff --git a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart index 83760caa..77994112 100644 --- a/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart +++ b/lib/shared/components/molecules/locals/presentation/widgets/local_profile/local_profile_widget.dart @@ -52,9 +52,7 @@ class _LocalProfileComponentWidgetState extends State( builder: (context, state) { From c73add16958aab256609535e0d7219ffe3d0e8a7 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 15:26:50 -0300 Subject: [PATCH 66/75] Desenvincular local com somente um local disponivel --- .../locals/data/data_sources/locals_local_data_source.dart | 1 - .../locals/data/data_sources/locals_remote_data_source.dart | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart index e8718025..439b1ef1 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart @@ -10,7 +10,6 @@ class LocalsLocalDataSourceImpl { Future unlinkLocal() async { await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); - await StorageHelper().set(KeychainStorageKey.ownerUUID.value, ''); await StorageHelper().set(KeychainStorageKey.clientName.value, ''); await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); } diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index ea9fa7a9..284c88aa 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -109,7 +109,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { AuthenticationService.signOut(context); return true; } else if (isUnavailable) { - return await LocalUtil.handleUnavailable(context, locals); + return await selectLocal(context, response); } else if (isEnabled) { return await LocalUtil.handleEnabled(context, locals[0]); } else if (isUnselected) { From eec6df095180f07ba33b989569725a43c7e05524 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 08:21:01 -0300 Subject: [PATCH 67/75] =?UTF-8?q?atualizar=20profile=20no=20drawer=20e=20v?= =?UTF-8?q?izualizar=20modal=20de=20sele=C3=A7=C3=A3o=20ap=C3=B3s=20desvin?= =?UTF-8?q?cular=20local?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 1 + .../data/data_sources/locals_remote_data_source.dart | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 9b72ba47..7ada3253 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -220,4 +220,5 @@ class _AppState extends State { ), ); } + } diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index 284c88aa..2b43583e 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -215,16 +215,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); context.pop(); - context.go( - '/homePage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); + context.go('/homePage', extra: {'update': LocalsRepositoryImpl().update}); SnackBarUtil.showSnackBar(context, content); } }).catchError((err, stack) { From bc0ef37a6048c848105685f1dc436255ebc1b28f Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 08:28:01 -0300 Subject: [PATCH 68/75] =?UTF-8?q?fix:=20exibir=20modal=20de=20sele=C3=A7?= =?UTF-8?q?=C3=A3o=20ao=20reabrir=20o=20app=20sem=20local=20vinculado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/features/home/presentation/pages/home_page.dart | 5 +---- lib/flutter_flow/nav/nav.dart | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 066d994f..350ae9a2 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -12,10 +12,7 @@ import 'package:hub/shared/components/molecules/menu/index.dart'; class HomePageWidget extends StatefulWidget { - const HomePageWidget({ - super.key, - this.update, - }); + const HomePageWidget(this.update, {super.key}); final Future Function(BuildContext context)? update; @override diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index a62e5d2a..25209384 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -31,6 +31,7 @@ import 'package:hub/pages/sign_up_page/sign_up_page_widget.dart'; import 'package:hub/pages/vehicles_on_the_property/vehicles_on_the_property.dart'; import 'package:hub/pages/visits_on_the_property/visits_on_the_property_screen.dart'; import 'package:hub/pages/welcome_page/welcome_page_widget.dart'; +import 'package:hub/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart'; import 'package:hub/shared/helpers/storage/base_storage.dart'; import 'package:hub/shared/helpers/storage/storage_helper.dart'; import 'package:hub/shared/utils/dialog_util.dart'; @@ -91,7 +92,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { final bool haveDevUUID = (await StorageHelper().get(KeychainStorageKey.devUUID.value))?.isNotEmpty ?? false; if (isLogged && haveDevUUID && haveUserUUID) { - return haveLocal ? const HomePageWidget() : const ReceptionPageWidget(); + return haveLocal ? HomePageWidget(LocalsRepositoryImpl().update) : const ReceptionPageWidget(); } else { return const WelcomePageWidget(); } @@ -124,7 +125,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { }), FFRoute(name: 'homePage', path: '/homePage', builder: (context, params) { final Future Function(BuildContext context)? update = params.getParam('update', ParamType.Function); - return HomePageWidget(key: UniqueKey(), update: update); + return HomePageWidget(key: UniqueKey(), update); }), FFRoute(name: 'petsOnThePropertyPage', path: '/petsOnThePropertyPage', builder: (context, params) => Scaffold(body: const PetsHistoryScreen(isApp: true))), From ab19c7f2318c70f721e24d90e87deda589010167 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 09:26:00 -0300 Subject: [PATCH 69/75] check cache locals in update locals --- .../locals_remote_data_source.dart | 14 ++++++++--- .../repositories/locals_repository_impl.dart | 23 +++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart index 2b43583e..2520b990 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_remote_data_source.dart @@ -18,11 +18,12 @@ import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/snackbar_util.dart'; abstract class LocalsRemoteDataSource { - Future checkLocals(BuildContext context); + Future linkLocal(BuildContext context); + Future checkLocals(BuildContext context); Future processLocals(BuildContext context) ; Future processData(BuildContext context); Future selectLocal(BuildContext context, ApiCallResponse? response) ; - Future detachLocal(BuildContext context) ; + Future detachLocal(BuildContext context); } class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { @@ -31,7 +32,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { LocalsRemoteDataSourceImpl._internal(); @override - Future checkLocals(BuildContext context) async { + Future linkLocal(BuildContext context) async { try { final GetLocalsCall callback = PhpGroup.getLocalsCall; var response = await callback.call(); @@ -142,6 +143,13 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { } } + @override + Future checkLocals(BuildContext context) async { + String cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; + String cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; + return cliUUID.isEmpty && cliName.isEmpty; + } + @override Future processData(BuildContext context) async { try { diff --git a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart index 93a8aa27..51c48596 100644 --- a/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart +++ b/lib/shared/components/molecules/locals/data/repositories/locals_repository_impl.dart @@ -20,7 +20,7 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future validateLocal(BuildContext context) async { - return await remoteDataSource.checkLocals(context); + return await remoteDataSource.linkLocal(context); } @override @@ -49,17 +49,22 @@ class LocalsRepositoryImpl implements LocalsRepository { Future _handleReponse(BuildContext context) async { bool response = false; - while (!response) { - try { - response = await remoteDataSource.processLocals(context); - if (!response) { - await _handleUpdateError(context); - } - } catch (e , s) { + final bool isUnselected = await remoteDataSource.checkLocals(context); + if (isUnselected) { + while (!response) { + try { + response = await remoteDataSource.processLocals(context); + if (!response) { + await _handleUpdateError(context); + } + } catch (e, s) { log('Error updating locals: $e', stackTrace: s); await _handleUpdateError(context); } - } + } + } else { + return true; + } return response; } From e0a67e5d1e2a655cbdf1ffb3f81bad99794985b5 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 09:34:56 -0300 Subject: [PATCH 70/75] WIP --- .../locals/data/data_sources/locals_local_data_source.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart index 439b1ef1..64d78e27 100644 --- a/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart +++ b/lib/shared/components/molecules/locals/data/data_sources/locals_local_data_source.dart @@ -9,7 +9,6 @@ class LocalsLocalDataSourceImpl { Future unlinkLocal() async { await StorageHelper().set(KeychainStorageKey.clientUUID.value, ''); - await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); await StorageHelper().set(KeychainStorageKey.clientName.value, ''); await StorageHelper().set(KeychainStorageKey.ownerName.value, ''); } From 546f84a009e3308fd8911ddafb723479bb34e6f1 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 10:15:57 -0300 Subject: [PATCH 71/75] fix: timeout in GetLocals.. --- lib/backend/api_requests/api_calls.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index aea6aa68..ab81afc1 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -953,7 +953,7 @@ class GetLocalsCall { cache: false, isStreamingApi: false, alwaysAllowBody: false, - ); + ).timeout(const Duration(seconds: 30)); } List? locais(dynamic response) => getJsonField( From 7a34785655a89efb86e0343322276e5c50d0993e Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 10:18:41 -0300 Subject: [PATCH 72/75] fix timeout --- lib/backend/api_requests/api_calls.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index ab81afc1..1b9a9a9f 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -953,7 +953,7 @@ class GetLocalsCall { cache: false, isStreamingApi: false, alwaysAllowBody: false, - ).timeout(const Duration(seconds: 30)); + ); } List? locais(dynamic response) => getJsonField( @@ -1380,7 +1380,7 @@ class GetDadosCall { cache: false, isStreamingApi: false, alwaysAllowBody: false, - ); + ).timeout(const Duration(seconds: 30)); } bool? errorBolean(dynamic response) => castToType(getJsonField( From ea18bee7c59187fb2c3329fcb4e26f020624909c Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 10:24:01 -0300 Subject: [PATCH 73/75] =?UTF-8?q?debit:=20nome=20da=20propriedade=20nas=20?= =?UTF-8?q?telas=20de=20agendamento=20provis=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../provisional_schedule_template_model.dart | 5 ++--- .../provisional_shcedule_template_widget.dart | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) 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 8ec62766..95937bac 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 @@ -11,7 +11,7 @@ class ScheduleProvisionalVisitPageModel extends FlutterFlowModel Date: Mon, 9 Dec 2024 16:25:32 -0300 Subject: [PATCH 74/75] fix: status da visitas em aberto --- lib/pages/visits_on_the_property/model.dart | 19 +++++++++++-------- .../visits_on_the_property_screen.dart | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/pages/visits_on_the_property/model.dart b/lib/pages/visits_on_the_property/model.dart index 9870b4bb..8a317179 100644 --- a/lib/pages/visits_on_the_property/model.dart +++ b/lib/pages/visits_on_the_property/model.dart @@ -75,13 +75,16 @@ class VisitsModel extends FlutterFlowModel { imagePath: 'https://freaccess.com.br/freaccess/getImage.php?devUUID=${devUUID}&cliID=${cliUUID}&atividade=getFoto&Documento=${item['VDO_DOCUMENTO']}&tipo=E', statusHashMap: [ - if (item['VTA_FIXA'] != null) - Map.from({ - item['VTA_FIXA'] - ? FFLocalizations.of(context).getVariableText(ptText: "Entrada Única", enText: "Single Entry") - : FFLocalizations.of(context).getVariableText( - ptText: "Entrada Recorrente", enText: "Recurrent Entry"): FlutterFlowTheme.of(context).warning - }), - ]); + Map.from({ + if (item['VTA_FIXA'] != null) + FFLocalizations.of(context).getVariableText( + ptText: item['VTA_FIXA'] ? "Entrada Única" : "Entrada Recorrente", + enText: item['VTA_FIXA'] ? "Single Entry" : "Recurrent Entry", + ): item['VTA_FIXA'] == true + ? FlutterFlowTheme.of(context).success + : FlutterFlowTheme.of(context).warning, + }) + ], + ); } } diff --git a/lib/pages/visits_on_the_property/visits_on_the_property_screen.dart b/lib/pages/visits_on_the_property/visits_on_the_property_screen.dart index b4a283eb..ddc81d31 100644 --- a/lib/pages/visits_on_the_property/visits_on_the_property_screen.dart +++ b/lib/pages/visits_on_the_property/visits_on_the_property_screen.dart @@ -232,14 +232,14 @@ class _VisitsOnThePropertyState extends State with TickerPr uItem['MOT_DESCRICAO'][0].toUpperCase() + uItem['MOT_DESCRICAO'].substring(1).toLowerCase(), }, statusHashMap: [ - if (uItem['VTA_FIXA'] == true) + if (uItem['VTA_FIXA'] == false) { FFLocalizations.of(context).getVariableText( ptText: 'Recorrente', enText: 'Recurrent', ): FlutterFlowTheme.of(context).warning, }, - if (uItem['VTA_FIXA'] == false) + if (uItem['VTA_FIXA'] == true) { FFLocalizations.of(context).getVariableText( ptText: 'Única', From 4e46edba867d1630e3eb3495787349702c6aeffe Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Mon, 9 Dec 2024 17:33:22 -0300 Subject: [PATCH 75/75] debit: nome do visitante no detalhe da visita em aberto --- lib/pages/visits_on_the_property/model.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/pages/visits_on_the_property/model.dart b/lib/pages/visits_on_the_property/model.dart index 8a317179..357ab6dd 100644 --- a/lib/pages/visits_on_the_property/model.dart +++ b/lib/pages/visits_on_the_property/model.dart @@ -43,6 +43,11 @@ class VisitsModel extends FlutterFlowModel { return DetailsComponentWidget( buttons: [], labelsHashMap: Map.from({ + if (item['VTA_NOME'] != null && item['VTA_NOME'] != '') + '${FFLocalizations.of(context).getVariableText( + ptText: "Nome", + enText: "Name", + )}:': item['VTA_NOME'].toString().toUpperCase(), if (item['MOT_DESCRICAO'] != null && item['MOT_DESCRICAO'] != '') '${FFLocalizations.of(context).getVariableText( ptText: "Motivo",