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

时间:2020-06-11 10:43:02

标签: flutter dart colors flutter-layout textcolor

我设法更改了 public class Product { public string name; public double price; public double quantity; public Product(string name, double price, int quantity) { this.Name = name; this.Price = price; this.Quantity = quantity; } ... public double Price { get { return this.price; } set { this.price = value; } } ... 颜色

hintstyle

hintStyle

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

enter image description here

如何正确更改@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), ), ); } 类中的textcolor

4 个答案:

答案 0 :(得分:2)

在应用headline6中更改ThemeData文本样式:

MaterialApp(
      theme: ThemeData(
      textTheme: TextTheme(
          headline6: TextStyle(color: 'Your Prefered Color'))
      ),
      home: Home()
    );

答案 1 :(得分:1)

使用SearchDelegate可以自定义搜索的文本提示值和颜色以及查询的颜色和大小。要实现这一目标:

搜索的文本提示值和颜色->您可以覆盖 searchFieldLabel searchFieldStyle ,第一个是String,第二个是TextStyle:

@override
String get searchFieldLabel => 'Your Custom Hint Text...';

@override
TextStyle get searchFieldStyle => TextStyle(
    color: Colors.white,
    fontSize: 18.0,
  );

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

@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;
}

答案 2 :(得分:1)

所有这些关于 textTheme 属性的答案都会影响搜索页面其他部分的 Text 小部件。所以你最终会在浅色主题中得到一些透明的文本,因为文本颜色已经与背景混合了。

所以这是一个不完整的解决方案

答案 3 :(得分:-1)

参考问题注释中的讨论,appBarTheme的{​​{1}}属性允许更改颜色。 示例代码积分@Matthias

代码:

textTheme