Repository navigation
Unexpected behaviour of TextField hintMaxLines property #52008
Copy link
Copy link
Closed
Labels
a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
I am using the hintMaxLines property of the TextField which unexpectedly increases the TextField height even if the hint is not shown (See images below)
TextField when Hint is displayed:

TextField when Hint is not shown:

Expected TextField when Hint is not shown:

In the last image i forced the hintMaxLines = 1 if a text value was inserted by the user.
Code:
import 'package:flutter/material.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomeScreen(title: 'Flutter Demo Home Page'),
);
}
}
class HomeScreen extends StatefulWidget {
HomeScreen({Key key, this.title}) : super(key: key);
final String title;
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
TextEditingController controller = TextEditingController();
bool isEmpty = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: EdgeInsets.all(16),
child: TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
controller: controller,
onChanged: (value) {
setState(() {
// Toggle this for expected behavior
// isEmpty = value.isEmpty;
});
},
decoration: InputDecoration(
labelText: 'Title',
hintMaxLines: isEmpty ? 15 : 1,
hintText:
Iterable.generate(400, (index) => 'a').join(),
errorText: 'This is an error'),
),
));
}
}
Flutter Doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Ultimate Edition (version 2019.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.42.1)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
justinmc commentedon Mar 19, 2020
Thanks for the detailed issue. Are you saying that the expected behavior is that the field is very tall when it's empty, but when the user enters a character, it will immediately shrink to one line high?
justinmc commentedon Mar 23, 2020
Potentially related: #46182
darshankawar commentedon May 3, 2022
This behavior is replicable on latest stable and master using the code sample provided.
runnable code sample
stable, master flutter doctor -v
Fix broken text field with set hint and min and max lines(#153183) (#…
github-actions commentedon Oct 11, 2024
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 -vand a minimal reproduction of the issue.Fix broken text field with set hint and min and max lines(#153183) (#…