flutter - 在 Flutter 的输入装饰中为 labelText 添加强制(*)
问题描述
我想在InputDecoration
labelText 中添加星号并更改它的颜色(如红色),以便用户轻松理解此字段是必需的。
TextField(
autofocus: true,
controller: _nameCtrlr,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name *",
))
像这个图像的预期结果 示例图像
解决方案
您可以像这样使用富文本小部件
RichText getRequiredLabel(String fieldName) {
return RichText(
text: TextSpan(
style: TextStyle(color: Colors.black),
text: fieldName,
children: [
TextSpan(text: '*', style: TextStyle(color: Colors.red))
]));
}
推荐阅读
- reactjs - PropTypes:如何检查对象的枚举?
- android - 使用Java的Appium(Android)中的ADB超时错误
- asp.net-core-mvc - 使用 Asp.net core 2.1 的 JWT 身份验证仅适用于 localhost
- python - Rasa nlu 模型不工作。AttributeError:“str”对象没有属性“load”
- loops - angular 和 ngrx :你能在循环中调度一个动作吗?
- java - Dagger 单例预加载
- android - 具有即时/(动态)功能模块的导航组件
- javascript - 使用 Vanilla JS 将事件和函数附加到动态元素
- javascript - Hapi 处理程序方法没有返回值
- sass - 在 gulp 中查看递归 scss 文件