Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset not working as expected #91

Closed
mkoorn opened this issue Jul 10, 2019 · 6 comments
Closed

reset not working as expected #91

mkoorn opened this issue Jul 10, 2019 · 6 comments
Labels
question Further information is requested

Comments

@mkoorn
Copy link

mkoorn commented Jul 10, 2019

I have have a form with FormBuilderTextField's as per example.
When calling fbKey.currentState.reset(), I can see when stepping through the code, that each field is reset to the initial value.

But when checking the value of the initial value, I see it has the value of the updated textfield which is also shown in the onChange.

I have no idea how this could be happening.

upgraded to v1.7.8+hotfix.3 today, but not sure if that could be an issue.

Any help would be greatly appreciated.

@stefensuhat
Copy link

experiencing same issue.

reset() not clearing any value.

@knaeckeKami
Copy link
Contributor

Could you please post a minimal example where this bug occurs? Just a main.dart file is enough. I'll look into it if I can reproduce it.

@mkoorn
Copy link
Author

mkoorn commented Jul 25, 2019

@knaeckeKami Thanks for your time. Currently I am swamped with work and in the end I managed by just creating a new key on reset.
I am new to flutter, so it is probably an issue on my side.
should I run into this some other time, I will update with an example.

@danvick danvick added the question Further information is requested label Jul 26, 2019
@gbtb
Copy link

gbtb commented Aug 20, 2019

I've faced the same issue. This issue caused by combination of 2 factors:

  1. Implementation detail of TextFormField - https://github.com/flutter/flutter/blame/9dce19e96ff36fc36c50d15f57fa20e096a5b29f/packages/flutter/lib/src/material/text_form_field.dart#L141
    Simply put, on each (re)build initial value of field will be set to current controller.text value.
  2. So, if you make your widget containing form stateful and use setState inside FormBuilder onChanged callback, you get rebuild each time you change field value => reassignment of initialValue. When time comes to reset form, reset "wont work".

@magillus
Copy link

I run into same issue, setting initialValue: "" fixed this - feels like work around = maybe by default set that value?

@danvick
Copy link
Collaborator

danvick commented Jul 18, 2020

This issue should be fixed. Feel free to reopen if not.

@danvick danvick closed this as completed Jul 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants