android-studio - 我如何表示行中的两个文本字段
问题描述
所以我正在尝试创建这样的布局。我在水平方向有 2 个文本字段,但将其包装成一行。但是在重新加载后没有文本字段出现:
但是,通过此代码,在重新加载后,这些都不会出现:
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],
)
),
),
],
)
解决方案
你必须使用一个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]
)
),
),
),
],
),
推荐阅读
- perl - 防止在具有原始数据库密码的 perl 脚本中的日志中打印异常
- excel - 不当使用财产
- microsoft-graph-api - Microsoft Graph API - 查询班次时出现未知错误
- asp.net-mvc - Syncfusion Treeview 未在 ASP.Net MVC5 中呈现
- java - 如何每小时强制触发分布式 GC(System.gc())?
- python - 如何合并 Pandas 中的列?
- javascript - 为什么我在 Angular 中的第二个休息请求无法更新数据网格?
- r - R中for循环的优化
- r - 如何根据开始时间创建具有不同间隔的时间序列
- swift - 通过 Swift 自动信任 URL 以防止 SSL 错误