i want to change the unfocused Text field icon color.
through primary color i can change the focused icon color like the 2nd text field, i want to change the first one (the not clicked one).
i want to change it in the whole app, so i am using ThemeData in my main MaterialApp
ex: i want the unfocused text field icon color be purple and the focused one be red.
UPDATE: 08/JUN/19 i made an issue for flutter team as i thought this needs to be in flutter framework itself not a workaround it with foucs node Issue Link and looks like there is an PR for it PR Link
By using a FocusNode
to determine when the TextField
is unfocused, and then assign the color you desire to Icon()
of prefixicon
, and when focused show the default theme color :
FocusNode fieldNode = FocusNode();
Container(
padding: EdgeInsets.only(bottom: 20.0),
child: TextField(
focusNode: fieldNode,
textAlign: TextAlign.start,
decoration: InputDecoration(
hintText: 'account',
labelText: 'Label',
hasFloatingPlaceholder: true,
prefixIcon: Icon(Icons.account_circle,
color: fieldNode.hasFocus
? Theme.of(context).primaryColor
: Colors.purple)),
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.words,
controller: firstNameController,
),
),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.