简体   繁体   中英

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. Any tips?

截屏

This is basically all the code:

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

CustomSearchDelegate() just contains an empty search delegate widget/class.

Add this inside the Searchdelegate class:

 @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.

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.

Result: Output image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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