尽管这些其他答案可能会以某种方式起作用,但您绝对不应使用它。这不是在Flutter中获得自定义主题的正确方法。
一个更优雅的解决方案如下:
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), ), ),);
同时,如果你只是想显示错误(红色),使用errorText的InputDecoration替代。它将自动将颜色设置为红色。



