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:flutter_bloc/flutter_bloc.dart';
import 'package:hub/shared/helpers/storage/base_storage.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/storage_helper.dart';

View File

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

View File

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

View File

@ -1,3 +1,5 @@
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hub/shared/components/molecules/locals/index.dart'; import 'package:hub/shared/components/molecules/locals/index.dart';
@ -17,6 +19,7 @@ class LocalsRepositoryImpl implements LocalsRepository {
@override @override
Future<bool> update(BuildContext context) async { Future<bool> update(BuildContext context) async {
log('update');
LocalsRepositoryImpl.license.add(false); LocalsRepositoryImpl.license.add(false);
final bool response = await remoteDataSource.processLocals(context); final bool response = await remoteDataSource.processLocals(context);
context.read<LocalProfileBloc>().add(LocalProfileEvent()); context.read<LocalProfileBloc>().add(LocalProfileEvent());

View File

@ -1,3 +1,5 @@
import 'dart:developer';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hub/flutter_flow/flutter_flow_model.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 { Future<void> _onLocalProfileEvent(LocalProfileEvent event, Emitter<LocalProfileState> emit) async {
log('LocalProfileBloc: _onLocalProfileEvent');
final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? ''; final cliName = (await StorageHelper().get(KeychainStorageKey.clientName.value)) ?? '';
final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? ''; final cliUUID = (await StorageHelper().get(KeychainStorageKey.clientUUID.value)) ?? '';
emit(state.copyWith(cliName: cliName, cliUUID: cliUUID)); emit(state.copyWith(cliName: cliName, cliUUID: cliUUID));
} }
void updateProfile(BuildContext context) { void updateProfile(BuildContext context) {
LocalsRepositoryImpl.license.add(false);
context.read<MenuBloc>().add(MenuEvent()); context.read<MenuBloc>().add(MenuEvent());
add(LocalProfileEvent()); 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:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
@ -38,6 +40,11 @@ class _LocalProfileComponentWidgetState extends State<LocalProfileComponentWidge
final double scaledFontSize = baseFontSize * textScaler.scale(1); final double scaledFontSize = baseFontSize * textScaler.scale(1);
final double limitedFontSize = scaledFontSize > 20 ? 12 : scaledFontSize; 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) { if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());

View File

@ -19,6 +19,7 @@ class MenuRepositoryImpl implements MenuRepository {
List<MenuItem?> entries = []; List<MenuItem?> entries = [];
try { try {
for (var entry in menuEntries) { for (var entry in menuEntries) {
log('Processing entry: ${entry.key}');
final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries); final bool isDefault = await menuDataSource.processDisplayDefault(item, entry, entries);
if (isDefault) continue; if (isDefault) continue;
final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key); final licenseValue = await LicenseRepositoryImpl().getLicense(entry.key);

View File

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

View File

@ -19,6 +19,7 @@ class LicenseRepositoryImpl implements LicenseRepository {
@override @override
Future<bool> updateLicense() async { Future<bool> updateLicense() async {
log('updateLicense');
bool result = false; bool result = false;
final bool isNewVersion = await localDataSource.isNewVersion(); final bool isNewVersion = await localDataSource.isNewVersion();
log('isNewVersion: $isNewVersion'); log('isNewVersion: $isNewVersion');
@ -39,7 +40,9 @@ class LicenseRepositoryImpl implements LicenseRepository {
@override @override
Future<String?> getLicense(String key) async { Future<String?> getLicense(String key) async {
return await localDataSource.get(key); final response = await localDataSource.get(key);
log('getLicense: $key: $response');
return response;
} }
@override @override

View File

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