moved reload actions out of error context
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user