Skip to content

Document that a null minLines defers to maxLines - #192799

Open
Saif64 wants to merge 2 commits into
flutter:masterfrom
Saif64:docs-minlines-maxlines-interaction
Open

Saif64 wants to merge 2 commits into
flutter:masterfrom
Saif64:docs-minlines-maxlines-interaction

Conversation

@Saif64

@Saif64 Saif64 commented Sep 15, 2026

Copy link
Copy Markdown

The minLines dartdoc currently says:

If this is null (default), text container starts with enough vertical space for one line and grows to accommodate additional lines as they are entered.

That is only accurate when maxLines is also null. RenderEditable._preferredHeight resolves a null minLines to maxLines:

final int? minLines = this.minLines ?? maxLines;

Since TextField.maxLines defaults to 1, a field declared as TextField(maxLines: 4) starts out four lines tall rather than starting at one line and growing into it. Measured heights of an empty field inside a SizedBox(width: 300) with the default Material theme:

widget height
TextField() 48.0
TextField(maxLines: 5) 136.0
TextField(minLines: 5, maxLines: 5) 136.0
TextField(maxLines: null) 48.0

maxLines: 5 with no minLines produces exactly the same height as an explicit minLines: 5, which is the interaction the issue asks to have documented.

This PR corrects the flutter.widgets.editableText.minLines template to describe the actual behavior and adds an example for the null-minLines case. The template is shared by TextField, TextFormField, CupertinoTextField, SelectableText, EditableText and RenderEditable, so all of their docs are updated by the single edit.

Documentation only; no behavior change.

Fixes #143903

Pre-launch Checklist

The docs for `minLines` said that a null value makes the field start with
enough vertical space for one line and grow as additional lines are
entered. That is only true when `maxLines` is also null.

`RenderEditable._preferredHeight` resolves a null `minLines` to `maxLines`
(`final int? minLines = this.minLines ?? maxLines;`), so a field declared
as `TextField(maxLines: 4)` starts out four lines tall rather than growing
into it.

Correct the `flutter.widgets.editableText.minLines` template to describe
the actual behavior, and add an example covering the null-`minLines` case.
The template is shared by TextField, TextFormField, CupertinoTextField,
SelectableText, EditableText and RenderEditable, so all of them are fixed.

Fixes flutter#143903

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels Sep 15, 2026
@google-cla

google-cla Bot commented Sep 15, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation for EditableText.minLines to clarify how its default null value interacts with maxLines, including adding a new code example. The review feedback suggests preserving the explicit mention of the default behavior when both minLines and maxLines are null to avoid confusion, and recommends minor grammatical improvements to the new code example for better readability.

Comment on lines +1312 to +1318
/// If this is null (default), the minimum height is determined by [maxLines]
/// instead: the field starts out tall enough to show [maxLines] lines, or a
/// single line when [maxLines] is also null. In other words, leaving
/// [minLines] null while setting [maxLines] to a value greater than one
/// produces a field that starts at its full [maxLines] height rather than
/// growing into it. To make the field start shorter and grow up to
/// [maxLines], set [minLines] explicitly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The updated documentation removes the explicit mention of the default behavior where both minLines and maxLines are null (i.e., that the text container starts with enough space for one line and grows as text is entered). To prevent confusion and maintain clarity for developers using the default configuration, we should explicitly preserve this detail.

  /// If this is null (default), the minimum height is determined by [maxLines]
  /// instead: the field starts out tall enough to show [maxLines] lines. If
  /// [maxLines] is also null, the field starts with enough vertical space for
  /// one line and grows to accommodate additional lines as they are entered.
  /// In other words, leaving [minLines] null while setting [maxLines] to a
  /// value greater than one produces a field that starts at its full [maxLines]
  /// height rather than growing into it. To make the field start shorter and
  /// grow up to [maxLines], set [minLines] explicitly.
References
  1. Optimize for readability: Code is read more often than it is written. (link)

Comment on lines +1347 to +1352
/// Input that is 4 lines tall from the start, because a null [minLines]
/// defers to [maxLines]. If additional lines are entered it will scroll
/// vertically.
/// ```dart
/// const TextField(maxLines: 4)
/// ```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and consistency with other documentation examples, use 'An input' instead of 'Input', and add a comma after the introductory conditional clause 'If additional lines are entered'.

  /// An input that is 4 lines tall from the start, because a null [minLines]
  /// defers to [maxLines]. If additional lines are entered, it will scroll
  /// vertically.
  /// ```dart
  /// const TextField(maxLines: 4)
  /// ```
References
  1. Optimize for readability: Code is read more often than it is written. (link)

The previous wording said the field starts at "a single line when
[maxLines] is also null", which described the starting height but dropped
the fact that it then grows as lines are entered. Restore that detail so
the both-null default is still fully described, while keeping the
correction for the non-null [maxLines] case.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField.minLines documentation is unclear about its maxLines interaction

1 participant