fix: forever CircularLoadingIndicator

This commit is contained in:
J. A. Messias 2024-12-04 16:20:29 -03:00
parent 7f05d85aa3
commit eb093299d2
10 changed files with 31 additions and 5 deletions

View File

@ -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';

View File

@ -43,7 +43,8 @@ class _HomePageWidgetState extends State<HomePageWidget> {
],
child: Builder(
builder: (context) {
context.read<LocalProfileBloc>().updateProfile(context);
LocalsRepositoryImpl.license.add(true);
// context.read<LocalProfileBloc>().updateProfile(context);
return Scaffold(
key: scaffoldKey,
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,

View File

@ -70,6 +70,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
@override
Future<bool> processLocals(BuildContext context) async {
log('() => processLocals');
try {
final GetLocalsCall callback = PhpGroup.getLocalsCall;
final ApiCallResponse response = await callback.call();

View File

@ -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<bool> update(BuildContext context) async {
log('update');
LocalsRepositoryImpl.license.add(false);
final bool response = await remoteDataSource.processLocals(context);
context.read<LocalProfileBloc>().add(LocalProfileEvent());

View File

@ -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<LocalProfileEvent, LocalProfileState> {
}
Future<void> _onLocalProfileEvent(LocalProfileEvent event, Emitter<LocalProfileState> 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<MenuBloc>().add(MenuEvent());
add(LocalProfileEvent());
LocalsRepositoryImpl.license.add(true);
}
}

View File

@ -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<LocalProfileComponentWidge
final double scaledFontSize = baseFontSize * textScaler.scale(1);
final double limitedFontSize = scaledFontSize > 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<LocalProfileBloc, LocalProfileState>(
builder: (context, state) {
return _buildDefaultLocalProfile(context, limitedFontSize);

View File

@ -19,6 +19,7 @@ class MenuRepositoryImpl implements MenuRepository {
List<MenuItem?> 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);

View File

@ -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<MenuEvent, MenuState> {
}
Future<void> _onMenuEvent(MenuEvent event, Emitter<MenuState> emit) async {
log('MenuBloc: waitForSaveCompletion');
await LicenseRemoteDataSourceImpl().waitForSaveCompletion();
log('MenuBloc: _onMenuEvent');
final List<MenuItem?> NewEntries = await MenuRepositoryImpl().generateMenuEntries(entries, item);
emit(state.copyWith(menuEntries: NewEntries));
}

View File

@ -19,6 +19,7 @@ class LicenseRepositoryImpl implements LicenseRepository {
@override
Future<bool> 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<String?> getLicense(String key) async {
return await localDataSource.get(key);
final response = await localDataSource.get(key);
log('getLicense: $key: $response');
return response;
}
@override

View File

@ -32,7 +32,7 @@ class DatabaseStorage {
onUpgrade: _onUpgrade,
onDowngrade: _onDowngrade,
);
// await LicenseRepositoryImpl().updateLicense();
await LicenseRepositoryImpl().updateLicense();
isInitialized = true;
}