dart - 如何在一行中设置文本以进行颤动
问题描述
我在第 4 行文本字段中有下一个颤振/飞镖代码:
Container(
margin: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: 100.0,
child: TextField(
maxLength: 2,
onChanged: (value) {
card.expMonth = int.parse(value);
},
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none, hintText: 'month'),
)),
Text("/",
style: TextStyle(fontSize: 36),
textAlign: TextAlign.center),
Container(
width: 100.0,
child: TextField(
maxLength: 2,
onChanged: (value) {
card.expYear = int.parse(value);
},
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none, hintText: 'year'),
)),
Container(
padding: EdgeInsets.only(left: 80.0),
width: 180.0,
child: TextField(
maxLength: 3,
onChanged: (value) {
card.cvc = int.parse(value);
},
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none, hintText: 'cvc'),
)),
],
),
)
如何将所有文本字段放在一行中。在 android 应用程序中,我简单地使用指南或其他简单路径。在这里,我粉碎了颤动的现实,其中不同的文本字段具有不同的可见性,乍一看,参数相同
UPD .:我制作拐杖解决方案:
Padding(
padding: EdgeInsets.only(bottom: 20),
child: Text("/",
style: TextStyle(fontSize: 36),
textAlign: TextAlign.center),
),
但我的想法很愚蠢
解决方案
我会这样做:
Row(children: <Widget>[
Expanded(
child: TextField(
inputFormatters: [LengthLimitingTextInputFormatter(2)],
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none, hintText: 'month'),
)),
Expanded(
child: Text("/",
style: TextStyle(fontSize: 36),
textAlign: TextAlign.center)),
Expanded(
child: TextField(
inputFormatters: [LengthLimitingTextInputFormatter(2)],
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none, hintText: 'year'),
)),
Expanded(
child: TextField(
inputFormatters: [LengthLimitingTextInputFormatter(3)],
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none, hintText: 'cvc'),
)),
])
产生这个:
我使用inputFormatters: [LengthLimitingTextInputFormatter(2)]
了代替,maxLength
这样用户仍然只能以有限的长度输入,但你没有得到下面的计数器,TextField
因为它看起来更整洁。
推荐阅读
- java - 如何处理在网页上没有任何结果的搜索?
- ios - sqlite在查询记录时如何选择索引?
- linux - arm64 上的 Linux:不使用 pgprot_noncached 将设备寄存器映射到用户空间
- linux - Linux 上的 .Net Core 控制台应用程序不会作为服务运行
- c# - 使用 dir.GetDirectories 时排除具有特定模式的目录
- java - selenium java中的多个角色
- reactjs - react.js 桌面和移动 web 项目架构
- javascript - 如何从另一个组件调用 React 的渲染方法()?
- gradle - 如何获取 Gradle CodeNarc 任务来检查 Gradle 构建文件?
- asp.net-core - 从 ASP.NET Core MVC 端点获取 Twilio SMS 响应时遇到问题