13

I have tried to define the Input decoration to change the color of underline of input TextField. But it's not working. can anyone suggest what am i missing here ?

Here is the Code snippet :

decoration: InputDecoration( hintText: 'Username', hintStyle: TextStyle(color: Colors.white), border: new UnderlineInputBorder( borderSide: BorderSide(color: Colors.white, width: 1.0, style: BorderStyle.none ), ), 
2
  • I changes the border style to solid (BorderStyle.solid). But still it didn't work. Commented Jul 18, 2018 at 6:02
  • Same problem here. Unable to change the border color of TextField Commented Apr 3, 2019 at 8:41

7 Answers 7

11
decoration: InputDecoration( hintText: 'Username', hintStyle: TextStyle(color: Colors.white), enabledBorder: new UnderlineInputBorder( borderSide: BorderSide( color: Colors.white, width: 1.0, style: BorderStyle.none ), ), ), 

Just change border to enabledBorder. Hope this help!

Sign up to request clarification or add additional context in comments.

Comments

7

We have to use both enabledBorder and focusedBorder.

  • enabledBorder: It will work when TextField not having focus.
  • focusedBorder: It will work when TextField has the focus.
enabledBorder: new UnderlineInputBorder( borderSide: BorderSide( color: Colors.black ), ), // and: focusedBorder: new UnderlineInputBorder( borderSide: BorderSide( color: Colors.black ), ), 

Comments

2

You have to put widget hierarchy under MaterialApp.

class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter WebView Demo', theme: new ThemeData( primarySwatch: Colors.blue, ), home: new Container( **//put widget here.** )); } } 

Comments

2

Just used -:

decoration: InputDecoration( focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.cyan), ), ), 

it works for me :)

1 Comment

This only works for focused state and does nothing to the normal state.
1

You can wrap your TextField in Theme and change accentColor like:

Theme( data: Theme.of(context).copyWith(accentColor: Colors.red), child: TextField(), ) 

Comments

0

If you want change that blue line color, used this below code..it works

focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: Colors.grey) 

Comments

-1
 child: TextField( controller: email, enabled: true, keyboardType: TextInputType.emailAddress, decoration: InputDecoration( filled: true, fillColor: Color(0xFFF2F2F2), enabledBorder: new OutlineInputBorder( borderSide: new BorderSide(color: Colors.orange)), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.orange), ), hintText: ' Email ', icon: Icon( Icons.email, color: Colors.orange, size: 30.0, ), ) ) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.