Skip to content

The cursor height becomes shorter when I delete all characters from TextField #92080

Closed

Description

@YowFung

like the following picture:

flutter doctor -v
[√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.17763.2237], locale    en-US)
    • Flutter version 2.5.3 at D:\SDK\Flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • FLUTTER_GIT_URL = https://gitee.com/mirrors/Flutter.git
    • Framework revision 18116933e7 (4 days ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at D:\SDK\Android
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = D:\SDK\Android
    • ANDROID_SDK_ROOT = D:\SDK\Android
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • CHROME_EXECUTABLE = C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.5)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31729.503
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 4.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] IntelliJ IDEA Community Edition (version 2021.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.3
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5486

[√] VS Code (version 1.55.2)
    • VS Code at C:\Users\Zhanghuifeng\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.15.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.17763.2237]
    • Chrome (web)      • chrome  • web-javascript • unknown
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 94.0.992.50

• No issues found!
simple code
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'TextField Demo',
      theme: ThemeData(primarySwatch: Colors.teal),
      home: Scaffold(
        body: Center(
          child: SizedBox(
            width: 200,
            height: 80,
            child: TextField(
              controller: TextEditingController(text: "Hello"),
              minLines: 1,
              textAlignVertical: TextAlignVertical.center,
              cursorHeight: 14,
              decoration: InputDecoration(
                border: const OutlineInputBorder(),
                hintText: "HintText",
                labelText: "LabelText",
                hintStyle: const TextStyle(fontSize: 14),
                labelStyle: const TextStyle(fontSize: 15),
                counterText:  "",
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Activity

  1. danagbemava-nc commented on Oct 19, 2021

    @danagbemava-nc
    Member

    Hi @YowFung, thanks for filing the issue.

    I just tried your sample and the cursor height remains the same. See screenshot below.

    May I know what platform you're running your app on?

    If there are more steps to reproduce too, kindly let me know.

    screenshot Screenshot 2021-10-19 at 13 12 28

    Thank you

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 19, 2021
  3. YowFung commented on Oct 19, 2021

    @YowFung
    Author

    Hi, @danagbemava-nc

    May I know what platform you're running your app on?

    I running it on the Windows platform.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 19, 2021
  5. danagbemava-nc commented on Oct 19, 2021

    @danagbemava-nc
    Member

    Hi @YowFung, my question was poorly phrased.

    I meant are you running the app or android, web or desktop?

    Thank you

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 19, 2021
  7. YowFung commented on Oct 19, 2021

    @YowFung
    Author

    Hi @danagbemava-nc
    Yes, I mean my app running on the Windows desktop platform. And it was also developed on the Windows platform.

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 19, 2021
  9. danagbemava-nc commented on Oct 20, 2021

    @danagbemava-nc
    Member

    @YowFung, thanks for the clarification.

    One question, is there any reason in particular you need to set the cursorHeight?

  10. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 20, 2021
  11. YowFung commented on Oct 20, 2021

    @YowFung
    Author

    Hi, @danagbemava-nc
    It always will get shorter whether the cursor height is set or not. Just doesn't look obvious.

    When the cursor height is not be set:
    cursor

  12. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 20, 2021
  13. danagbemava-nc commented on Oct 20, 2021

    @danagbemava-nc
    Member

    I don't think it's just a matter of it becoming short. I played around with the values of the cursorHeight and it shows an issue with the behaviour of the cursor.

    Reproducible on stable and master.

    @YowFung, thanks for catching that.

    videos

    cursorHeight: defaultValue

    Screen.Recording.2021-10-20.at.13.11.53.mov

    cursorHeight: 1

    Screen.Recording.2021-10-20.at.13.09.13.mov

    cursorHeight: 32

    Screen.Recording.2021-10-20.at.13.07.05.mov
    flutter doctor -v
    [✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-arm, locale en-GB)
        • Flutter version 2.5.3 at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 18116933e7 (5 days ago), 2021-10-15 10:46:35 -0700
        • Engine revision d3ea636dc5
        • Dart version 2.14.4
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 13.0, Build version 13A233
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    
    [✓] VS Code (version 1.61.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.27.0
    
    [✓] Connected device (3 available)
        • M2007J20CG (mobile) • 5dd3be00 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)     • macos    • darwin-arm64   • macOS 11.6 20G165 darwin-arm
        • Chrome (web)        • chrome   • web-javascript • Google Chrome 94.0.4606.81
    
    • No issues found!
    [✓] Flutter (Channel master, 2.6.0-12.0.pre.405, on macOS 11.6 20G165 darwin-arm, locale en-GB)
        • Flutter version 2.6.0-12.0.pre.405 at /Users/nexus/dev/sdks/flutters
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f80d1d9447 (5 hours ago), 2021-10-19 23:33:03 -0400
        • Engine revision e6a4610ebd
        • Dart version 2.15.0 (build 2.15.0-233.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    
    [✓] VS Code (version 1.61.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.27.0
    
    [✓] Connected device (3 available)
        • M2007J20CG (mobile) • 5dd3be00 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)     • macos    • darwin-arm64   • macOS 11.6 20G165 darwin-arm
        • Chrome (web)        • chrome   • web-javascript • Google Chrome 94.0.4606.81
    
    • No issues found!
  14. 7 remaining items

  15. guidezpl commented on Oct 26, 2021

    @guidezpl
    Member

    Related/duplicate issues include #64072 and #61715 with some additional context. It might still be the case that this bug doesn't occur for iOS and macOS

  16. navaronbracke commented on Nov 7, 2021

    @navaronbracke
    Contributor

    I reported a similar issue #87790 a while ago. I decided to see if I could fix it myself. I found that the results of TextPainter._computeCaretMetrics() are off. Or at least that is how it looks to me? I can still reproduce the weird cursor behaviour on master while testing on Android (a physical device).

    Should the initial metric not try to emulate a character,
    to prevent resizing the caret / repositioning the caret on the y-axis? But this contradicts what @justinmc just said?

    Some examples of the _CaretMetrics results that I found while testing:

    An empty EditableText
    
    TextPainter Caret Metrics:
    offset: dx 0.0, dy: 0.0
    fullHeight: null -> should this not be equal to 16.40625 ?
    
    A character in EditableText, i.e. `k`
    TextPainter Caret Metrics:
    offset: dx 7.09765625, dy: -0.40625
    fullHeight: 16.40625
    

    A single space character in EditableText yields some strange behaviour.
    The metrics kept recomputing back and forth:

    TextPainter Caret Metrics:
    offset: dx 3.47265625, dy: -0.40625
    fullHeight: 16.40625
    TextPainter Caret Metrics:
    offset: dx 0.0, dy: -0.40625
    fullHeight: 16.40625
    TextPainter Caret Metrics:
    offset: dx 3.47265625, dy: -0.40625
    fullHeight: 16.40625
    TextPainter Caret Metrics:
    offset: dx 0.0, dy: -0.40625
    fullHeight: 16.40625
    
    // Keeps repeating itself
    
  17. justinmc commented on Dec 28, 2021

    @justinmc
    Contributor

    @GaryQian Digging into this it looks like there are some old TODOs of yours in the code related to this bug. Do you still have any plans or insight on fixing this?

    // TODO(garyq): This is no longer producing the highest-fidelity caret
    // heights for Android, especially when non-alphabetic languages
    // are involved. The current implementation overrides the height set
    // here with the full measured height of the text on Android which looks
    // superior (subjectively and in terms of fidelity) in _paintCaret. We
    // should rework this properly to once again match the platform. The constant
    // _kCaretHeightOffset scales poorly for small font sizes.

    In that method and elsewhere there are switch statements that perform different behavior for Mac and iOS, which is probably why this bug doesn't seem to happen on those platforms.

    When there is text in the field it uses TextPainter. getFullHeightForCaret instead (code), and the caret height is correct.

  18. added
    P2Important issues not at the top of the work list
    on Feb 23, 2022
  19. PcolBP commented on Jun 13, 2022

    @PcolBP

    Issue is reproducible on Flutter 3.0.2 - Platform Android
    image
    image

    image

  20. jiangkang commented on Jul 21, 2022

    @jiangkang

    Issue is reproducible on Flutter 3.0.5 - Platform IOS

    cursor-not-center.mp4
  21. antOnioOnio commented on Aug 11, 2022

    @antOnioOnio

    Any news on this ? Anyone has come with a workaround?

  22. justinmc commented on Oct 5, 2022

    @justinmc
    Contributor

    CC @LongCatIsLooong, should be fixed with your upcoming cursor refactor.

  23. github-actions commented on Mar 28, 2023

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

  24. locked as resolved and limited conversation to collaborators on Mar 28, 2023
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

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsfound in release: 1.21Found to occur in 1.21found in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagesp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions