0

I'm using flutter_bloc library to manage the state of the widgets. I'm trying to update a variable in the state that is a List. When I capture the state and modify the desired value, then yield the new state, the state doesn't update, but the clone of the state is changed.

Stream<ItemState> _updateRestrictions(ItemUpdateRestrictionValue event) async * {
  if (state is ItemLoaded) {
    final restrictions = (state as ItemLoaded).restrictions;

    final newState = restrictions.map((restriction) {
      if (restriction.id == event.restrictionId) {
        return ItemRestriction(
          id: restriction.id,
          name: restriction.name,
          restrictionType: restriction.restrictionType,
          restrictionValues: restriction.restrictionValues,
          restrictionValue: event.restrictionValueId
        );
      }

      return restriction;
    }).toList();

    yield ItemLoaded(restrictions: newState);
  }
}

Am I doing something wrong? Or how do you update the state using flutter_bloc correctly?

1 Answer 1

2

That probably happens because you use Equatable on your ItemState class and yield the same state back-to-back which is IteamLoaded().

You may wanna read this https://bloclibrary.dev/#/faqs?id=when-to-use-equatable

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.