From eae3792abe8dbaa64f6a259d59357b3e7b062059 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 6 Dec 2024 14:42:08 -0300 Subject: [PATCH] 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); }