Flutter Form persistence + example RadioTile FormField derivation

985 views
Skip to first unread message

rickb

unread,
Aug 18, 2017, 11:49:14 AM8/18/17
to Flutter Dev
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
StatePersister.zip

rickb

unread,
Aug 18, 2017, 7:01:43 PM8/18/17
to Flutter Dev
Ok, I split this up into a demo and package and put it up on GitHub

rickb

unread,
Aug 19, 2017, 7:55:09 PM8/19/17
to Flutter Dev
Fixed a lot of problems.  This now works as expected.  The known bug listed above is fixed.
Reply all
Reply to author
Forward
0 new messages