From eb093299d20dcabb6ceec1b0ae06c70adc40f572 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 16:20:29 -0300 Subject: [PATCH] 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; }