Repository navigation
Clearing a TextField by tapping on its suffixIcon causes its ripple to break, and the field stays gray. #36324
Copy link
Copy link
Closed
Labels
frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Description
Update: See the minimal example in the comment below.
If you comment out this line of datetime_picker_formfield and try its bundled example, an exception is thrown when when tapping the reset icon. The ripple effect slowly goes across the widget and it will be gray in color forever after. If the next line, _effectiveController.text = '';, is commented out, there is no exception.
I/flutter (18641): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (18641): The following assertion was thrown while handling a gesture:
I/flutter (18641): invalid text selection: TextSelection(baseOffset: 16, extentOffset: 16, affinity:
I/flutter (18641): TextAffinity.upstream, isDirectional: false)
I/flutter (18641):
I/flutter (18641): When the exception was thrown, this was the stack:
I/flutter (18641): #0 TextEditingController.selection=
I/flutter (18641): #1 EditableTextState._handleSelectionChanged
I/flutter (18641): #2 RenderEditable._handlePotentialSelectionChange
I/flutter (18641): #3 RenderEditable.selectPositionAt
I/flutter (18641): #4 RenderEditable.selectPosition
I/flutter (18641): #5 _TextFieldState._handleSingleTapUp
I/flutter (18641): #6 _TextSelectionGestureDetectorState._handleTapUp
I/flutter (18641): #7 TapGestureRecognizer._checkUp.<anonymous closure>
I/flutter (18641): #8 GestureRecognizer.invokeCallback
I/flutter (18641): #9 TapGestureRecognizer._checkUp
I/flutter (18641): #10 TapGestureRecognizer.acceptGesture
I/flutter (18641): #11 _TransparentTapGestureRecognizer.rejectGesture
I/flutter (18641): #12 GestureArenaManager.sweep
I/flutter (18641): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent
I/flutter (18641): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent
I/flutter (18641): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent
I/flutter (18641): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue
I/flutter (18641): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket
I/flutter (18641): #21 _invoke1 (dart:ui/hooks.dart:250:10)
I/flutter (18641): #22 _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
I/flutter (18641): (elided 3 frames from package dart:async)
I/flutter (18641):
I/flutter (18641): Handler: "onTapUp"
I/flutter (18641): Recognizer:
I/flutter (18641): _TransparentTapGestureRecognizer#b7e00
I/flutter (18641): ════════════════════════════════════════════════════════════════════════════════════════════════════
Flutter doctor
[✓] Flutter (Channel stable, v1.7.8+hotfix.3, on Linux, locale en_US.UTF-8)
• Flutter version 1.7.8+hotfix.3 at /home/jphilli85/tools/flutter
• Framework revision b712a172f9 (7 days ago), 2019-07-09 13:14:38 -0700
• Engine revision 54ad777fd2
• Dart version 2.4.0
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /home/jphilli85/tools/android
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /home/jphilli85/tools/android
• Java binary at: /usr/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-2~deb9u1-b03)
• All Android licenses accepted.
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/setup/#android-setup for detailed instructions).
[✓] VS Code (version 1.36.1)
• VS Code at /usr/share/code
• Flutter extension version 3.2.0
[✓] Connected device (1 available)
• moto g 6 • ZY322QW4KM • android-arm • Android 8.0.0 (API 26)It happens on stable and master.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Activity
[-]Unfocusing a TextField when its suffixIcon is tapped [/-][+]Unfocusing a TextField when its suffixIcon is tapped causes exception, ripple breaks[/+][-]Unfocusing a TextField when its suffixIcon is tapped causes exception, ripple breaks[/-][+]Setting TextField controller text when its suffixIcon is tapped causes exception, ripple breaks[/+]HansMuller commentedon Jul 17, 2019
Sorry, I'm not clear on the error being reported here. Can you provide a small self-contained app that demonstrates the problem in terms of an unmodified version of Flutter? Note also: https://gist.github.com/ is a useful way to share the code.
jifalops commentedon Jul 17, 2019
Here's a minimal example.
[-]Setting TextField controller text when its suffixIcon is tapped causes exception, ripple breaks[/-][+]Clearing a TextField by tapping on its suffixIcon causes its ripple to break, and the field stays gray.[/+]jifalops commentedon Jul 19, 2019
@HansMuller I'm surprised by how easy the ripple is broken here. This might be a critical bug. Just wanted to make sure you saw my last comment.
jifalops commentedon Aug 6, 2019
This is basically the same as #35848, #35909, #36065, #36671, and similar to #17647. The workaround is to clear the controller after the next frame or some delay. I've read it's because clicking the suffix icon causes the field to gain focus, and then it attempts to select text, but there is no text.
HansMuller commentedon Aug 6, 2019
@jifalops Thanks for the input, I've seen the test case and appreciate the rollup of similar issues.
justinmc commentedon Aug 6, 2019
The question is, should prefixes and suffixes pass taps through to the text field or not?
When vertical alignment was implemented for Material and Cupertino, we made the decision to pass touch gestures through to the text field in all cases except for CupertinoTextField's built in clear button. This is the code where CupertinoTextField explicitly ignores taps on the clear button.
We could reverse the behavior and ignore taps on all prefixes and suffixes. Or we could instead add new parameters like
ignoreTapsOnSuffix. @jifalops What do you think? Any other ideas?jifalops commentedon Aug 6, 2019
It does seem like passing taps to the text field would be the right thing to do in principle. I'm not sure if Flutter has any mechanism to allow the suffix icon to consume the tap like in DOM. I kind of lean towards calling clear() on the controller during a tap should not cause an error either way.
3 remaining items
justinmc commentedon Aug 12, 2019
Unfortunately it's not possible to do something like
event.stopPropagation()from the web world in Flutter, because Flutter uses an "event arena" model instead of event bubbling like the web.I'm thinking the idea of some flag/flags on TextField would be a good solution.
callumclift commentedon Aug 16, 2019
any updates on this? it's pretty much broken all of my text fields as i use the suffix icon to allow users to clear their text
justinmc commentedon Aug 16, 2019
@callumclift I'll try to put up a "work in progress" PR as a proposal for how we might solve this later today. I'll post back here when I do.
justinmc commentedon Aug 16, 2019
@callumclift (and anyone else that is interested) please let me know what you think of this approach! #38722
callumclift commentedon Aug 17, 2019
@justinmc sounds good, how are you coming along with a solution for Material? I'm using material TextFormField (due to its validator parameter which cupertino text fields don't have.) Also not sure if this is related but if you tap a textformfield to gain focus then tap the suffix icon without typing anything the tap is not registered on the suffix icon, instead it bring up the Paste & Select All options (on iPhone)
justinmc commentedon Aug 19, 2019
Thanks, good to know that would work. I'll keep that suffix tapping problem in mind as I build this. It sounds like it should be fixed by this change.
I think I can solve the problem in Material in the same way (same two parameters), but the code will just be a bit more indirect.
callumclift commentedon Aug 19, 2019
@justinmc awesome, any ideas on timescales for this?
justinmc commentedon Aug 19, 2019
I wouldn't count on it landing in master for a few weeks. I'm going to talk to some teammates about the Material solution tomorrow though and that will give me a better idea.
callumclift commentedon Sep 4, 2019
@justinmc is there any updates on when a fix will be available on master roughly?
JZ-at-TP commentedon Sep 5, 2019
This is preventing us from updating Flutter as well.
justinmc commentedon Sep 12, 2019
I've got a WIP pull request #38722, but I need to get some time to finish it... Sorry for holding everyone up!
justinmc commentedon Sep 24, 2019
Here is an open issue about this problem: #39376
DeveloperWaybee commentedon Mar 16, 2020
SOLUTION
Here's the solution for a suffix or prefix taps
Solution Link
lock commentedon Apr 2, 2020
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 -vand a minimal reproduction of the issue.