labelStyle property Null safety

TextStyle? labelStyle
final

The style to use for InputDecoration.labelText when the label is on top of the input field.

If labelStyle is a MaterialStateTextStyle, then the effective text style can depend on the MaterialState.focused state, i.e. if the TextField is focused or not.

When the InputDecoration.labelText is above (i.e., vertically adjacent to) the input field, the text uses the floatingLabelStyle instead.

If null, defaults to a value derived from the base TextStyle for the input field and the current Theme.

Note that if you specify this style it will override the default behavior of InputDecoration that changes the color of the label to the InputDecoration.errorStyle color or ThemeData.errorColor.

It's possible to override the label style for just the error state, or just the default state, or both.

In this example the labelStyle is specified with a MaterialStateProperty which resolves to a text style whose color depends on the decorator's error state.

To create a local project with this code sample, run:
flutter create --sample=material.InputDecoration.labelStyle.1 mysample

Implementation

final TextStyle? labelStyle;