How to make flutter TextField height match parent of container?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to make flutter TextField height match parent of container?



I want to make my TextField height same as my container height. Please check below code and let me know how can I make TextField match_parent of my container. I've checked this question The equivalent of wrap_content and match_parent in flutter? but didn't find any solution. I need to make TextField to take full height and width of my container.


TextField


TextField


TextField


new Container(
height: 200.0,
decoration: new BoxDecoration(
border: new Border.all(color: Colors.black)
),

child: new SizedBox.expand(
child: new TextField(
maxLines: 2,
style: new TextStyle(
fontSize: 16.0,
// height: 2.0,
color: Colors.black
),
decoration: const InputDecoration(
hintText: "There is no data",
contentPadding: const EdgeInsets.symmetric(vertical: 40.0),
)
),
),
)



Please check below screenshot, I need my TextField to take full height of Container


TextField


Container



enter image description here





Possible duplicate of The equivalent of wrap_content and match_parent in flutter?
– Ahmet Zorer
Aug 7 at 6:55




1 Answer
1



Let's remove a few lines in code and understand how flutter works.


200


Container


Container


SizedBox.expand


SizedBox


Container


TextField



Final version of code which displays the above image


new Container(
// height: 200.0,
decoration: new BoxDecoration(
border: new Border.all(color: Colors.black)
),

child: new TextField(
maxLines: 2,
style: new TextStyle(
fontSize: 16.0,
// height: 2.0,
color: Colors.black
),
decoration: const InputDecoration(
hintText: "There is no data",
// contentPadding: const EdgeInsets.symmetric(vertical: 40.0),
)
),
)





Thanks @Dinesh, actually I need a fixed height of my Container and to make my TextFiled to take this height.
– Ammy Kang
Aug 8 at 14:59



Container


TextFiled





Hi Ammy, How are you giving height to your TextField ?
– Dinesh Balasubramanian
Aug 8 at 16:28





currently I am using maxline attribute to give height to TextField, but this is not a good a practice.
– Ammy Kang
Aug 9 at 7:53


maxline


TextField





Got it.. 1) It is highly coupled with fontSize. 2) I am not sure whether it will affect if you change the device (like tablet, iPad). For now, it solves the problem. Have a eye on above two problems.
– Dinesh Balasubramanian
Aug 9 at 10:05





Yes, I know problems may occur, this is temporary fix for now, can you please help me with this? I need to make my container height fix all time.
– Ammy Kang
Aug 9 at 10:37






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS