While these other answers may somehow work, you should definitely not use it.
That's not the proper way to get a custom theme in Flutter.
A much more elegant solution is as followed :
final theme = Theme.of(context);
return new Theme(
data: theme.copyWith(primaryColor: Colors.red),
child: new TextField(
decoration: new InputDecoration(
labelText: "Hello",
labelStyle: theme.textTheme.caption.copyWith(color: theme.primaryColor),
),
),
);
At the same time, if you just want to show an error (Red), use errorText
of InputDecoration
instead. It will automatically set the color to red.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…