我正在使用Ffltter SDK开发一个应用程序.当我使用TextField小部件并将其聚焦时,下划线变为蓝色.我需要把这个 colored颜色 改成红色,怎么做好呢?

关于我需要更改的内容的屏幕截图.我只想把下划线改一下,, not the label color.

Screenshot of what I need to change. (I want the underline to change, not the label color)

推荐答案

虽然这些其他答案可能会以某种方式奏效,但你绝对应该not%使用它. 这不是在FLUTH中获得自定义主题的正确方式.

下面是一个更优雅的解决方案:

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.它会自动将 colored颜色 设置为红色.

Flutter相关问答推荐

Flutter ReorderableListView在可滚动父级中无法完美工作

如何防止alert 对话框在收到通知时出现在某个flutter页面中

手势捕获的异常:类型';Double';不是类型转换中类型';Double';的子类型

为什么我的PIN字段在第一次打字时不显示数字?

如何将Visual Studio代码中Flutter 应用的包名从com.example.XXX更改为Play Store中受限制的包名称

带有图标抖动的自定义下拉按钮

如何使 dart 函数变得通用?

如何在flutter中更改showModalBottomSheet小部件中CheckboxListTile小部件的值?

Dart:未捕获错误:RangeError(索引):索引超出范围:索引应小于 7:7

显示图像的放大部分

Flutter开发中,如何通过'nfc_manager'插件在Android设备上避免默认的New Tag Scanned弹出窗口?

如何计算 Firestore 集合中的文档数量?

Dart 撕掉 const 构造函数

为什么轮播加载图片很慢?

如何从 Firebase `get()` 获取 `DocumentReference`

如何在 flutter 中更改日期 Select 器 colored颜色 ?

Flutter Web Responsiveness 效率不高

我收到这个错误我无法解决

在自动完成中 Select 值后保持键盘焦点

Flutter GetX:Get.put 在 Widget 中的什么位置?