Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter TextField change Icon color when selected

Tags:

flutter

dart

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'
  )
)
like image 973
Marco Zielbauer Avatar asked Feb 21 '19 08:02

Marco Zielbauer


People also ask

How do you change the color of a selected icon in Flutter?

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 do I use TextFormField in Flutter?

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.

How do you change the color of the TextField in Underlight in Flutter?

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

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,
  ),
),

Live Demo

like image 120
NearHuscarl Avatar answered Sep 17 '22 12:09

NearHuscarl


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,
  ),
),
like image 44
Shrijan Regmi Avatar answered Sep 18 '22 12:09

Shrijan Regmi