gpt4 book ai didi

dart - 如何使 flutter 的TextField高度匹配容器的父级?

转载 作者:IT老高 更新时间:2023-10-28 12:38:18 27 4
gpt4 key购买 nike

我想让我的 TextField 高度与我的容器高度相同。请检查下面的代码,让我知道如何使 TextField match_parent 成为我的容器。我已经检查了这个问题 The equivalent of wrap_content and match_parent in flutter?但我没有找到任何解决方案。我需要使 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),
)
),
),
)

请查看下面的屏幕截图。如前所述,我需要我的 TextField 占据 Container

的全部高度

enter image description here

最佳答案

这是我的解决方案:

Container(
height: 200,
color: Color(0xffeeeeee),
padding: EdgeInsets.all(10.0),
child: new ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 200.0,
),
child: new Scrollbar(
child: new SingleChildScrollView(
scrollDirection: Axis.vertical,
reverse: true,
child: SizedBox(
height: 190.0,
child: new TextField(
maxLines: 100,
decoration: new InputDecoration(
border: InputBorder.none,
hintText: 'Add your text here',
),
),
),
),
),
),
),

对我来说效果很好。这是一个屏幕截图。

enter image description here

关于dart - 如何使 flutter 的TextField高度匹配容器的父级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51720468/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com