When you use notifyListeners() in provider so basically, it means that you want to update this value based on different state but bloc is works on stream where you need to emit the state like if your app is in initial state then you emit your initial widget and on loading state you can emit your loading state through bloc.
But if you want to know that is there similar related to Consumer then answer is Yes. Bloc Builder is widget which rebuild the widget based on the different event.
bloc.dart
import 'package:flutter_bloc/flutter_bloc.dart';
abstract class TextFormEvent {}
class ChangeImageOnTextForm extends TextFormEvent {}
class LoadingImageEvent extends TextFormEvent {}
abstract class ImageState {
int get number => 0;
}
class FetchingState extends ImageState {}
class FetchedState extends ImageState {
@override
int number;
FetchedState(this.number);
}
class BLocExample extends Bloc<TextFormEvent, ImageState> {
BLocExample() : super(FetchingState()) {
on<LoadingImageEvent>((event, emit) {
emit(FetchingState());
});
on<ChangeImageOnTextForm>((event, emit) {
emit(FetchedState(state.number));
});
}
}
// From UI Side
BlocBuilder<BLocExample, ImageState>(
builder: (context, state) {
print(state);
if (state is FetchingState) {
return const CircularProgressIndicator();
} else if (state is FetchedState) {
print(state.number);
return SizedBox(
height: 200,
width: 500,
child: Image.network(
frameBuilder:
(context, image, frame, wasSynchronouslyLoaded) {
if (frame == null) {
return const LinearProgressIndicator();
} else {
return image;
}
},
'https://source.unsplash.com/random?sig=${state.number}',
),
);
}
From above sample code you can understand that how bloc is work based on the different state and event.