import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:logging/logging.dart'; import 'package:np_codegen/np_codegen.dart'; import 'package:to_string/to_string.dart'; part 'progress.g.dart'; abstract class ProgressBlocEvent { const ProgressBlocEvent(); } @toString class ProgressBlocUpdate extends ProgressBlocEvent { const ProgressBlocUpdate(this.progress, [this.text]); @override String toString() => _$toString(); final double progress; final String? text; } @toString class ProgressBlocState with EquatableMixin { const ProgressBlocState(this.progress, this.text); @override String toString() => _$toString(); @override List get props => [progress, text]; final double progress; final String? text; } /// A generic bloc to bubble progress update for some events @npLog class ProgressBloc extends Bloc { ProgressBloc() : super(const ProgressBlocState(0, null)) { on(_onEvent); } Future _onEvent( ProgressBlocEvent ev, Emitter emit) async { _log.info("[_onEvent] $ev"); if (ev is ProgressBlocUpdate) { await _onEventUpdate(ev, emit); } } Future _onEventUpdate( ProgressBlocUpdate ev, Emitter emit) async { emit(ProgressBlocState(ev.progress, ev.text)); } }