I am new to flutter_bloc
and need some clarity.
I am developing an app similar to TikTok, that has a PageView
with VideoPlayer
s. I want to toggle Like
, Save
, and Follow
buttons on the screen. The parent widget is wrapped in FeedBloc
BlocBuilder
already, so how should I handle updating the widgets without using StatefulWidgets
?
In Provider
, we simply use Selector
or Consumer
widgets wherever we want and just call notifyListerners()
. What is the alternative to notifyListeners()
in flutter_bloc
?
I just want to update widgets when variable values change and the state
remains the same.
2
Answers
You use
emit
for that as well. Just make sure that the state is comparable. So two versions of same state can be differentiated using equals and hashcode.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
From above sample code you can understand that how bloc is work based on the different state and event.