Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand a textField in flutter looks like a text Area

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";
                }
              },
            )
like image 200
Micael Avatar asked Mar 03 '19 19:03

Micael


People also ask

How do you expand the TextField in Flutter?

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).

How do you customize a TextField in Flutter?

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.

How do you write text in TextField in Flutter?

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.


4 Answers

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"),               ),             )           )         ],       )     );   } 

like image 194
Matt List Avatar answered Sep 18 '22 12:09

Matt List


Set maxLines to null and keyboardType to TextInputType.multiline like this:

TextField(     maxLines: null,     keyboardType: TextInputType.multiline, )  
like image 45
AnasSafi Avatar answered Sep 17 '22 12:09

AnasSafi


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) enter image description here

Enjoy....

like image 22
Shoaib Khan Avatar answered Sep 19 '22 12:09

Shoaib Khan


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.

like image 31
Francisca Mkina Avatar answered Sep 19 '22 12:09

Francisca Mkina