Skip to content

WIP TextField prefix/suffix events - #38722

Closed
justinmc wants to merge 4 commits into
flutter:masterfrom
justinmc:prefix-suffix-gestures
Closed

justinmc wants to merge 4 commits into
flutter:masterfrom
justinmc:prefix-suffix-gestures

Conversation

@justinmc

@justinmc justinmc commented Aug 16, 2019 •

Copy link
Copy Markdown
Contributor

Description

In both Material and Cupertino, taps on a prefix or suffix in a text field are received by the text field itself as well as the prefix/suffix. This causes unexpected behavior when a button is in the prefix/suffix or even exceptions when clearing text.

The root cause of this problem is TextSelectionGestureDetector, which allows listening to all events, not just events given to it by the gesture arena. This is necessary, however, because it needs to listen to gestures that happen on top of the selection handles.

Cupertino Solution

CupertinoTextField already solves this problem for its built-in clear button. It uses a GlobalKey to check if a tap hits the clear button and ignores the tap if so. I've taken the same approach to solve this for prefix/suffix.

I added two parameters to enable this solution. Here is a typical use case:

CupertinoTextField(
  prefix: IconButton(...),
  prefixGesturesIgnored: true,
  suffix: IconButton(...),
  suffixGesturesIgnored: true,
)

Read more in the code and docs here.

Material Solution

This is still a work in progress. I'm trying to take the same approach, but prefix and suffix are passed into InputDecoration, so I can't directly give them GlobalKeys and access them in TextField's TextSelectionGestureDetector. I'm trying to work around that.

Related Issues

#36324
#39376
Closes #39376

Tests

TODO

@justinmc justinmc added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages p: cupertino_ui cupertino_ui package in flutter/packages work in progress; do not review labels Aug 16, 2019
@justinmc justinmc self-assigned this Aug 16, 2019
@fluttergithubbot

Copy link
Copy Markdown
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. While there are exceptions to this rule, if this patch modifies code it is probably not an exception.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@justinmc
justinmc force-pushed the prefix-suffix-gestures branch from 6c4b13b to a38b629 Compare September 27, 2019 18:21
@justinmc justinmc mentioned this pull request Oct 22, 2019
7 of 9 tasks
@goderbauer

Copy link
Copy Markdown
Member

@justinmc Do you still have plans for this PR?

@justinmc

Copy link
Copy Markdown
Contributor Author

Yes, but it seems like I haven't gotten back to this in a long time! I'll close it for now and make a note to myself to reopen when I have time to work on it.

@justinmc justinmc closed this Feb 24, 2020
@justinmc
justinmc deleted the prefix-suffix-gestures branch March 11, 2020 19:11
@justinmc
justinmc restored the prefix-suffix-gestures branch March 11, 2020 19:12
@DeveloperWaybee

Copy link
Copy Markdown

SOLUTION

Here's the solution for a suffix or prefix taps

Solution Link

@lock

lock Bot commented Apr 2, 2020

Copy link
Copy Markdown

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.

@lock lock Bot locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Taps on TextField prefix/suffix

5 participants