英文:
How to add red asterisk(*) in label of text field In Flutter
问题
在Flutter中如何在文本字段的标签中添加一个红色星号。
[请在这里查看我想要的效果][1]。我尝试过了,但是出现了错误。
[1]: https://i.stack.imgur.com/Inm31.jpg
Container(
width: 310,
child: CTextField(
decoration: new CInputDecoration(
isMandate: true,
labelText: '名字',
labelStyle: GoogleFonts.lato(
color: Color(0xffb0b0b0),
fontSize: 19,
letterSpacing: 0.5),
),
),
),
英文:
How to add a red asterisk in the label of the text field In Flutter.
Please see here to find what I want. I tried, but I am getting error.
Container(
width: 310,
child: CTextField(
decoration: new CInputDecoration(
isMandate: true,
labelText: 'First Name',
labelStyle: GoogleFonts.lato(
color: Color(0xffb0b0b0),
fontSize: 19,
letterSpacing: 0.5),
),
),
),
答案1
得分: 0
你可以尝试以下的代码:
SizedBox(
width: 310,
child: TextField(
decoration: InputDecoration(
label: RichText(
text: TextSpan(
text: 'Full Name',
style: const TextStyle(
color: Colors.grey),
children: [
TextSpan(
text: ' *',
style: TextStyle(
color: Colors.red,
)
)
]
),
),
),
floatingLabelBehavior:FloatingLabelBehavior.never,
),
)
英文:
You can try this code:
SizedBox(
width: 310,
child: TextField(
decoration: InputDecoration(
label: RichText(
text: TextSpan(
text: 'Full Name',
style: const TextStyle(
color: Colors.grey),
children: [
TextSpan(
text: ' *',
style: TextStyle(
color: Colors.red,
)
)
]
),
),
floatingLabelBehavior:FloatingLabelBehavior.never,
),
),
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论