Skip to content

Cursor with custom height has an incorrect vertical position when the text field is empty  #87790

Closed

Description

@navaronbracke

The cursor position behaves weirdly when the text field is empty and a cursor height has been provided.
On Web the cursor has different vertical positions when the text field is empty and when there is text.

Steps to Reproduce

  1. Run flutter create bug.
  2. Update main.dart with the code sample:
import 'package:flutter/material.dart';

void main() {
  runApp(
    const MaterialApp(
      home: Scaffold(
        body: Padding(
          padding: EdgeInsets.all(8.0),
          child: TextFieldBug(),
        ),
      ),
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    const double fontSize = 16;
    const double verticalPadding = 6;

    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: const [
        TextField(
          style: TextStyle(
            color: Color(0xFF939393),
            fontSize: fontSize,
          ),
          cursorHeight: 24,
          keyboardType: TextInputType.emailAddress,
          textInputAction: TextInputAction.next,
          cursorColor: Color(0xFF939393),
          decoration: InputDecoration(
            contentPadding: EdgeInsets.symmetric(
              horizontal: 18,
              vertical: verticalPadding,
            ),
            focusedBorder: OutlineInputBorder(
              borderSide: BorderSide.none,
              borderRadius: BorderRadius.all(Radius.circular(8)),
            ),
            border: OutlineInputBorder(
              borderSide: BorderSide.none,
              borderRadius: BorderRadius.all(Radius.circular(8)),
            ),
            filled: true,
            fillColor: Color(0xFFF4F4F4),
            floatingLabelBehavior: FloatingLabelBehavior.never,
            hoverColor: Color(0xFFF4F4F4),
            focusColor: Color(0xFFF4F4F4),
            isDense: true,
          ),
        )
      ],
    );
  }
}
  1. Type some text

Expected results:
The cursor is always aligned properly on the vertical axis, regardless if the textfield has text or not.

Actual results:
The cursor has a different vertical position when text has been typed then when there is none.
The cursor is pushed upwards when there is text. It sticks out from the top of the text field but is touching the bottom of the text field.

Screenshot 2021-08-06 at 12 05 21

Screenshot 2021-08-06 at 12 05 33

[✓] Flutter (Channel stable, 2.2.3, on macOS 11.2.3 20D91 darwin-x64, locale en-BE)
    • Flutter version 2.2.3 at /Users/navaronbracke/Documents/flutter
    • Framework revision f4abaa0735 (5 weeks ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/navaronbracke/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/navaronbracke/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_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • 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 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.58.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.25.0

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.131

• No issues found!

Activity

  1. changed the title [-][web] Cursor with a custom cursorHeight has an incorrect vertical position when the text field is empty [/-] [+][web] Cursor has an incorrect vertical position when the text field is empty [/+] on Aug 6, 2021
  2. changed the title [-][web] Cursor has an incorrect vertical position when the text field is empty [/-] [+][web] Cursor with custom cursor height has an incorrect vertical position when the text field is empty [/+] on Aug 6, 2021
  3. navaronbracke commented on Aug 6, 2021

    @navaronbracke
    ContributorAuthor

    It's even easier to notice with cursorWidth: 1 and isCollapsed: true.

    Screenshot 2021-08-06 at 13 19 44

    Screenshot 2021-08-06 at 13 19 56

  4. darshankawar commented on Aug 6, 2021

    @darshankawar
    Member

    Verified this using latest master and seems to be occuring on mobile as well, so this doesn't seem to be web specific.

    Mobile behavior:

    RPReplay-Final1628248600.MP4
    flutter doctor -v
    [✓] Flutter (Channel master, 2.5.0-6.0.pre.21, on Mac OS X 10.15.4 19E2269
        darwin-x64, locale en-GB)
        • Flutter version 2.5.0-6.0.pre.21 at
          /Users/dhs/documents/fluttersdk/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 40e8620a27 (7 hours ago), 2021-08-06 09:14:50 +0430
        • Engine revision 431ac604da
        • Dart version 2.14.0 (build 2.14.0-383.0.dev)
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.3, Build version 12C33
        • CocoaPods version 1.10.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.58.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (4 available)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 92.0.4515.131
    
    • No issues found!
    
    
    
    
    
  5. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Aug 6, 2021
  6. navaronbracke commented on Aug 6, 2021

    @navaronbracke
    ContributorAuthor

    @darshankawar Thanks for the fast response and repro. I assume this is a regression?

  7. changed the title [-][web] Cursor with custom cursor height has an incorrect vertical position when the text field is empty [/-] [+]Cursor with custom height has an incorrect vertical position when the text field is empty [/+] on Aug 6, 2021
  8. added
    engineflutter/engine related. See also e: labels.
    on Aug 6, 2021
  9. werainkhatri commented on Aug 8, 2021

    @werainkhatri
    Member

    Same problem exists with default TextField too.

    Empty One Space
    Empty One Space
    minimal code sample
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(
        const MaterialApp(
          home: Scaffold(
            body: Padding(
              padding: EdgeInsets.all(8.0),
              child: Center(
                child: TextField(),
              ),
            ),
          ),
        ),
      );
    }
    
  10. removed
    engineflutter/engine related. See also e: labels.
    on Aug 9, 2021
  11. chinmaygarde commented on Aug 9, 2021

    @chinmaygarde
    Contributor
  12. justinmc commented on Jul 14, 2022

    @justinmc
    Contributor

    Possibly related to #64072

  13. navaronbracke commented on Sep 20, 2023

    @navaronbracke
    ContributorAuthor

    I can no longer reproduce this on stable. (3.13.4)

  14. github-actions commented on Oct 4, 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.

  15. locked as resolved and limited conversation to collaborators on Oct 4, 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

    a: text inputEntering text in a text field or keyboard related problemsfound in release: 2.5Found to occur in 2.5frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions