In this tutorial, we’ll learn how to properly customize Flutter textformfield error text color by using practical Flutter code examples.
Introduction: Flutter Textformfield Error Text Color
Flutter textformfield error text is the text that is shown in the bottom left side of Flutter textformfield underline/outline border.
It is shown whenever a wrong input(implemented through proper logic) is given to the Flutter textformfield.
For instance, if the user input some blank space inside the email textformfield then we can show a Flutter textformfield error text. If you want to learn how to create this logic in Flutter textfield then click here. It will be same for textformfield as well.
In this post, we’ll see how to easily change Flutter textformfield error text color. So let’s get right into it.
Default Flutter Textformfield Error Text Color
For that, we’ve to use the decoration constructor of Flutter textformfield widget and pass it input decoration. Then by using the error text constructor of input decoration, we can easily set error text.
For demonstration, we’ll pass a simple string as this constructor only accepts a string. Let’s now see what the default Flutter textformfield error text color is. See below code:
TextFormField( decoration: InputDecoration( errorText: 'Default Error Text Color' ) )
![How To Change Flutter Textformfield Error Text Color [Detailed Flutter Guide] 3 flutter textformfield error text default color](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220925_061020-1-300x88.jpg)
Change Flutter Textformfield Error Text Color
In order to do that, we’ve to use the error style constructor of input decoration widget. It accepts a text style widget so we’ll pass it a Flutter text style widget. This text style has a color constructor. It accepts a color, so for demonstration, we’ll pass a green color to it. See below code:
decoration: InputDecoration( errorText: 'Custom Error Text Color', errorStyle: TextStyle(color: Colors.green))
![How To Change Flutter Textformfield Error Text Color [Detailed Flutter Guide] 4 flutter textformfield error text color](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220925_061146-1-300x88.jpg)
We can see that Flutter textformfield error text color is now customized.
So this is how you can easily give an error text a color of your choice. Hope you like this post.
The complete source code of Flutter textformfield error text with custom color is given in the next section.
Custom Flutter Textformfield Error Text Color Source Code
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Homepage(), ); } } class Homepage extends StatelessWidget { @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( body: Center( child: Padding( padding: EdgeInsets.symmetric(horizontal: 40), child: TextFormField( decoration: InputDecoration( errorText: 'Custom Error Text Color', errorStyle: TextStyle(color: Colors.green)), ))), )); } }
Conclusion
To conclude this tutorial, now you’ve a detailed practical knowledge of how to customize Flutter textformfield error text color. I’d love to have your feedback on this post.
I’d also love to see you visit my other tutorials on Flutter app development and Python programming as well. Thank you for reading this post.