I'm working on an application using Flutter SDK. When I use a TextField
widget, and I focus it, the underline becomes blue. I need to change this color to red, how can I do it?
Screenshot of what I need to change. I want just the underline to change, , not the label color.
To change underline color use the underline property of the Dropdown widget and then assign the Container widget with height and color property. Inside the Dropdown widget, and add the underline property and assign the Container widget. Inside the Container , add the color property and assign the color.
In Flutter, you can customize the color, thickness, and style (actually, there are only 2 stypes for underline: solid and none) of a TextFIeld's underline by using the parameters from the InputDecoration class listed below: enabledBorder. focusedBorder.
While these other answers may somehow work, you should definitely not use it. That's not the proper way to get a custom theme in Flutter.
A much more elegant solution is as followed :
final theme = Theme.of(context); return new Theme( data: theme.copyWith(primaryColor: Colors.red), child: new TextField( decoration: new InputDecoration( labelText: "Hello", labelStyle: theme.textTheme.caption.copyWith(color: theme.primaryColor), ), ), );
At the same time, if you just want to show an error (Red), use errorText
of InputDecoration
instead. It will automatically set the color to red.
You can also change its color by following ways.
Wrap your TextField
in Theme
and provide accentColor
Theme( data: Theme.of(context).copyWith(accentColor: Colors.red), child: TextField(), )
Using inputDecoration
property.
TextField( decoration: InputDecoration( focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.red), ), ), )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With