I've been using validation which I think is very good the problem is when I want to clean up the textformfields, since I have to update the status of the inputs How could I clean up the inputs? already try to return
` else if (event is FormSubmitted) {
if (state.status.isValidated) {
yield state.copyWith(status: FormzStatus.submissionInProgress);
await Future<void>.delayed(const Duration(seconds: 1));
yield state.copyWith(status: FormzStatus.submissionSuccess);
yield MyFormState(); <------- but dont work
}
}`
I'm having this issue too, see this SO question
I also note that the form validation example in this repo doesn't clear the form after submitting, so there's not much guidance on what seems to be a simple task but is actually quite an architectural question.
If it's a little complex to fix this and then I'd better use TextEditingController
Hi @Makarov96 馃憢
Thanks for opening an issue!
The reason it doesn't work is because you need to use a BlocListener to update the TextEditingController when the state changes. Otherwise the UI will update the bloc but the bloc won't update the UI (because the TextField maintains its own state by default).
BlocListener<FormBloc, FormState>(
listener: (context, state) {
// Handle updating the `TextEditingController` text based on the bloc state
_controller.text = state.value;
},
child: ...
)
Hope that helps! 馃憤
Thank you so much !!
Most helpful comment
Thank you so much !!