Skip to content

TextField, when center aligned, shows caret in the middle when pasting text #22496

Closed

Description

@pablote

Steps to Reproduce

I have a TextField like this:

child: TextField(
        onChanged: handleInputChange,
        enabled: !disabled,
        textAlign: TextAlign.center,
        style: TextStyle(color: Colors.black, fontSize: 16.0),
        obscureText: obscureText,
        decoration: new InputDecoration(
          contentPadding: const EdgeInsets.all(7.0),
          hintText: hintText,
          border: new OutlineInputBorder(
              borderRadius: new BorderRadius.all(const Radius.circular(5.0))
          )
        ),
      )

As I type, the caret is correctly shown at the end, but if I paste text from my keyboard, like my email which it remembers, the caret is shown in the middle in a weird position, not really in between characters. BTW, this does not happen when left aligned, in which case the caret is correctly advanced to the end.

caret_middle

Logs

N/A

Flutter doctor

$ flutter doctor -v
[✓] Flutter (Channel beta, v0.8.2, on Mac OS X 10.13.6 17G65, locale en-US)
    • Flutter version 0.8.2 at /Users/pablo/Documents/work/projects/forks/flutter
    • Framework revision 5ab9e70727 (3 weeks ago), 2018-09-07 12:33:05 -0700
    • Engine revision 58a1894a1c
    • Dart version 2.1.0-dev.3.1.flutter-760a9690c2

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.2)
    • Android SDK at /Users/pablo/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.2
    • ANDROID_HOME = /Users/pablo/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.0, Build version 10A255
    • ios-deploy 2.0.0
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 28.0.2
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)

• No issues found!

Activity

  1. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Oct 1, 2018
  2. added this to the milestone on Oct 1, 2018
  3. JediBurrell commented on Nov 11, 2018

    @JediBurrell

    This also happens when writing text if there's a space at the end.

  4. yohom commented on Nov 16, 2018

    @yohom

    I made a workaround to fix this problem, you can try it. @JediBurrell

    _controller.addListener(() {
      if (_controller.text.length != _controller.text.trim().length) {
        _controller.text = _controller.text.trim();
      }
      _controller.selection =
        TextSelection.collapsed(offset: _controller.text.length);
    });
  5. pablote commented on Nov 16, 2018

    @pablote
    Author

    This seems fixed for me starting with v0.10.2, can you guys verify it got fixed from 0.9.x to 0.10.x?

  6. yohom commented on Nov 16, 2018

    @yohom

    My flutter version is 0.11.3, and I met same problem with @JediBurrell 's situation(text if there's a space at the end), so I found a workaround. This is my flutter doctor:

    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel beta, v0.11.3, on Mac OS X 10.14.1 18B75, locale en-CN)
    [✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    [✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    [✓] Android Studio (version 3.2)
    [!] IntelliJ IDEA Ultimate Edition (version 2018.2.6)
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    [✓] VS Code (version 1.28.2)
    
  7. justinmc commented on Dec 26, 2018

    @justinmc
    Contributor

    I'm unable to reproduce this on the iOS simulator. I'll try on a real device soon if I can get set up. There have been several improvements to the TextField cursor recently that hopefully have fixed this.

  8. goderbauer commented on Jan 3, 2019

    @goderbauer
    Member

    With the example code given I cannot reproduce this anymore on neither a physical Android nor iOS device. I am tentatively closing this. If you still see this, please do not hesitate to reopen with additional details of how you reproduced it.

  9. zoechi commented on Jan 4, 2019

    @zoechi
    Contributor

    Looks like a dup of #24456 that was fixed recently #24456 (comment)

  10. github-actions commented on Aug 14, 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.

  11. locked as resolved and limited conversation to collaborators on Aug 14, 2021
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

    a: text inputEntering text in a text field or keyboard related problemsframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions