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, ), ), ),
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.
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.
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.
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, ), ), ),
As an addition to the accepted answer, to update the focused hint decoration you have to update the app's Theme.
@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(), ); }
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