Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter textfield that auto expands when text is entered and then starts scrolling the text when a certain height is reached

I've tried many configurations of the Flutter TextField but can't figure out how to build this one.

I'm looking for a textfield that is a single line initially and it auto expands as the text is entered into it and then at some point begins scrolling itself.

This can be achieved partially by using the maxLines: null attribute. But then when a lot of text is entered the Text in the textfield itself overflows.

And if the maxLines is set to a value then the whole textfield itself gets expanded to those many lines to start off with rather than beginning with a single line.

Is there a way to limit the height of textfield at some point like done in many chat apps like WhatsApp and telegram.

like image 255
sujay_br Avatar asked Jul 06 '18 07:07

sujay_br


People also ask

How do you add a dynamic TextField in Flutter?

Add a form with a text field to enter our name in this class. 3. Create a list that will tell how many dynamic text fields to display and will also store each text field data. static List<String> friendsList = [null];


1 Answers

Container(
    child: new ConstrainedBox(
        constraints: BoxConstraints(
            maxHeight: 300.0,
        ),
        child: TextField(
                    maxLines: null,
                ),
            ),
        ),
    ),
)

In older Flutter versions it was

Container(
    child: new ConstrainedBox(
        constraints: BoxConstraints(
            maxHeight: 300.0,
        ),
        child: new Scrollbar(
            child: new SingleChildScrollView(
                scrollDirection: Axis.vertical,
                reverse: true,
                child: new TextField(
                    maxLines: null,
                ),
            ),
        ),
    ),
)
like image 169
Günter Zöchbauer Avatar answered Oct 10 '22 22:10

Günter Zöchbauer