flutter - Flutter TextFormField:在输入字段左侧对齐文本描述
问题描述
美好的一天,我正在 Flutter 中创建 TextFormFields,我有点沮丧,因为我不能在输入输入的左侧有文本,而留在那里。
当您输入该字段时,hintText 会消失。
prefixText 仅在您输入该字段后出现。
prefixIcon 完全符合我的要求,但我想要 Text 而不是图标。
上图使用了prefixIcon 和hintText。
有没有人建议如何用永久文本替换我目前拥有的图标?感谢您的任何帮助。
解决方案
尝试prefixText
在装饰中使用该属性。
TextField(
controller: _textController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Enter a valid ZIP-Code',
errorText: _hasInputError ? "ZIP-Code is too short" : null,
counterText: _textController.text.length.toString(),
helperText: "ZIP-Code of shipping destination",
labelText: "ZIP-Code",
prefixText: "DE - ",
suffixIcon: Icon(Icons.airport_shuttle),
),
),
参考这个链接
我认为您在使用prefixIcon
时不能使用decoration
.
推荐阅读
- neo4j - 在 Neo4j 中为关系设置属性
- react-native - React Native 文本和图像并排对齐问题
- netlogo - 如何在 NetLogo 中改变随机海龟的颜色
- java - SpEL Spring中的三元运算符
- c# - Windows 身份验证:用户 'DOMAIN\MACHINE$' 登录失败
- android - Android 推送通知与 Firebase 推送通知
- mysql - 是否可以使用 mysql_user ansible 模块删除 mysql root 用户进行远程登录?
- java - 当参数是给定类型的子类时如何调用重载方法?
- amazon-web-services - 字体未从 aws s3 加载(400 错误请求)
- php - PHP / htaccess中带有正斜杠的GET参数