我想在 InputDecoration
labelText 中添加星号并更改它的颜色(如红色),以便用户轻松理解此字段是必需的。
TextField(
autofocus: true,
controller: _nameCtrlr,
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Name *",
))
像这张图片的预期结果 Sample Image
最佳答案
您可以像这样使用 Rich Text Widget
RichText getRequiredLabel(String fieldName) {
return RichText(
text: TextSpan(
style: TextStyle(color: Colors.black),
text: fieldName,
children: [
TextSpan(text: '*', style: TextStyle(color: Colors.red))
]));
}
关于flutter - 在 Flutter 的 Input Decoration 中为 labelText 添加 mandatory(*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57320684/