On the image below the Demo Text label by default a little bit small. I tried to change labelSmall and labelMedium styles but it doesn’t work for that. What style is responsible for that?
Demo Text
labelSmall
labelMedium
3
You can use floatingLabelStyle in InputDecoration of the TextField
floatingLabelStyle
InputDecoration
TextField
Example:
TextField( decoration: InputDecoration( floatingLabelStyle: TextStyle( color: Colors.red, fontSize: 12 ), labelText: 'Demo Text', labelStyle: TextStyle( fontSize: 16 ) ), ),
You can set the style using the parameter floatingLabelStyle in decoration:. See the example below:
decoration:
TextField( decoration: InputDecoration( labelText: 'Enter your username', floatingLabelStyle: TextStyle(fontSize: 1) ), )
Take a look at the Flutter docs about TextField widget here: https://docs.flutter.dev/cookbook/forms/text-input
You can try this code:
var textStyle = const TextStyle( fontSize: 40.0, color: Colors.green,); /// StatefulBuilder( builder: (BuildContext context, StateSetter setState) { return TextField( onChanged: (value) { if (value.isEmpty) { setState(() { textStyle = const TextStyle( fontSize: 40.0, color: Colors.green, ); }); } else { setState(() { textStyle = const TextStyle( fontSize: 16.0, color: Colors.red, ); }); } }, decoration: InputDecoration( labelStyle: textStyle, floatingLabelStyle: const TextStyle( fontSize: 16.0, color: Colors.red, ), label: Text('Demo Text'), ), ); }, )
Here is the screenshot of when the TextField is Empty:
Here is the screenshot of when the TextField is NotEmpty or is active:
And when you make the TextField Empty it changes to your Empty style.
happy coding…
Click here to cancel reply.
3
Answers
You can use
floatingLabelStyle
inInputDecoration
of theTextField
Example:
You can set the style using the parameter
floatingLabelStyle
indecoration:
. See the example below:Take a look at the Flutter docs about TextField widget here: https://docs.flutter.dev/cookbook/forms/text-input
You can try this code:
Here is the screenshot of when the
TextField
is Empty:Here is the screenshot of when the
TextField
is NotEmpty or is active:And when you make the
TextField
Empty it changes to your Empty style.happy coding…