Skip to content

TextField doesn't respect maxLength limit #67898

@gocal

Description

@gocal

Doctor summary

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.1, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.50.0)
[✓] Connected device (1 available)

Steps to Reproduce

  1. Create TextField as follows:
      TextField(
              maxLength: 5,
            ),

or

      TextField(
              maxLength: 5,
              inputFormatters: [LengthLimitingTextInputFormatter(5)],
            ),
  1. Start typing some text

Expected results:

  • TextField allows to enter only maxLength characters

Actual results:

  • it's possible to enter more than maxLength characters

Looks like it's related to the following change introduced in flutter 1.22 - https://github.com/flutter/flutter/pull/63754/files

packages/flutter/lib/src/services/text_formatter.dart

  ///
  /// ### Composing text behaviors
  ///
  /// There is no guarantee for the final value before the composing ends.
  /// So while the value is composing, the constraint of [maxLength] will be
  /// temporary lifted until the composing ends.
  ///
  /// In addition, if the current value already reached the [maxLength],
  /// composing is not allowed.

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: text inputEntering text in a text field or keyboard related problemsa: typographyText rendering, possibly libtxtc: proposalA detailed proposal for a change to Flutterc: regressionIt was better in the past than it is nowcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.f: 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