【问题标题】:How to remove the elevation (shadow) in a SearchDelegate?如何删除 SearchDelegate 中的高程(阴影)?
【发布时间】:2022-02-28 16:43:17
【问题描述】:

我想在使用SearchDelegate 时从搜索栏中删除阴影,但我找不到如何操作。有什么建议吗?

这基本上是所有的代码:

showSearch(
  context: context,
  delegate: CustomSearchDelegate(),
);

CustomSearchDelegate() 只包含一个空的搜索委托小部件/类。

【问题讨论】:

  • 你能把你当前的代码和小截图贴出来吗?
  • @MarianoZorrilla 编辑了我的帖子

标签: flutter


【解决方案1】:

在 Searchdelegate 类中添加这个:

 @override
  ThemeData appBarTheme(BuildContext context){
    assert(context != null);
    final ThemeData theme = Theme.of(context);
    assert(theme != null);
    return theme.copyWith(
      primaryColor: Colors.grey[50],

    );
  }

这是主应用主题:

MaterialApp(
      theme: ThemeData(
        backgroundColor: Colors.white,
        appBarTheme: AppBarTheme(elevation: 0.0), //This is important
      title: 'Flutter Demo',
      home: MyHomePage(),
    );

在您的ThemeData() 中进行相应更改并添加appBarTheme: AppBarTheme(elevation: 0.0), 以删除海拔和 SearchDelegate 主题,因为它是您的搜索委托类,它将确保您的 Material 应用程序的 ThemeData 中定义的海拔得到实施。

注意:我猜,在 ThemeData 中设置的高度也会影响整个应用程序中其他页面中应用栏的高度。

结果: Output image

【讨论】:

  • 非常感谢,这成功了!它没有改变我其他页面中的应用栏高度,所以这也很好!
【解决方案2】:
@override
  ThemeData appBarTheme(BuildContext context) {
    return super.appBarTheme(context).copyWith(
      appBarTheme: super.appBarTheme(context).appBarTheme.copyWith(
        elevation: 0.0,
      ),
    );
  }

【讨论】:

    猜你喜欢
    • 2023-02-06
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多