ResoCoder / flutter-ddd-firebase-course

https://resocoder.com/flutter-firebase-ddd-course
GNU General Public License v3.0
470 stars 161 forks source link

state.copyWith not overriding properties #12

Closed BrianMwas closed 4 years ago

BrianMwas commented 4 years ago

Hi I have been trying to find out the problem for a whole two days and I still haven't found what the problem is When writing the property_form_bloc with initialNote the state does not update no matter what I do here's the code

`class PropertyFormBloc extends Bloc<PropertyFormEvent, PropertyFormState> { final IPropertyFacade _propertyFacade; PropertyFormBloc(this._propertyFacade) : super(PropertyFormState.initial());

@override Stream mapEventToState( PropertyFormEvent event, ) async { yield event.map( initialized: (e) async { e.initialPropertyOption.fold( () => state, (initialProperty) => state.copyWith( isEditing: true, property: initialProperty ) ); print("current state is now $state"); }, nameChanged: (e) async { print("name changed ${e.name}"); yield state.copyWith( property: state.property.copyWith(name: PropertyName(e.name)), saveFailureOrSuccessOption: none() ); }, descriptionEvent: (e) async { yield state.copyWith( property: state.property.copyWith(description: e.description), saveFailureOrSuccessOption: none() ); }, saved: (e) async { Either<ClassFailure, String> failureOrSuccess;

      yield state.copyWith(
          isSaving: true,
          saveFailureOrSuccessOption: none()
      );
      if(state.property.name.isValid() && state.property.description.length > 5) {
        failureOrSuccess = state.isEditing ?
          await _propertyFacade.updateProperty(state.property)
            : await _propertyFacade.createProperty(state.property);
      }

      yield state.copyWith(
        isSaving: false,
        showErrorMessages: true,
        saveFailureOrSuccessOption: optionOf(failureOrSuccess)
      );
    }
);

} }` Am I missing something? When I log out the initial property in this case it logs out the initialPropertyOption but is unable to update the state. Any answer is welcome

djordje-maslic commented 4 years ago

try adding the type of the stream PropertyFormState. @override Stream < PropertyFormState > mapEventToState( PropertyFormEvent event, ) async { yield event.map(

BrianMwas commented 4 years ago

Thanks I tried it and found out I had not added yield to the event. Thanks for this