我如何表示行中的两个文本字段
how do i represent two text fields in row
所以我正在尝试创建这样的布局。我有 2 个水平文本字段,但将其包装成一行。但是,重新加载后没有显示文本字段:
通过此代码,但是在重新加载时会出现 none:
Column(
children: <Widget>[
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
SizedBox(width: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
],
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Email/Mobile Number',
labelStyle: TextStyle(
color: Colors.grey[400],
)
),
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Password',
labelStyle: TextStyle(
color: Colors.grey[400],
)
),
),
],
)
您 Row
中的 TextField
小部件没有指定宽度,因此 Flutter 不知道文本字段应该占据多少水平 space。
要修复,请将您的两个 TextFields 包装在一个 Expanded
小部件中。 Expanded
根据行中的可用宽度调整文本字段的大小。
您必须使用 Expanded
小部件。
将您的 Row
小部件替换为以下小部件:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
// optional flex property if flex is 1 because the default flex is 1
flex: 1,
child: TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
),
SizedBox(width: 10.0),
Expanded(
// optional flex property if flex is 1 because the default flex is 1
flex: 1,
child: TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
),
],
),
所以我正在尝试创建这样的布局。我有 2 个水平文本字段,但将其包装成一行。但是,重新加载后没有显示文本字段:
通过此代码,但是在重新加载时会出现 none:
Column(
children: <Widget>[
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
SizedBox(width: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
],
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Email/Mobile Number',
labelStyle: TextStyle(
color: Colors.grey[400],
)
),
),
SizedBox(height: 10.0),
TextField(
decoration: InputDecoration(
labelText: 'Password',
labelStyle: TextStyle(
color: Colors.grey[400],
)
),
),
],
)
您 Row
中的 TextField
小部件没有指定宽度,因此 Flutter 不知道文本字段应该占据多少水平 space。
要修复,请将您的两个 TextFields 包装在一个 Expanded
小部件中。 Expanded
根据行中的可用宽度调整文本字段的大小。
您必须使用 Expanded
小部件。
将您的 Row
小部件替换为以下小部件:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
// optional flex property if flex is 1 because the default flex is 1
flex: 1,
child: TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
),
SizedBox(width: 10.0),
Expanded(
// optional flex property if flex is 1 because the default flex is 1
flex: 1,
child: TextField(
decoration: InputDecoration(
labelText: 'Name',
labelStyle: TextStyle(
color: Colors.grey[400]
)
),
),
),
],
),