From 66302358b9e74f1795189d3a9482cafeea0bb063 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 20 Dec 2024 11:46:04 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20atualiza=20o=20getDados=20ao=20entrar=20?= =?UTF-8?q?na=20tela=20de=20op=C3=A7=C3=B5es=20e=20refatora=20o=20processD?= =?UTF-8?q?ata=20do=20LocalsRemoteDataSource=20para=20somente=20processar?= =?UTF-8?q?=20a=20propriedade=20(Single=20Responsability)=20(antes=20o=20p?= =?UTF-8?q?roprio=20m=C3=A9todo=20chamava=20para=20atualizar=20licen=C3=A7?= =?UTF-8?q?a).=20E=20como=20isso=20precisei=20fazer=20com=20que=20ele=20re?= =?UTF-8?q?torna-se=20true=20e=20que=20chama=20processa=20propriedade=20ca?= =?UTF-8?q?so=20retorne=20true=20chame=20processa=20licen=C3=A7a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/presentation/pages/about_system.dart | 4 ++-- .../locals_remote_data_source.dart | 21 +++++++++++----- .../repositories/locals_repository_impl.dart | 24 +++++++++++++++++-- .../respositories/locals_repository.dart | 1 + lib/features/local/utils/local_util.dart | 4 ++-- .../preferences_settings_model.dart | 1 + .../preferences_settings_widget.dart | 1 - 7 files changed, 43 insertions(+), 13 deletions(-) diff --git a/lib/features/home/presentation/pages/about_system.dart b/lib/features/home/presentation/pages/about_system.dart index 26fb1b72..388a464a 100644 --- a/lib/features/home/presentation/pages/about_system.dart +++ b/lib/features/home/presentation/pages/about_system.dart @@ -124,8 +124,8 @@ class _AboutSystemPageState extends State { Widget _buildLogo() { return SizedBox( - height: 50, - width: 50, + height: 100, + width: 100, child: Image.asset('assets/images/fre.png'), ); } diff --git a/lib/features/local/data/data_sources/locals_remote_data_source.dart b/lib/features/local/data/data_sources/locals_remote_data_source.dart index bf4b710b..fd91b648 100644 --- a/lib/features/local/data/data_sources/locals_remote_data_source.dart +++ b/lib/features/local/data/data_sources/locals_remote_data_source.dart @@ -18,7 +18,7 @@ abstract class LocalsRemoteDataSource { Future linkLocal(BuildContext context); Future checkLocals(BuildContext context); Future processLocals(BuildContext context); - Future processData(BuildContext context); + Future processProperty(BuildContext context); Future selectLocal(BuildContext context, ApiCallResponse? response); Future detachLocal(BuildContext context); } @@ -118,10 +118,16 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { return await selectLocal(context, response); } else if (isSelected) { log('() => isSelected'); - return await processData(context); + return await processProperty(context).then((v) async { + if (v == true) return await LicenseRepositoryImpl().updateLicense(); + return v; + }); } else if (isAvailable) { log('() => isAvailable'); - return await processData(context); + return await processProperty(context).then((v) async { + if (v == true) return await LicenseRepositoryImpl().updateLicense(); + return v; + }); } else { if (!isUnique && !isActive) log('() => not unique and not active'); if (!isUnique && isInactived) log('() => not unique and inactived'); @@ -153,7 +159,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { } @override - Future processData(BuildContext context) async { + Future processProperty(BuildContext context) async { try { final GetDadosCall callback = PhpGroup.getDadosCall; ApiCallResponse? response = await callback.call(); @@ -178,7 +184,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { return false; } else { await LocalUtil.updateStorageUtil(response.jsonBody); - return await LicenseRepositoryImpl().updateLicense(); + return true; } } catch (e, s) { log('() => error processData: $e', stackTrace: s); @@ -209,7 +215,10 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource { child: BottomArrowLinkedLocalsComponentWidget(response: response), ), ), - ).then((_) async => await processData(context)); + ).then((_) async => await processProperty(context).then((v) async { + if (v == true) return await LicenseRepositoryImpl().updateLicense(); + return v; + })); } @override diff --git a/lib/features/local/data/repositories/locals_repository_impl.dart b/lib/features/local/data/repositories/locals_repository_impl.dart index 37b49a95..232e511e 100644 --- a/lib/features/local/data/repositories/locals_repository_impl.dart +++ b/lib/features/local/data/repositories/locals_repository_impl.dart @@ -27,11 +27,16 @@ class LocalsRepositoryImpl implements LocalsRepository { @override Future update(BuildContext context) async { LocalsRepositoryImpl.license.add(false); - final bool response = await _handleReponse(context); + final bool response = await _handleLocal(context); LocalsRepositoryImpl.license.add(response); return response; } + @override + Future fetch(BuildContext context) async { + return await _handleProperty(context); + } + Future select(BuildContext context) async { await unselect(); await update(context); @@ -56,7 +61,7 @@ class LocalsRepositoryImpl implements LocalsRepository { } } - Future _handleReponse(BuildContext context) async { + Future _handleLocal(BuildContext context) async { bool response = false; final bool isUnselected = await remoteDataSource.checkLocals(context); if (isUnselected) { @@ -74,6 +79,21 @@ class LocalsRepositoryImpl implements LocalsRepository { } else { return true; } + + return response; + } + + Future _handleProperty(BuildContext context) async { + bool response = false; + try { + response = await remoteDataSource.processProperty(context); + if (!response) { + await _handleUpdateError(context); + } + } catch (e, s) { + log('Error updating locals: $e', stackTrace: s); + await _handleUpdateError(context); + } return response; } diff --git a/lib/features/local/domain/respositories/locals_repository.dart b/lib/features/local/domain/respositories/locals_repository.dart index 1862d79c..6e4dcd97 100644 --- a/lib/features/local/domain/respositories/locals_repository.dart +++ b/lib/features/local/domain/respositories/locals_repository.dart @@ -4,4 +4,5 @@ abstract class LocalsRepository { Future validateLocal(BuildContext context) async {} Future update(BuildContext context) async => false; Future unlinkLocal(BuildContext context) async {} + Future fetch(BuildContext context) async {} } diff --git a/lib/features/local/utils/local_util.dart b/lib/features/local/utils/local_util.dart index 0338315e..32541690 100644 --- a/lib/features/local/utils/local_util.dart +++ b/lib/features/local/utils/local_util.dart @@ -63,7 +63,7 @@ class LocalUtil { } if (response.jsonBody['error'] == false) return await LocalsRemoteDataSourceImpl() - .processData(context) + .processProperty(context) .then((value) => value); } catch (e, s) { await DialogUtil.errorDefault(context); @@ -86,7 +86,7 @@ class LocalUtil { .set(ProfileStorageKey.ownerName.key, local['CLU_OWNER_DSC']); await StorageHelper() .set(ProfileStorageKey.userName.key, local['USU_NOME']); - return await LocalsRemoteDataSourceImpl().processData(context); + return await LocalsRemoteDataSourceImpl().processProperty(context); } static void logLocalsStatus(List locals) { diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index e3be441a..5e05a735 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -22,6 +22,7 @@ class PreferencesPageModel with ChangeNotifier { late bool isPanic = false; Future _initialize() async { + await LocalsRepositoryImpl().fetch(navigatorKey.currentContext!); isFingerprint = await StorageHelper().get(LocalsStorageKey.fingerprint.key) == 'true'; isPerson = await StorageHelper().get(LocalsStorageKey.person.key) == 'true'; diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index a8da0d72..06c1d96b 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -22,7 +22,6 @@ class _PreferencesPageWidgetState extends State { @override void initState() { super.initState(); - LocalsRepositoryImpl().update(context); } @override