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
Allow multiline TextField to expand vertically to fit container #21943
This is the only way I have been able to achieve this and its pretty hacky. Would be nice if TextFields were able to expand vertically to fit the container.
Having to put it in a container with an arbitrary 40px padding and force it to try to spill by giving it a maxLines of 99 just to get it to flex to height. An expanded: false or flexible: true property would be ideal
Due to the speed of flutter development my flutter doctor -v has changed considerably since I made this post. Sorry about that.
Reacted by Günter Zöchbauer, Dmitry, amervelic, Michael Pfaff, Loredana, Lai Zong Hao(Lai) and scottsidekick
I don't think flutter doctor output is essential for this feature request.
I just try to annoy people with requesting it until everyone adds it automatically everywhere ;-)
Actually flutter doctor -v output provides some context that is usually helpful and often essential.
Reacted by Luke Pighetti, Adeel Ahmad, Michael Pfaff, Orlando, Shubhranshu Shekhar and Omar Khaled
This is how you lay out every other set of widgets in a column, it's a surprise that the TextField handles its own size and doesn't expand. Possibly based on implementation, you may also need to set maxLines: null or some other value.
Reacted by scottwinter, Mhd Hejazi, Vitalii Shcherbyna, Michael Pfaff, Simion Nacu, Pete Morgan, fzyzcjy, David Miguel Lozano and 337240552
@zoechi That is a solution to a separate problem (a problem I also have, and the solution that I'm using). That is about changing the size of the textfield based on amount of content. This issue is about a textfield that has a fixed size (for a given screen size), taking up the remaining space.
100 px of the available height will be a container, and the rest will be the Placeholder. You can replace the placeholder with most normal widgets and get the same behaviour. If you replace it with a TextField, that's not what happens, and this is surprising.
I couldn't find a mention of scale in this issue and don't think it is about scaling text.
If your comment is about scaling text to a size, please check StackOverflow (I'm sure there is at least one question) and https://pub.dartlang.org (I'm also pretty sure there is a package that provides that)
I'm sorry, the use of the word "scale" was very misleading - I was trying to make it more clear not less! "Changes size" would be more appropriate. I have edited the comment as such.
@Will-W I'm working some changes that should make TextFields work with Expandeds as expected by using an expands parameter. I wrote up a proposal if you want to take a look: #27205
The expands parameter on TextField will do what's desired in this issue and allow the TextField to be sized based on its parent. So @Will-W's example could be achieved like this now:
To get it like a WhatsApp textbox which increases height up to a few lines then stop,
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 100 //put here the max height to which you need to resize the textbox
),
child: TextField(
maxLines: null, ),
)
Reacted by Luke Pighetti, AshfaqAshi, Jahan Zaib Bhatti, Muhammed Nazeem, ezzabuzaid and Dinesh Kachhot
The expands parameter on TextField will do what's desired in this issue and allow the TextField to be sized based on its parent. So @Will-W's example could be achieved like this now:
Closing this with #27205.
The expands parameter on TextField will do what's desired in this issue and allow the TextField to be sized based on its parent. So @Will-W's example could be achieved like this now:
I suspect the error you have got is assert. When you use expanded = true both minLines and maxLines have to be null. All that said, the correct code snippet should be:
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
lukepighetti commentedon Sep 17, 2018
zoechi commentedon Sep 25, 2018
What part do you find hacky?
How would you prefer it to be?
Please add the output of
flutter doctor -v.lukepighetti commentedon Sep 25, 2018
Having to put it in a container with an arbitrary 40px padding and force it to try to spill by giving it a maxLines of 99 just to get it to flex to height. An
expanded: falseorflexible: trueproperty would be idealDue to the speed of flutter development my
flutter doctor -vhas changed considerably since I made this post. Sorry about that.zoechi commentedon Sep 25, 2018
Thanks for your update!
I don't think flutter doctor output is essential for this feature request.
I just try to annoy people with requesting it until everyone adds it automatically everywhere ;-)
Actually
flutter doctor -voutput provides some context that is usually helpful and often essential.Will-W commentedon Dec 14, 2018
The user expectation (sample size: me) is that you would be able to do this:
This is how you lay out every other set of widgets in a column, it's a surprise that the TextField handles its own size and doesn't expand. Possibly based on implementation, you may also need to set
maxLines: nullor some other value.zoechi commentedon Jan 15, 2019
https://stackoverflow.com/questions/51205333/flutter-textfield-that-auto-expands-when-text-is-entered-and-then-starts-scrolli/51205467 might do what you want.
Will-W commentedon Jan 15, 2019
@zoechi That is a solution to a separate problem (a problem I also have, and the solution that I'm using). That is about changing the size of the textfield based on amount of content. This issue is about a textfield that has a fixed size (for a given screen size), taking up the remaining space.
E.g., you can do this:
100 px of the available height will be a container, and the rest will be the Placeholder. You can replace the placeholder with most normal widgets and get the same behaviour. If you replace it with a TextField, that's not what happens, and this is surprising.
[Edited as per following comments]
zoechi commentedon Jan 15, 2019
@Will-W
I couldn't find a mention of scale in this issue and don't think it is about scaling text.
If your comment is about scaling text to a size, please check StackOverflow (I'm sure there is at least one question) and https://pub.dartlang.org (I'm also pretty sure there is a package that provides that)
Will-W commentedon Jan 15, 2019
I'm sorry, the use of the word "scale" was very misleading - I was trying to make it more clear not less! "Changes size" would be more appropriate. I have edited the comment as such.
justinmc commentedon Jan 29, 2019
@Will-W I'm working some changes that should make TextFields work with Expandeds as expected by using an
expandsparameter. I wrote up a proposal if you want to take a look: #27205zoechi commentedon Jan 29, 2019
Looks like a dup of #18825, #15388
justinmc commentedon Mar 8, 2019
Closing this with #27205.
The
expandsparameter onTextFieldwill do what's desired in this issue and allow theTextFieldto be sized based on its parent. So @Will-W's example could be achieved like this now:AshfaqAshi commentedon Jun 11, 2020
To get it like a WhatsApp textbox which increases height up to a few lines then stop,
vokhidovhusan commentedon Jun 24, 2020
Make
alignLabelWithHint: trueinsideInputDecoration.note8g2018 commentedon Jul 6, 2020
I try it, I got error
lukepighetti commentedon Jul 6, 2020
Please provide a code snippet for reproduction. Thanks!
angel1st commentedon Jul 27, 2020
I suspect the error you have got is
assert. When you useexpanded = truebothminLinesandmaxLineshave to benull. All that said, the correct code snippet should be:TextField(expands: true, minLines: null, maxLines: null)omidraha commentedon May 19, 2021
Sample worked codes:
Links: 1, 2.
github-actions commentedon Aug 1, 2021
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.