Skip to content

Add CupertinoFormRow #69916

Closed
Closed

Description

@DanielEdrisian

Related: #26745

We would like to provide a more native look for forms in Cupertino.

So far, forms in Material are unlike the traditional look in iOS. As an example, TextFormField in Material displays a red helper text underneath the TextField when an error appears after validation. This experience is very rare in iOS, therefore supporting something like CupertinoTextFormField, where one has a similar validation experience to that of TextFormField but with an iOS theme, is not the best decision going forward.

About CupertinoTextFormField

  1. Validation is different in iOS. Oftentimes, an error in a field is reported using an alert view (cupertino dialog) which covers the center of the screen. In standard iOS forms, the dialog simply draws the user's attention to red-outlined inputs that need fixing. This is different to that of material, where submitting an invalid form input results in a helper text appearing beneath the widget, in red.

Screen Shot 2020-11-05 at 12 19 10 PM

  1. Furthermore, supporting the helper text style for Cupertino widgets (like CupertinoTextField,) isn't as straight-forward as the implementation in the Material counter-parts (like TextFormField.) This is because TextField's decorator type is an InputDecorator, as opposed to CupertinoTextField's decorator type which is a BoxDecorator. This means that in order to support a helper text, we would have to wrap the CupertinoTextField anyway. So we might as well do it the right (iOS) way.

The iOS Way

In iOS, standard forms take the following look:

Screen Shot 2020-11-05 at 12 19 10 PM

CupertinoFormRow

If we want to support forms for Cupertino widgets, I believe we should provide the aesthetic that's shown above. This would mean creating a CupertinoFormRow that has a label to its left and a child widget to its right.

Upon submission of the form, there should be the option to display a dialog encompassing all relevant errors. The most common user experience is something to the order of "Please fix the errors indicated in the form" but of course, that message should be determined by the developer. More importantly, the label within the CupertinoFormRow would turn red upon an invalid input submission.

CupertinoFormRow lets developers create their rows with the Cupertino look, while also giving them the freedom over the child widget displayed. This provides an experience consistent with iOS, while also avoiding the need to implement FormField support for each existing Cupertino widget.

Outstanding Tasks

  • Create CupertinoFormRow
    • Support left helper text
    • Support right child widget
    • Support validation and red color behavior
  • Support onValidate property for Form to have an input validation behavior on submission
    • Provide a default onValidate static function defined within CupertinoFormRow to pass to Form.onValidate
  • Create CupertinoFormSection

cc: @xster

Activity

  1. added
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Nov 5, 2020
  2. xster commented on Nov 5, 2020

    @xster
    Member

    We've also explicitly decided to make this separately from the #19228 since the iOS API for forms are less rigid about the content layout than table views and forms have 1 single primary "data entry" widgets per row.

    2 minor observations we should account for:

    • We should account for RTL right from the beginning to make sure the directionality look right on both sides
    • Could be worth creating a separately composable CupertinoFormSection widget to handle the padding/section header text/rounded corners/background/top, bottom borders which look different when extending edge to edge etc.

    Such as in
    image

    We should also look into who should draw the dividers, which may not be trivial. Drawing dividers in the CupertinoFormRows make them easier to use without CupertinoFormSections but rows won't know if they're the first or the last entry (dividers in the middle don't go edge-to-edge). Drawing dividers in CupertinoFormSection is easier to get the look correct, but it makes CupertinoFormRows less convenient to use on their own. I'm leaning towards the latter currently to prefer structuring the code to make the UI as correct as possible.

  3. DanielEdrisian commented on Nov 5, 2020

    @DanielEdrisian
    ContributorAuthor

    This is similar to how SwiftUI does it, so I am also in favor of CupertinoFormSections. I think it would be able to fix the divider issue pretty well. Adding it to the tasks.

  4. Daniel-BD commented on Nov 6, 2020

    @Daniel-BD

    You asked for feedback in #26745, so I'd just like to say that this looks like a great approach! I would be much more happy with this rather than just wrapping CupertinoTextField to support helper text. :)

  5. github-actions commented on Aug 9, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.p: cupertino_uicupertino_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions