-1

I have an issue when trying to update a bloc's state locally. I am trying to retrieve the state to manipulate the data and then emit a new state so it reflects those changes in the UI. I am not trying to manipulate the state itself just the property. The property is of type List this class is defined like this

This entity is in the domain layer. I have another class at the data layer which is defined like this

I am trying to modify one user's email and name but when retrieving the property is being parsed to List which is not correct since my porperty is defined as a List and when trying to update the list it fails. I do not want to cast the entire list to a userDataModel since that layer(presentation) where the bloc is should not know about models just entities.

I have tried to specified the types in both classes but I still get the same error. I have tried to copyWith the class and still having the same result. I have tried casting the list from List to List but does take effect.

Here is the error I am getting in the console.

Maybe I am doing things wrong, I have never had to modified a state locally like this. Any advice with an example would be really helpful on how to handle this scenario.

enter image description here

enter image description here

Matias
  • 708
  • 10
  • 24

1 Answers1

0

Ok, after a good night sleep I found that this is the best way to update a bloc.

//!Modify user in users list
final UsersListLoaded actualState = state as UsersListLoaded;
List<UserData> modifiedList = actualState.usersList.map((userData) {
  return userData.id == event.user.id ? event.user : userData;
}).toList();

And afterwards emit the loaded state with proper data.

Matias
  • 708
  • 10
  • 24