Form and FormFields are incomplete. Fields in a Form have a problem in that during scrolling or other obscuration (keyboard popup), the data doesn't persist. This because when a FormField is out of view, it is destroyed.
It is therefore up to the caller to persist field data state and restore it when the field comes back into view.
How to persist the data is non-obvious/non-intuitive. In TextFormField, you have to supply a TextEditingController instance that lives in something that maintains state above the Form instance.
Furthermore, the only input-specific FormField is TextFormField. There are no FormField derivations for RadioButtons, Switches, Checkboxes, etc.
Attached is an example that demonstrates:
- How to persist data in a FormField
- Introduces a RadioTileChoiceFormField
These are just the lib sources -- create a project with your favorite tool and replace the sources in the /lib directory with these.
I have lots to do to get this to the state I want. I will be formalizing this more in a GitHub repo, but I thought I would forward this as a preview/solution for anyone that is trying to figure out how to do this.
The intent is to:
- Round out the FormField set to create a FormField-derived class for each of the input widgets.
- Put it all together in a comprehensive package.
- Fix any bugs.
Known bugs:
- If you scroll while the keyboard is up and hit a radio button that was previously hidden by the keyboard, it crashes (on iOS, anyway). I'm looking into it. The workaround, currently, is to knock the keyboard down immediately after entering text. Then it works as expected.
Cheers,
rickb