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

Mat*_*ias 10 colors textcolor dart flutter flutter-layout

我设法改变了hintStyle-color

提示风格

@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),
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述

我怎样才能正确地改变课堂textcolor上的内容SearchDelegate

Car*_*iel 14

使用 SearchDelegate,您可以自定义搜索的文本提示值和颜色以及查询的颜色和大小。为了达成这个:

搜索的文本提示值 --> 您可以覆盖searchFieldLabel,它是一个字符串。

@override
String get searchFieldLabel => 'Your Custom Hint Text...';
Run Code Online (Sandbox Code Playgroud)

搜索的颜色 --> 您可以使用 Theme 类的hintColor 属性覆盖:

@override
  ThemeData appBarTheme(BuildContext context) {
    return Theme.of(context).copyWith(
      hintColor: Colors.white,
    );
  }
Run Code Online (Sandbox Code Playgroud)

查询的文本颜色和大小 --> 您需要重写委托的appBarTheme方法并更改您需要的内容。要更改查询的文本颜色,请设置header6textTheme

@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;
}
Run Code Online (Sandbox Code Playgroud)


dev*_*tgs 0

参考问题评论中的讨论, appBarThemetextTheme属性允许更改颜色。示例代码信用@Matthias

代码:

textTheme: TextTheme(title: TextStyle( color: Colors.white, fontSize: 18,),),

  • 那是我的错@Aleksey Potapov。他在问题下的评论部分指出了这一点,因为它解决了我的问题,所以我让他写一个答案,以便我可以接受。 (2认同)