Goal: Changing the color of the prefixIcon
next to the TextField
when clicking on the TextField
.
TextField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock_outline),
hintText: 'Username'
)
)
Steps to change icon button color in Flutter Locate the file where you have placed the IconButton widget. Inside the IconButton widget, add the color parameter and assign the color of your choice. Run the App.
How to Handle Input Data In TextFormField In Flutter Using Controller. To handle user input in TextFormField, create an object of TextEditingController class. Create a TextEditingController object like below and assign it to the controller property of TextFormField. Its object will hold the input data.
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.
In Flutter 2.5, you can set the active color of the icon in ColorScheme.primary
:
theme: ThemeData().copyWith(
colorScheme: ThemeData().colorScheme.copyWith(
primary: Colors.green,
),
),
As per flutter's update, accentColor property has been deprecated.
https://flutter.dev/docs/release/breaking-changes/theme-data-accent-properties
OLD:
theme: ThemeData(
accentColor: Colors.blue,
),
NEW:
theme: ThemeData(
colorScheme: ThemeData().colorScheme.copyWith(
secondary: Colors.blue,
),
),
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