本文介绍了如何在 Flutter 中的 TextFormField 标签中添加红色星号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于我们无法制作像 RichText/Text Span 这样的小部件来设置 TextFormField 的样式,
As we are not able to make widget like RichText/Text Span For styling TextFormField,
谁能帮我解决这个问题...
Can anyone help me out regarding this...
现在得到:-
预期结果:-
我们怎样才能达到这样的结果?
How we can achieve a result like this?
推荐答案
最简单的方法,但不完全等于:
Simplest way, but not exactly equals:
TextField(
decoration: InputDecoration(
hintText: 'Ciao',
suffixText: '*',
suffixStyle: TextStyle(
color: Colors.red,
),
),
),
或者创建一个自定义的TextField
来使用hint作为Widget而不是String
Or create a custom TextField
to use hint as Widget instead of String
您可以使用我的两个自定义文件:
You can use my two customized files:
TextFieldCustom(
hintText: Text.rich(
TextSpan(
text: 'FIRST NAME',
children: <InlineSpan>[
TextSpan(
text: '*',
style: TextStyle(color: Colors.red),
),
],
style: TextStyle(color: Colors.black54),
),
),
),
这篇关于如何在 Flutter 中的 TextFormField 标签中添加红色星号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!