Conversation
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]>
|
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. |
There was a problem hiding this comment.
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.
| /// 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. |
There was a problem hiding this comment.
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
- Optimize for readability: Code is read more often than it is written. (link)
| /// 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) | ||
| /// ``` |
There was a problem hiding this comment.
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
- 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]>
The
minLinesdartdoc currently says:That is only accurate when
maxLinesis also null.RenderEditable._preferredHeightresolves a nullminLinestomaxLines:Since
TextField.maxLinesdefaults to1, a field declared asTextField(maxLines: 4)starts out four lines tall rather than starting at one line and growing into it. Measured heights of an empty field inside aSizedBox(width: 300)with the default Material theme:TextField()TextField(maxLines: 5)TextField(minLines: 5, maxLines: 5)TextField(maxLines: null)maxLines: 5with nominLinesproduces exactly the same height as an explicitminLines: 5, which is the interaction the issue asks to have documented.This PR corrects the
flutter.widgets.editableText.minLinestemplate to describe the actual behavior and adds an example for the null-minLinescase. The template is shared byTextField,TextFormField,CupertinoTextField,SelectableText,EditableTextandRenderEditable, so all of their docs are updated by the single edit.Documentation only; no behavior change.
Fixes #143903
Pre-launch Checklist
///).