Asa*_*sad 2 expand textfield flutter flutter-layout
我想扩展 aTextField以垂直覆盖所有空间,它Container正在扩展但TextField没有扩展,这是设计:
蓝色是Container区域。但TextField没有扩大
这是我正在使用的代码:
Container(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Title"),
Container(
margin: EdgeInsets.only(top: 8),
child: TextField(
controller: c_title,
decoration: Styles.getInputFieldStyle(""),
),
),
Container(
margin: EdgeInsets.only(top: 16),
child: Text("Feedback"),
),
Expanded(
child: Container(
color: Colors.blue,
margin: EdgeInsets.only(top: 8),
child: TextField(
decoration: Styles.getInputFieldStyle(""),
controller: c_feedback,
keyboardType: TextInputType.multiline,
),
),
),
Container(
margin: EdgeInsets.only(top: 16),
width: double.infinity,
child: RaisedButton(
onPressed: (){_onSubmitPressed();},
child: Text("Submit"),
textColor: Colors.white,
color: MyColors.theme_red,
),
)
],
),
);
Run Code Online (Sandbox Code Playgroud)
使用 Flutter 1.5.4,您只需执行以下操作:
Expanded(
child: TextField(
expands: true,
maxLines: null,
),
)
Run Code Online (Sandbox Code Playgroud)
它将占据所有垂直自由空间。
你需要这个。
TextFormField(
decoration: InputDecoration(hintText: "Enter your very long text here"),
maxLines: double.maxFinite.floor(),
),
Run Code Online (Sandbox Code Playgroud)
编辑:这是您的最终解决方案。
Container(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Title"),
Container(
margin: EdgeInsets.only(top: 8),
child: TextField(
controller: c_title,
decoration: Styles.getInputFieldStyle(""),
),
),
Container(
margin: EdgeInsets.only(top: 16),
child: Text("Feedback"),
),
Expanded(
child: LayoutBuilder(
builder: (_, __) {
return Container(
color: Colors.blue,
margin: EdgeInsets.only(top: 8),
child: TextField(
decoration: Styles.getInputFieldStyle(""),
controller: c_feedback,
maxLines: double.maxFinite.floor(),
keyboardType: TextInputType.multiline,
),
);
},
),
),
Container(
margin: EdgeInsets.only(top: 16),
width: double.infinity,
child: RaisedButton(
onPressed: () {
_onSubmitPressed();
},
child: Text("Submit"),
textColor: Colors.white,
color: MyColors.theme_red,
),
)
],
),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2963 次 |
| 最近记录: |