Reputation: 7768
I have the following BuiltMap get map; in the BowlerState. It contains BowlerEntity objects. I want to update a particular bowler in this map. My BowlerUpdate action contains the values that need to be updated in that particular bowler. How do I do so? I need to modify the below reducer to do so.
One reducer is like this
BowlerState _updateBowlerAge(
BowlerState bowlerState, SaveBowlerAgeSuccess action) {
return bowlerState.rebuild((b) => b
..map[action.bowler.id] = action.bowler
);
}
Upvotes: 1
Views: 205
Reputation: 2617
Use replace()
to replace the desired BowlerEntityBuilder.
BowlerState _updateBowlerAge(BowlerState state, SaveBowlerAgeSuccess action) {
final newMap = state.map[action.bowler.id].toBuilder()
..replace(action.bowler);
return state.rebuild((b) => b
..map.replace(newMap));
}
Upvotes: 1