How to emit empty state more than one time when I am using equatable

359 Views Asked by At

I am trying to emit a state more than one time because I am validating a form no need to add any thing on the constructor and make copyWith func etc..

so could you help me with other solutions?

    class PersonUnValid extends PersonState {

  const PersonUnValid();

  @override
  List<Object> get props => [];

}
  void validate() {
    personKey.currentState!.save();
    if (Formz.validate(personForm.inputs) == FormzStatus.valid) {
      emit(const PersonValid());
      return;
    }
    emit(PersonUnValid());
  }

1

There are 1 best solutions below

1
On

emit() will not emit a new state, if it (the state) is identical. This is by design. See:

/// Updates the [state] to the provided [state].
/// [emit] does nothing if the [state] being emitted
/// is equal to the current [state].
void emit(State state) {
...
if (state == _state && _emitted) return;
...

What do you expect the UI should change when the state is the same?