Skip to content

Clearing a TextField by tapping on its suffixIcon causes its ripple to break, and the field stays gray. #36324

Closed

Description

@jifalops

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.

Activity

  1. changed the title [-]Unfocusing a TextField when its suffixIcon is tapped [/-] [+]Unfocusing a TextField when its suffixIcon is tapped causes exception, ripple breaks[/+] on Jul 17, 2019
  2. changed the title [-]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[/+] on Jul 17, 2019
  3. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jul 17, 2019
  4. HansMuller commented on Jul 17, 2019

    @HansMuller
    Contributor

    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.

  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 17, 2019
  6. jifalops commented on Jul 17, 2019

    @jifalops
    Author

    Here's a minimal example.

    import 'package:flutter/material.dart';
    
    const appName = 'Breaks Ripple';
    
    void main() => runApp(MaterialApp(title: appName, home: BreakTheRipple()));
    
    class BreakTheRipple extends StatelessWidget {
      final controller = TextEditingController(text: 'clear the text');
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text(appName)),
          body: ListView(
            padding: EdgeInsets.all(24),
            children: <Widget>[
              TextField(
                controller: controller,
                decoration: InputDecoration(
                  suffixIcon: IconButton(
                    icon: Icon(Icons.close),
                    onPressed: () {
                      // Workaround exception
                      // await Future.delayed(Duration(milliseconds: 10));
    
                      // Throws exception onTapUp
                      controller.clear();
                    },
                  ),
                ),
              ),
            ],
          ),
        );
      }
    }
    Flutter 1.7.8+hotfix.3 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision b712a172f9 (8 days ago) • 2019-07-09 13:14:38 -0700
    Engine • revision 54ad777fd2
    Tools • Dart 2.4.0
    
  7. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 17, 2019
  8. changed the title [-]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.[/+] on Jul 17, 2019
  9. jifalops commented on Jul 19, 2019

    @jifalops
    Author

    @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.

  10. jifalops commented on Aug 6, 2019

    @jifalops
    Author

    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.

  11. HansMuller commented on Aug 6, 2019

    @HansMuller
    Contributor

    @jifalops Thanks for the input, I've seen the test case and appreciate the rollup of similar issues.

  12. justinmc commented on Aug 6, 2019

    @justinmc
    Contributor

    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?

  13. jifalops commented on Aug 6, 2019

    @jifalops
    Author

    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.

  14. 3 remaining items

  15. justinmc commented on Aug 12, 2019

    @justinmc
    Contributor

    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.

  16. callumclift commented on Aug 16, 2019

    @callumclift

    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

  17. justinmc commented on Aug 16, 2019

    @justinmc
    Contributor

    @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.

  18. justinmc commented on Aug 16, 2019

    @justinmc
    Contributor

    @callumclift (and anyone else that is interested) please let me know what you think of this approach! #38722

  19. callumclift commented on Aug 17, 2019

    @callumclift

    @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)

  20. justinmc commented on Aug 19, 2019

    @justinmc
    Contributor

    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.

  21. callumclift commented on Aug 19, 2019

    @callumclift

    @justinmc awesome, any ideas on timescales for this?

  22. justinmc commented on Aug 19, 2019

    @justinmc
    Contributor

    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.

  23. callumclift commented on Sep 4, 2019

    @callumclift

    @justinmc is there any updates on when a fix will be available on master roughly?

  24. JZ-at-TP commented on Sep 5, 2019

    @JZ-at-TP

    This is preventing us from updating Flutter as well.

  25. justinmc commented on Sep 12, 2019

    @justinmc
    Contributor

    I've got a WIP pull request #38722, but I need to get some time to finish it... Sorry for holding everyone up!

  26. justinmc commented on Sep 24, 2019

    @justinmc
    Contributor

    Here is an open issue about this problem: #39376

  27. DeveloperWaybee commented on Mar 16, 2020

    @DeveloperWaybee

    SOLUTION

    Here's the solution for a suffix or prefix taps

    Solution Link

  28. lock commented on Apr 2, 2020

    @lock

    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.

  29. locked and limited conversation to collaborators on Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_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