In flutter, TextField doesn't have an intrinsic width; it only knows how to size itself to the full width of its parent container. How do I set the width to the width of the contained text.
I tried putting the TextField inside a container
As outlined here How to update flutter TextField's height and width?
new Container(
width: 100.0,
child: new TextField()
)
I expect the width of the TextField to match the width of the text it contains. The TextField should grow wider as text is typed, and shrink narrower as text is deleted.
Step 1: Inside the TextField, Add the style parameter and assign the TextStyle(). Step 2: Inside the TextStyle(), Add the fontSize parameter and set the appropriate value. Step 3: Run the app.
Change the font size to increase TextField's height.In TextField there is a property style:TextStyle(); Inside the textstyle there is a property called font size. Then give the appropriate font size.
To hide counter value from TextField or TextFormField widget while using maxLength attribute, try following: TextField( decoration: InputDecoration( hintText: "Email", counterText: "", ), maxLength: 40, ), In this, I have set counterText attribute inside InputDecoration property with empty value. Hope it will help.
Currently, TextFields are 40px high with default settings.
Flutter has IntrinsicWidth to do the calculation for you. Just wrap your TextField
or TextFormField
in it as follow:
IntrinsicWidth(child: TextField())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With