After Material 3, default TextField border and label color (when focused) were changed to grey. So I needed to set my ThemeData as below. If the TextField is empty, there’s a hint inside it with light gray color, which is desired behaviour. When I focus the TextField the label is now red at the top of the TextField. The problem arrives when I unfocus it and the color of the label text remains red, whereas border color is light gray.
My desired behavior would be the label color turning light gray, instead of red. I know I can do it programmatically but I have several TextFields on my app rendering it unpractical. Let’s note that on material 2 it worked like desired just by setting primary color.
theme: ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.red,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
),
inputDecorationTheme: InputDecorationTheme(
floatingLabelStyle: TextStyle(color: Colors.red),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide()),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.red, width: 2),
),
),
textSelectionTheme: TextSelectionThemeData(cursorColor: Colors.red),
),
2
Answers
You can use
FocusScope
&&Focus
Widgets to handle this issue.Main Widget :
The reusable
TextFeild
widgetYou can use
InputDecoration()
directly inTextFeild
or separate it like this so you can reuse it (which is better)Hope that help you !!
This issue is interesting, I think I should add enableFloatingLabelStyle but in the meantime what occurs to me is to use the MaterialStateTextStyle to obtain the desired result.