Flutter - 如何更改搜索委托(delegate)类中的文本颜色?

标签 flutter dart colors flutter-layout textcolor

我设法更改了 hintStyle -颜色

hintstyle

@override
ThemeData appBarTheme(BuildContext context) {
  return ThemeData(
    primaryColor: kPrimaryColor,
    primaryIconTheme: IconThemeData(
      color: Colors.white,
    ),
    inputDecorationTheme: InputDecorationTheme(
      hintStyle:
        Theme.of(context).textTheme.title.copyWith(color: Colors.white),
    ),
  );
}

但是,如果我在 appbar 搜索字段中输入一些内容,颜色仍然是黑色...

enter image description here

如何正确更改 textcolorSearchDelegate类(class)?

最佳答案

使用 SearchDelegate 您可以自定义搜索的文本提示值和颜色以及查询的颜色和大小。为达到这个:
搜索的文本提示值 --> 您可以覆盖作为字符串的 searchFieldLabel。

@override
String get searchFieldLabel => 'Your Custom Hint Text...';
搜索的颜色 --> 您可以使用 Theme 类的 hintColor 属性覆盖:
@override
  ThemeData appBarTheme(BuildContext context) {
    return Theme.of(context).copyWith(
      hintColor: Colors.white,
    );
  }
查询的文本颜色和大小 --> 您需要覆盖委托(delegate)的 appBarTheme 方法并更改您需要的内容。要更改查询的文本颜色,请将 textTheme 设置为 标题6 :
@override
ThemeData appBarTheme(BuildContext context) {
assert(context != null);
final ThemeData theme = Theme.of(context).copyWith(
  textTheme: TextTheme(
    headline6: TextStyle(
      color: Colors.white,
      fontSize: 18.0,
    ),
  ),
);
assert(theme != null);
return theme;
}

关于Flutter - 如何更改搜索委托(delegate)类中的文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62322535/

相关文章:

flutter - 如何知道图像是否在 Flutter 中的内存中?

api - http.dart HttpException:在收到完整的 header 之前,连接已关闭

Dart ,反射和源 map ?

dart - 增加构建 future 的延迟

android - 如何在应用程序重新启动之间保存和恢复 Flutter ListView 的滚动位置?

dart - Dart 是否支持通常被可选类型排除的构造?

c++ - OpenGL 三角形 strip 上不需要的颜色褪色问题。想要在三角形上获得统一的颜色

javascript - 在 JavaScript 中处理 HTML 颜色和透明度

powershell - 运行命令时自定义 powershell 背景颜色会恢复吗?

gradle - 使用Lateast gradle获取此警告:API 'variant.getMergeAssets()'已过时,已被 'variant.getMergeAssetsProvider()'取代