飞镖 – 在颤动中更改TextField的下划线[复制]

前端之家收集整理的这篇文章主要介绍了飞镖 – 在颤动中更改TextField的下划线[复制]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Changing EditText bottom line color with appcompat v7                                    23个
我正在使用Flutter SDK开发应用程序.当我使用 TextField小部件时,我将其聚焦,下划线变为蓝色.我需要将此颜色更改为红色,我该怎么办?

我需要改变的截图.我只想改变下划线,而不是标签颜色.

解决方法

虽然这些其他答案可能以某种方式起作用,但您绝对不应该使用它.
这不是在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),),);

同时,如果您只想显示错误(红色),请改用InputDecoration的errorText.它会自动将颜色设置为红色.

猜你在找的Flutter相关文章