Reputation: 114
Good evening, I have been working with bloc pattern and I have some issues: The state update is being called only once on BlocBuilder, no matter what I do
What I have as state is:
class DateScreenState {
Future<List<PrimaryPetModifierModel>> primaryPetModifiers;
Future<List<SecondaryPetModifierModel>> secondaryPetModifiers;
PrimaryPetModifierModel primaryPetModifierSelected;
SecondaryPetModifierModel secondaryPetModifierSelected;
Widget animatedWidget;
DateTime dateOfSchedule;
DateTime timeOfSchedule;
bool shouldReload = false;
bool isFirstCallAnimation = true;
}
And my mapEventToState looks like this:
@override
Stream<DateScreenState> mapEventToState(
ScheduleDateScreenEvent event) async* {
if (event is SelectPrimaryModifierEvent) {
state.primaryPetModifierSelected = event.modifier;
yield state;
} else if (event is SelectSecondaryModifierEvent) {
state.secondaryPetModifierSelected = event.modifier;
yield state;
}
}
My exact issue is, when I change a value in a DropdownButton, it will fire a SelectedPrimaryModifierEvent or SelectedSecondaryModifier event, the event firing works fine, but the state yielding and updating will happen only once after the first fire of any of those events, after that, BlocBuilder builder function will not be called anymore after any event.
Upvotes: 2
Views: 1484
Reputation: 1002
I don't know If you use flutter_bloc
or you create a bloc pattern in your question.
If it was the first case then explain more how did you useBlocBuilder
and if it was the second case then read the bloc documentation.
Upvotes: 0
Reputation: 1
You're implementing the same state with each event, although you're changing a variable with the DateScreenState class. if you're extending "Equatable" : try to override the props function and put your variable in its list, or stop extending it
Upvotes: 0
Reputation: 5595
You're yielding the same state with each event, despite the fact that you're changing a variable with the DateScreenState
class. Try splitting up your primary and secondary into different state classes and yield them separately in your mapEventToState
.
Upvotes: 2