You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[TextField] The computation of the intrinsic width of a TextField should include the hint width only when visible #93337
Currently, when a TextField has decoration with an hint text, the width of this hint element is always integrated into the computation of the intrinsic width of the TextField widget, even if this hint is not displayed (= when the TextField text is not empty). This do not really make sense. As a consequence of this, when wrapping a TextField with an hint into an IntrinsicWidth widget or when setting a suffixText decoration to the TextField, the result is not the one you would expect as the minimal width of the text field would be constrained by the hint width.
This should be fixed by integrating the width of the hint text into the computation of the TextField intrinsic width only when its text is empty (=when the hint is actually displayed).
changed the title [-]The computation of the intrinsic width of a TextField should integrate the hint width only when visible[/-][+]The computation of the intrinsic width of a TextField should include the hint width only when visible[/+]on Nov 9, 2021
Hi @ramsestom, Thanks for filing the issue. Can you please provide reproducible steps to replicate the issue along with the output of flutter doctor -v.
IntrinsicWidth(
child: TextField(
decoration: InputDecoration(
hintText: 'this is some hint',
suffixText: 'sufix',
),
),
in the text field type some short text (like 'test') and you will see that the field width remains the width of the hint text (it will only increase when the text you enter is longer than the hint text). If you remove the hintText property, it works as expected.
flutter doctor -v
[√] Flutter (Channel beta, 2.6.0-5.2.pre, on Microsoft Windows [version 10.0.19043.1288], locale fr-FR)
• Flutter version 2.6.0-5.2.pre at C:\Development\Flutter\SDK
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 400608f101 (8 weeks ago), 2021-09-15 15:50:26 -0700
• Engine revision 1d521d89d8
• Dart version 2.15.0 (build 2.15.0-82.2.beta)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Development\Android\android-sdk
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = C:\Development\Android\android-sdk
• Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio1
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] VS Code, 64-bit edition (version 1.61.2)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.28.0
[√] Connected device (3 available)
• Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64 • Android 7.0 (API 24) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 94.0.4606.81
• Edge (web) • edge • web-javascript • Microsoft Edge 95.0.1020.40
! Doctor found issues in 1 category.
Thanks for the info @ramsestom, I am quite not sure I understand your proposal
I can see the textfield width increasing (as expected) when it goes beyond the hint
counter.2021-11-10.12-59-26.mp4
And I also see the minimal width of textfield is hintwidth +suffix text width so I don't see a problem here. can you please explain your proposal or issue?
Like I said, type some short text into the textfield (so the hint text disapear and is replaced by the text you typed). In this case the text field would not have the correct width (it will keep the same width as when the hint text was displayed, even if the text in it is now shorter). You can see this in you first video. The textfield starts changing its width only when the typed text is longer than the hint one (wich is not what is expected. As soon as the hint text dissapear, the textfield should shrink to fit its content as it is inside an IntrinsicWidth widget.)
Like I said, type some short text into the textfield (so the hint text disapear and is replaced by the text you typed). In this case the text field would not have the correct width (it will keep the same width as when the hint text was displayed, even if the text in it is now shorter).
Ah, I see thanks for the clarification @ramsestom. The textfield when wrapped in a IntrinsicWidth widget its width should be based on the width of the text in the textfield (when hint is not shown) but currently its constant until the entered text width is greater than the hint.
e.g in the below image textfield should have shrinked since it is within the IntrinsicWidth widget, but instead it still has constant width of hintText
flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
• Flutter version 2.5.3 at /Users/mahesh/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/mahesh/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = /Users/mahesh/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.1, Build version 13A1030d
• CocoaPods version 1.10.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 60.1.4
• Dart plugin version 212.5080.8
[✓] VS Code (version 1.61.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.28.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.0.1 21A559 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• No issues found!
[✓] Flutter (Channel master, 2.6.0-12.0.pre.655, on macOS 12.0.1 21A559 darwin-arm, locale en-GB)
• Flutter version 2.6.0-12.0.pre.655 at /Users/mahesh/Documents/flutter_master
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 5ce05e6ec5 (34 hours ago), 2021-11-08 23:43:04 -0500
• Engine revision 162d8508f8
• Dart version 2.15.0 (build 2.15.0-285.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/mahesh/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = /Users/mahesh/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.10.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 60.1.4
• Dart plugin version 212.5080.8
[✓] VS Code (version 1.61.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.28.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.0.1 21A559 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• No issues found!
code sample
import'package:flutter/material.dart';
voidmain() {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({Key? key}) :super(key: key);
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
// This is the theme of your application.//// Try running your application with "flutter run". You'll see the// application has a blue toolbar. Then, without quitting the app, try// changing the primarySwatch below to Colors.green and then invoke// "hot reload" (press "r" in the console where you ran "flutter run",// or simply save your changes to "hot reload" in a Flutter IDE).// Notice that the counter didn't reset back to zero; the application// is not restarted.
primarySwatch:Colors.blue,
),
home:constMyHomePage(title:'Flutter Demo Home Page'),
);
}
}
classMyHomePageextendsStatefulWidget {
constMyHomePage({Key? key, requiredthis.title}) :super(key: key);
// This widget is the home page of your application. It is stateful, meaning// that it has a State object (defined below) that contains fields that affect// how it looks.// This class is the configuration for the state. It holds the values (in this// case the title) provided by the parent (in this case the App widget) and// used by the build method of the State. Fields in a Widget subclass are// always marked "final".finalString title;
@overrideState<MyHomePage> createState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
int _counter =0;
void_incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has// changed in this State, which causes it to rerun the build method below// so that the display can reflect the updated values. If we changed// _counter without calling setState(), then the build method would not be// called again, and so nothing would appear to happen.
_counter++;
});
}
@overrideWidgetbuild(BuildContext context) {
// This method is rerun every time setState is called, for instance as done// by the _incrementCounter method above.//// The Flutter framework has been optimized to make rerunning build methods// fast, so that you can just rebuild anything that needs updating rather// than having to individually change instances of widgets.returnScaffold(
appBar:AppBar(
// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.
title:Text(widget.title),
),
body:Center(
// Center is a layout widget. It takes a single child and positions it// in the middle of the parent.
child:Column(
// Column is also a layout widget. It takes a list of children and// arranges them vertically. By default, it sizes itself to fit its// children horizontally, and tries to be as tall as its parent.//// Invoke "debug painting" (press "p" in the console, choose the// "Toggle Debug Paint" action from the Flutter Inspector in Android// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)// to see the wireframe for each widget.//// Column has various properties to control how it sizes itself and// how it positions its children. Here we use mainAxisAlignment to// center the children vertically; the main axis here is the vertical// axis because Columns are vertical (the cross axis would be// horizontal).
mainAxisAlignment:MainAxisAlignment.center,
children:<Widget>[
constText(
'You have pushed the button this many times:',
),
IntrinsicWidth(
child:TextField(
decoration:InputDecoration(
hintText:'this is some hint',
suffixText:'sufix',
),
)),
Text(
'$_counter',
style:Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton:FloatingActionButton(
onPressed: _incrementCounter,
tooltip:'Increment',
child:constIcon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Reacted by ramsestom, Christian Mele, Raşit Ayaz and Hari07
@PoojaB26 Managed to make this situation work by removing the hint text altogether from the textfield (hintText:null), and having hint text be a separate text element thats next in the row that shows only when controller.text is empty
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 -v and a minimal reproduction of the issue.
Activity
[-]The computation of the intrinsic width of a TextField should integrate the hint width only when visible[/-][+]The computation of the intrinsic width of a TextField should include the hint width only when visible[/+]maheshj01 commentedon Nov 10, 2021
Hi @ramsestom, Thanks for filing the issue. Can you please provide reproducible steps to replicate the issue along with the output of
flutter doctor -v.Thanks
ramsestom commentedon Nov 10, 2021
Just try this:
in the text field type some short text (like 'test') and you will see that the field width remains the width of the hint text (it will only increase when the text you enter is longer than the hint text). If you remove the hintText property, it works as expected.
maheshj01 commentedon Nov 10, 2021
Thanks for the info @ramsestom, I am quite not sure I understand your proposal
I can see the textfield width increasing (as expected) when it goes beyond the hint
counter.2021-11-10.12-59-26.mp4
And I also see the minimal width of textfield is hintwidth +suffix text width so I don't see a problem here. can you please explain your proposal or issue?
counter.2021-11-10.13-05-37.mp4
ramsestom commentedon Nov 10, 2021
Like I said, type some short text into the textfield (so the hint text disapear and is replaced by the text you typed). In this case the text field would not have the correct width (it will keep the same width as when the hint text was displayed, even if the text in it is now shorter). You can see this in you first video. The textfield starts changing its width only when the typed text is longer than the hint one (wich is not what is expected. As soon as the hint text dissapear, the textfield should shrink to fit its content as it is inside an IntrinsicWidth widget.)
maheshj01 commentedon Nov 10, 2021
Ah, I see thanks for the clarification @ramsestom. The textfield when wrapped in a
IntrinsicWidthwidget its width should be based on the width of the text in the textfield (when hint is not shown) but currently its constant until the entered text width is greater than the hint.e.g in the below image textfield should have shrinked since it is within the
IntrinsicWidthwidget, but instead it still has constant width of hintTextflutter doctor -v
code sample
5 remaining items
Hari-07 commentedon Nov 2, 2024
@PoojaB26 Managed to make this situation work by removing the hint text altogether from the textfield (
hintText:null), and having hint text be a separate text element thats next in the row that shows only when controller.text is emptyHari-07 commentedon Nov 2, 2024
This is a P2 that's been open for more than 2 years, any ETA?
Fix TextField intrinsic width when hint is not visible (#161235)
github-actions commentedon Feb 7, 2025
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.