我想让我的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
全高度
让我们删除代码中的几行,并了解flutter的工作原理。
200
。不能Container
根据其子项调整高度(在本例中为SizedBox.expand)Container
,SizedBox.expand
占据了整个屏幕SizedBox
用于我们的用例。让我们删除它也看看会发生什么。Container
包裹了TextField
。但是上面和下面都有一些空间。显示上述图像的最终版本代码
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),
)
),
)
这是我的解决方案:
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',
),
),
),
),
),
),
),
它对我很有用。这是一个截屏。