Skip to content

Proposal to make TextField.onTapOutside default logic configurable  #150123

@kubatatami

Description

@kubatatami

Use case

We have a good API to handle tap outside events (TapRegion/TapRegionSurface) in Flutter and we even have onTapOutside on TextField but we have no ability to change the default logic of onTapOutside for the whole app or scope.

Current default logic bases on platform and follows default platform behavior. If I want to change it globally I have to set a custom onTapOutside for every TextField(which is a bit redundant for such a simple task) but if I am using external library with UI (like firebase_ui_auth) I am not able to change onTapOutside logic.

We have very similar situation for ScrollPhysics where we have a default per platform behaviour and we have physics on every Scrollable but we also let to configure default physics for the whole app or scope using ScrollConfiguration.

Proposal

My proposition is to create TapOutsideConfiguration where you can define a custom default logic for `onTapOutside.

TapOutsideConfiguration(
  behavior: AlwaysUnfocusTapOutsideBehavior(),
  // behavior: const NeverUnfocusTapOutsideBehavior(),
  // behavior: const CustomTapOutsideBehavior(),
  child: Column(
    children: [
      // This TextField will use onTapOutside from TapOutsideConfiguration
      TextField(),
      // Of course you can still define onTapOutside
      TextField(onTapOutside: (event) => print('Tapped outside')),
    ],
  ),
)

We can add 2 simple behaviors like AlwaysUnfocusTapOutsideBehavior and NeverUnfocusTapOutsideBehavior and let devs to define own custom logic like this:

class CustomTapOutsideBehavior extends TapOutsideBehavior {
  const CustomTapOutsideBehavior();

  @override
  void defaultOnTapOutside(PointerDownEvent event, FocusNode focusNode) {
    // any custom logic here
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions