How can I change the color of an string-input in a TextField?
FlutterDartFlutter Problem Overview
I am working in the styles of my app, i am not able to change the color of the input of the TextField
, there isn't any property to change it.
Theme(
data: new ThemeData(
hintColor: Colors.white
),
child:
TextField(
focusNode: _focusUsername,
controller: _controller,
decoration: InputDecoration(
border: InputBorder.none,
fillColor: Colors.grey,
filled: true,
hintText: 'Username',
))),
Flutter Solutions
Solution 1 - Flutter
You can assign a TextStyle
TextField(
style: TextStyle(color: Colors.white),
...
)
https://docs.flutter.io/flutter/painting/TextStyle-class.html
Solution 2 - Flutter
In the example bellow, text is 'red' and the background of the TextField is 'orange'.
TextField(
style: TextStyle(color: Colors.red),
decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)
Is that what you mean?
If you want to do it generically through the app's theme, it's indeed tricky. It's probably going to be something like that:
theme: ThemeData(
textTheme: TextTheme(
bodyText1: TextStyle(color: Colors.black),
bodyText2: TextStyle(color: Colors.black),
button: TextStyle(color: Colors.black),
caption: TextStyle(color: Colors.black),
subtitle1: TextStyle(color: Colors.red), // <-- that's the one
headline1: TextStyle(color: Colors.black),
headline2: TextStyle(color: Colors.black),
headline3: TextStyle(color: Colors.black),
headline4: TextStyle(color: Colors.black),
headline5: TextStyle(color: Colors.black),
headline6: TextStyle(color: Colors.black),
),
inputDecorationTheme: InputDecorationTheme(
fillColor: Colors.orange,
filled: true,
)
)
Solution 3 - Flutter
To change it in ThemeData I used:
ThemeData(
textTheme: TextTheme(subtitle1: TextStyle(color: Colors.grey)),