moved reload actions out of error context

This commit is contained in:
2024-05-11 17:52:53 +02:00
parent 9fa711e460
commit 181682a424
14 changed files with 129 additions and 93 deletions

View File

@ -4,20 +4,19 @@ import 'package:bloc/bloc.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import '../loading_error.dart';
import 'loadable_state_event.dart';
import 'loadable_state_state.dart';
class LoadableStateBloc extends Bloc<LoadableStateEvent, LoadableStateState> {
late StreamSubscription<List<ConnectivityResult>> _updateStream;
LoadingError? loadingError;
void Function()? reFetch;
LoadableStateBloc() : super(const LoadableStateState(connections: null)) {
on<ConnectivityChanged>((event, emit) {
emit(event.state);
if(connectivityStatusKnown() && isConnected() && loadingError != null) {
if(!loadingError!.enableRetry) return;
loadingError!.retry!();
if(connectivityStatusKnown() && isConnected()) {
if(reFetch == null) return;
reFetch!();
}
});
@ -29,8 +28,8 @@ class LoadableStateBloc extends Bloc<LoadableStateEvent, LoadableStateState> {
bool connectivityStatusKnown() => state.connections != null;
bool isConnected() => !(state.connections?.contains(ConnectivityResult.none) ?? true);
bool allowRetry() => loadingError?.retry != null;
bool showErrorMessage() => isConnected() && loadingError != null;
bool allowRetry() => reFetch != null;
bool showErrorMessage() => isConnected() && reFetch != null;
IconData connectionIcon() => connectivityStatusKnown()
? isConnected()