How to add red asterisk in label of TextFormField In Flutter
Using this code you can achieve that kind of styling in flutter.
TextField(
decoration: InputDecoration(
hintText: 'Ciao',
suffixText: '*',
suffixStyle: TextStyle(
color: Colors.red,
),
),
),
Related
How to change TextFormField hint label background color in flutter?
You can use backgroundColor propetry of TextStyle to change the background color of labelText or hintText:
TextFormField(
decoration: const InputDecoration(
hintText: 'Hint Text',
labelText: 'Label Text',
hintStyle: TextStyle(
backgroundColor: Colors.red, // Change background color for hint text
),
labelStyle: TextStyle(
backgroundColor: Colors.blue, // Change background color for label text
),
),
)
You can edit the hintStyle of InputDecoration
In the below image, the label text is aligned with the input field data.
How to align the label text with the prefix icon?
Below is the alignment i want!How to get this using TEXTFORMFIELD?
Please have a look
TextFormField(
style:
TextStyle(fontSize: 26.0, color: Colors.black),
decoration: InputDecoration(
prefix: Icon(Icons.email, size: 20,),
border: OutlineInputBorder(),
labelText: "Email",
)
),
output:
use in TextField and decoration in suffixText show text but need suffixText click event
TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white10,
hintText: 'Password',
hintStyle: TextStyle(color: Colors.white),
contentPadding: const EdgeInsets.all(24),
prefixIcon: Icon(Icons.lock, color: Colors.white),
suffixText: 'forget?'.toUpperCase(),
),
),
There is also an suffix property available in TextField. You can use it in place of suffixText and provide it either an GestureDetector or InkWell for the onTap method and give their child the Text Widget you are providing to suffixText.
suffix:GestureDetector(
onTap:(){},
child:Text("Your Text"),
),
Here is the code. I want to remove the black underline just below text, and currently the TextField is in edit mode:
TextField(
autofocus: true,
decoration: InputDecoration.collapsed(
hintText: "Search",
border: InputBorder.none,
),
maxLines: 1,
)
Try to give a TextStyle to your TextField widget. Your TextField is getting your default Theme's TextStyle.
TextField(
autofocus: true,
style: TextStyle(color: Colors.white, fontSize: 30),
decoration: InputDecoration.collapsed(
hintText: "Search",
border: InputBorder.none,
),
maxLines: 1,
)
In TextField widgets source code it states:
/// If null, defaults to the `subhead` text style from the current [Theme].
final TextStyle style;
You should use TextDecoration.none in decoration property.
Text(
'your txt',
style: TextStyle( decoration: TextDecoration.none),
)
I suspect it's something to do with the predictive text. The underlines disappear when you press the space bar to end the word you're typing; they then start appearing again when you start typing the next word. As suggested here, try setting TextInputType.visiblePassword; - this worked for me.
just code ...
TextFormField(
decoration: InputDecoration(
hintText: 'comment..',
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
contentPadding: EdgeInsetsDirectional.only(start: 10.0),
),
)
style:TextStyle(
decorationThickness: 0)
As stated in https://stackoverflow.com/a/57499189/445887
This is an accessibility feature (if you still see an underline after disabling it in TextStyle) from the Android keyboard.
Then input text is always underlined while typing use:
autocorrect: false,
enableSuggestions: false,
https://stackoverflow.com/a/69921656/10932271
Provide the following code inside the TextField widget and change the color according to the background color of a TextField. If the background is white provide white color which will make the underline invisible.
style: TextStyle(
fontSize: 16,
letterSpacing: 1,
decoration: TextDecoration.none,
decorationStyle: TextDecorationStyle.dotted,
decorationColor: Colors.white),
You have to add a "decoration:TextDecoration.none", like this:
Text(
"Don't forget",
style: TextStyle(
decoration: TextDecoration.none
)
)
#Immortal Dude is right that this is not the problem of textfield. Because when you click somewhere else after typing in the textfield, the underline automatically remove from the text.
You just need to set the keyboard type:
keyboardType: TextInputType.visiblePassword,
I have a TextField like this, where the input text and the hint text are sized differently.
TextField(
style: Theme.of(context).textTheme.subhead.copyWith(
fontSize: 70.0,
),
decoration: InputDecoration(
hintText: 'Enter a number',
hideDivider: true,
hintStyle: TextStyle(
color: Colors.grey[500],
fontSize: 25.0,
),
),
);
While the user input text is centered in my parent container, the hintText is not (top has more space than the bottom). Is there a way to vertically center the hint text as well?
The reason the hint text is not the same size as the input text is that it takes up more space than the green Container has, so it looks like Enter a nu..., which isn't very user friendly. (So alternatively, is there a way to have a newline in the hintText?)
I see this is over 2 years old but in case others run into this problem:
InputDecoration has the property contentPadding.
TextField(
decoration: InputDecoration(
hintText: 'Hint Text',
contentPadding: EdgeInsets.all(10.0),
),
);
Add textAlignVertical: TextAlignVertical.center, in your TextField.
Note: make sure you are not modifying it with other Containers or anything else & if you do then check those widgets as well.
TextField(
textAlignVertical: TextAlignVertical.center,
),
new TextField(
decoration: new InputDecoration(
hintText: 'your hint',
),
textAlign: TextAlign.center,
)
textAlign: TextAlign.center will make your hint appear in the center.
Below is the solution for your problem:
Container(
color: Colors.red,
width: 1000,
height: 500,
alignment: Alignment.center,
child: TextFormField(
keyboardType: TextInputType.emailAddress,
autofocus: false,
style: new TextStyle(fontSize: 20),
decoration: InputDecoration(
hintText: 'Email', hintStyle: TextStyle(color: Color(0xff777777))),
),
)