GiancarloCode / form_bloc

🔥 Dart and Flutter Package 🔥 Easy Form State Management using BLoC pattern 🔥 Wizard/stepper forms, asynchronous validation, dynamic and conditional fields, submission progress, serialization and more! 🔥
https://GiancarloCode.github.io/form_bloc/
462 stars 199 forks source link

Can't set TextFieldBlocState.error to null after successful validation #342

Open Oleg3n opened 9 months ago

Oleg3n commented 9 months ago

In a scenario when editing an already existing record, there is a need to initialize initial values for FieldBlocs. The first validation seems to happen on creating FormBloc. Values are empty at that point, so if field is required, State.error has error message. When SingleFieldBloc.updateInitialValue performs successful validation of new value, it calls emit(state.copyWith( ... error: Param(error), ... )) where error is NULL. The TextFieldBlocState.copyWith implementation is like this: error: error == null ? this.error : error.value, so when error is NULL it just keeps an old error message instead of reset it to null. As result the valid form submission fails.

vasilich6107 commented 2 months ago

https://github.com/GiancarloCode/form_bloc/pull/312#issuecomment-1164240179