Skip to content

TextField maxLength property is not working correctly. #67236

@altherat

Description

@altherat

Sample app:

void main() => runApp(App());

class App extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: TextField(
            maxLength: 5,
            maxLengthEnforced: true
          )
        )
      )
    );
  }

}

When I enter only letters into the TextField, the length is not restricted and I can enter an unlimited amount of characters. When I enter only numbers into the TextField, it does not display more than 5 characters (as it should) although pressing backspace is bugged when typing more than 5 numbers. Example: If you type 12345678, the TextField will show 12345 but typing backspace will do nothing 3 times as if the TextField contains 12345678 but is only showing 12345.

flutter doctor -v:

[√] Flutter (Channel stable, 1.22.0, on Microsoft Windows [Version 10.0.19041.508], locale en-CA)
    • Flutter version 1.22.0 at C:\Flutter
    • Framework revision d408d302e2 (4 days ago), 2020-09-29 11:49:17 -0700
    • Engine revision 5babba6c4d
    • Dart version 2.10.0

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) 
    • Android SDK at C:\Users\Matt\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio Canary\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b01)
    • All Android licenses accepted.

[!] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio Canary
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b01)

[!] IntelliJ IDEA Community Edition (version 2019.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.2
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.dev/intellij-setup/#installing-the-plugins

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

[√] Connected device (1 available)
    • ONEPLUS A6013 (mobile) • 9e76e20e • android-arm64 • Android 10 (API 29)

! Doctor found issues in 3 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.found in release: 1.22Found to occur in 1.22found in release: 1.23Found to occur in 1.23frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions