简体   繁体   English

如何删除 SearchDelegate 中的高程(阴影)?

[英]How to remove the elevation (shadow) in a SearchDelegate?

I want to remove the shadow from the search bar when using SearchDelegate but I can't find how to.我想在使用SearchDelegate时从搜索栏中删除阴影,但我找不到方法。 Any tips?有小费吗?

截屏

This is basically all the code:这基本上是所有的代码:

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

CustomSearchDelegate() just contains an empty search delegate widget/class. CustomSearchDelegate() 只包含一个空的搜索委托小部件/类。

Add this inside the Searchdelegate class:在 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],

    );
  }

and this to the main app theme:这是主要的应用程序主题:

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

Make changes accordingly in your ThemeData() and add the appBarTheme: AppBarTheme(elevation: 0.0), to remove the elevation and the SearchDelegate theme as it is your search delegate class which will ensure that the elevation defined in the ThemeData of your material app is implemented.在您的ThemeData()相应的更改并添加appBarTheme: AppBarTheme(elevation: 0.0),以删除高程和 SearchDelegate 主题,因为它是您的搜索委托类,它将确保您的材料应用程序的 ThemeData 中定义的高程是实施的。

Note: I guess, that the elevation set in the ThemeData will affect the elevation of the appbar in other pages all over the app too.注意:我猜,ThemeData 中设置的高度也会影响整个应用程序其他页面中应用栏的高度。

Result: Output image结果:输出图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM