Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - How to change TextField hint color?

I'm a bit confused how to change the hint color of the textfield. Someone can guide me how to do it.Thanks

child: TextField(    style: TextStyle(fontSize: 20),    decoration: InputDecoration(                   hintText: "Password",                   border: new OutlineInputBorder(                             borderSide: new BorderSide(                               color: Colors.teal,                             ),                           ),                    prefixIcon: const Icon(                             Icons.security,                             color: Colors.white,                           ),                 ),    ), 
like image 533
kelvincer Avatar asked Dec 08 '18 02:12

kelvincer


People also ask

How do I change the color of a TextField hint?

Step 2: Inside the TextField widget, add the decoration parameter and assign the InputDecoration widget. Step 3: Inside the InputDecoration widget, add the hintStyle parameter and assign the TextStyle widget. Step 4: Inside the TextStyle , add color parameter and set the color of your choice.

How do you add hint to TextField in Flutter?

By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.

How do you change the color of the TextField underline?

You can change the TextField underline color globally by defining the inputDecorationTheme and then adding the UnderlineInputBorder widget. Inside the UnderlineInputBorder widget, you can specify which type of border you want to change. for example, enabledBorder , focusedBorder , and so on, and then assign the color.


2 Answers

You can do with hintStyle: in InputDecoration

TextField(         style: TextStyle(fontSize: 20),         decoration: InputDecoration(           hintText: "Password",           hintStyle: TextStyle(fontSize: 20.0, color: Colors.redAccent),           border: OutlineInputBorder(             borderSide: BorderSide(               color: Colors.teal,             ),           ),           prefixIcon: const Icon(             Icons.security,             color: Colors.white,           ),         ),       ), 
like image 123
anmol.majhail Avatar answered Sep 18 '22 18:09

anmol.majhail


As an addition to the accepted answer, to update the focused hint decoration you have to update the app's Theme. enter image description here

@override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Flutter Demo',       theme: ThemeData(           primaryColor: Colors.white,           inputDecorationTheme: const InputDecorationTheme(             labelStyle: TextStyle(color: Colors.black),             hintStyle: TextStyle(color: Colors.grey),           )),       home: MainScreen(),     );   } 
like image 33
Andrei Neacsu Avatar answered Sep 20 '22 18:09

Andrei Neacsu