How to add red asterisk in label of TextFormField In Flutter
5,256
Solution 1
Simplest way, but not exactly equals:
TextField(
decoration: InputDecoration(
hintText: 'Ciao',
suffixText: '*',
suffixStyle: TextStyle(
color: Colors.red,
),
),
),
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),
),
),
),
Solution 2
Try these two files I had same requirement.
Just add attribute isMandate: true
in CInputDecoration and use CTextField.
CTextField(
...
decoration: new CInputDecoration(
isMandate: true,
...
))
https://github.com/sumit1954/Flutter/blob/master/CInputDecorator.dart https://github.com/sumit1954/Flutter/blob/master/CTextField.dart
Author by
Zeeshan Ansari
Updated on December 15, 2022Comments
-
Zeeshan Ansari over 1 year
As we are not able to make widget like RichText/Text Span For styling TextFormField,
Can anyone help me out regarding this...
Now Getting:-
Expected Result:-
How we can achieve a result like this?
-
Elijan9 about 4 yearsWelcome at Stackoverflow. While your answer may help to achieve what the original poster wants, your post offers no guidance or explanation that may help others seeking a similar solution. Please include more context in your reply, see How do I write a good answer?
-
Chung almost 4 yearsBut when i use your two customized files, validator of TextFiled disappear?
-
gowthaman C over 2 yearscan you share null safety file
-
gowthaman C over 2 yearscan you share null safety file
-
gowthaman C over 2 yearscan you share null safety file
-
Phúc Nguyễn almost 2 yearsThe label param takes a text, not a widget.