Amm*_*ang 5 dart flutter flutter-layout
我要使我的TextField高度与我的容器高度相同。请检查以下代码,让我知道如何使TextField容器的match_parent。我已经检查了这个问题,在flutter中相当于wrap_content和match_parent?但没有找到任何解决方案。我需要将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),
)
),
),
)
Run Code Online (Sandbox Code Playgroud)
请检查下面的屏幕截图,我需要TextField全力以赴Container
Jac*_*Sun 11
这是我的解决方案:
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',
),
),
),
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
它对我来说效果很好。这是一个屏幕截图。
2021 年回答这个问题。现在有expands房产可用。这段代码的工作原理:
Column(
children: [
Expanded(
child: TextField(
maxLines: null,
minLines: null,
expands: true,
),
flex: 1),
],
)
Run Code Online (Sandbox Code Playgroud)
让我们删除几行代码并了解 flutter 的工作原理。
200Container高度。无法Container根据其子项调整高度(在本例中为 SizedBox.expand)Container占据了整个屏幕因为SizedBox.expandSizedBox我们的用例真的需要它吗?让我们将其删除,看看会发生什么。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),
)
),
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7834 次 |
| 最近记录: |