【问题标题】:Overriding appBarTheme in SearchDelegate在 SearchDelegate 中覆盖 appBarTheme
【发布时间】:2021-04-19 10:32:29
【问题描述】:

我想改变 SearchDelegate 的 appbar 的颜色。所以我做了以下

class DataSearch extends SearchDelegate<String> {
  var suggestionList = [];
  @override
  ThemeData appBarTheme(BuildContext context) {
    assert(context != null);
    final ThemeData theme = Theme.of(context);
    assert(theme != null);
    return ThemeData(
        primaryColor: createMaterialColor(Color(0xFF0E2848)));
  }

这样做的问题是状态栏中的文本和搜索文本是黑色的。我希望它是白色的。所以我尝试改变亮度。

class DataSearch extends SearchDelegate<String> {
  var suggestionList = [];
  @override
  ThemeData appBarTheme(BuildContext context) {
    assert(context != null);
    final ThemeData theme = Theme.of(context);
    assert(theme != null);
    return ThemeData(
        primaryColor: createMaterialColor(Color(0xFF0E2848)),
        brightness: Brightness.dark);
  }

但整个屏幕似乎是暗模式,所有列表图块也处于暗模式。

如何让文本和状态栏变成白色。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    以下工作。仅在 appBar(最后一行)内将亮度设置为暗。

    class DataSearch extends SearchDelegate<String> {
      var suggestionList = [];
      @override
      ThemeData appBarTheme(BuildContext context) {
        assert(context != null);
        final ThemeData theme = Theme.of(context);
        assert(theme != null);
        return ThemeData(
            primaryColor: Colors.blue,
            textTheme: TextTheme(headline6: TextStyle(color: Colors.white)),
            textSelectionTheme: TextSelectionThemeData(cursorColor: Colors.white),
            inputDecorationTheme: InputDecorationTheme(
                hintStyle: Theme.of(context)
                    .textTheme
                    .headline6
                    .copyWith(color: Colors.white)),
            appBarTheme: AppBarTheme(brightness: Brightness.dark));
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-18
      • 2023-03-07
      • 1970-01-01
      • 2012-12-17
      • 2019-10-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 2012-01-28
      相关资源
      最近更新 更多