When i tap in textField in landScape mode i would like to expand in full screen likes whatsapp
Example gif Whats
TextFormField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.all(0.0),
child: Icon(Icons.person,
size: 40.0, color: Colors.white),
),
hintText: "Input your opinion",
hintStyle: TextStyle(color: Colors.white30),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(new Radius.circular(25.0))),
labelStyle: TextStyle(color: Colors.white)),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
),
controller: host,
validator: (value) {
if (value.isEmpty) {
return "Empty value";
}
},
)
In Flutter, you can create an auto-resize as needed TextField (or TextFormField) in one of the following ways: Set the maxlines argument to null. The textfield can expand forever if a lot of text is entered. Set minLines to 1 and maxLines to N (a possitive integer).
By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.
In Flutter, this can be done using TextEditingController . First, create a TextEditingController and set it as a controller property of your TextField widget. In this example, I have added an extra Button and Text widget which will show the added text when you click the “Show Text” button.
All you need to do is set the maxLines
variable when creating a TextField
. I have added the text field inside a Card widget so you can see the total area.
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Simple Material App"), ), body: Column( children: <Widget>[ Card( color: Colors.grey, child: Padding( padding: EdgeInsets.all(8.0), child: TextField( maxLines: 8, decoration: InputDecoration.collapsed(hintText: "Enter your text here"), ), ) ) ], ) ); }
Set maxLines to null and keyboardType to TextInputType.multiline like this:
TextField( maxLines: null, keyboardType: TextInputType.multiline, )
To achieve the exact look of the text area you can use this
TextFormField(
minLines: 6, // any number you need (It works as the rows for the textarea)
keyboardType: TextInputType.multiline,
maxLines: null,
)
Here is the output (Some extra styling will needed)
Enjoy....
Unfortunately, there is no way in flutter you can set the minimum height of a TextField or TextFormField. The best way to give a TextField or a TextFormField a fixed size is to specify the maximum lines the Field should take without expanding farther. Note: This does not limit the amount of input text, it only limits the number of lines shown.
Example:
TextFormField(
keyboardType: TextInputType.multiline,
maxLines: 8,
maxLength: 1000,
),
This will limit the size of the field to 8 lines, but can take as much as 1000 characters. Hope this will help someone.
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