DEV Community

Federico Stizza
Federico Stizza

Posted on

My flutter app's state is not transitioning.

I'm developing a Flutter app and I faced the next problem: My application state's is not transitioning like I would like.

The BLoC manage the behaviour of a form with properties of a Person Model.

So my state class looks like this.

class SynchronizedForm extends Equatable {

final PersonModel savedModel;

final PersonModel actualModel;

SynchronizedForm(this.savedModel, this.actualModel);

}
Note: The PersonModel also extends Equatable.

I've added a Simple Delegate to the BLoC, just for me to know what is exactly happening during the application run.

The delegate print on all state transitions.

The properties of the actualModel are updated via Events (BLoC pattern).

class PersonBloc extends Bloc {

PersonModel person;

PersonBloc (PersonModel person);

@override
PersonState get initialState => SynchronizedForm (person, person.copyWith());

@override
Stream mapEventToState(
PersonEvent event) async* {

if (event is ModifyPerson)
  yield* _modifyPerson();

else if ...

}

Stream _modifyPerson(
ModifyPerson event) async* {

PersonModel actual = state.actualModel;

actual.prop = event.value;

yield SynchronizedForm (
   state.savedModel,
   actual);

}
}
So the main problem is that I have widgets in my screens that consumes this state changes, but when the actual state is SynchronizedForm and I modify the person I'm again returning a SynchronizedForm. There's no explicit transition here but I need one to.

I tryied without Equatable, with Equatable. Using BlocConsumer, BlocListener (all this from flutter_bloc package). I don't know what more to do.

I hope you understand what I'm trying to do. Thank you all!

Top comments (1)

Collapse
 
mastersam07 profile image
Samuel Abada

To be honest, i don't know what you want to achieve.