Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter BackdropFilter for Appbar

Tags:

flutter

how can i use BackdropFilter in flutter for Appbar ? when i use that for the Appbarother widgets which they are into Scaffold blurred, not AppBar

for example:

BackdropFilter(
  filter: ImageFilter.blur(
      sigmaX: 5,
      sigmaY: 5
  ),

  child: AppBar(
      automaticallyImplyLeading: false,
      // Used for removing back button.
      elevation: 8.0,
      titleSpacing: 0.0,
      backgroundColor: theme.appMainColor,
      title: Stack(
        children: <Widget>[

        ],
      )),
),
like image 773
DolDurma Avatar asked Jun 08 '26 08:06

DolDurma


2 Answers

After searching web for a while and trying different combinations of widgets, I finally found the solution

    appBar: PreferredSize(
      child: Container(
        child: ClipRRect(
            child: BackdropFilter(
                filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
                child: Container(
                  //   width: MediaQuery.of(context).size.width,
                  //  height: MediaQuery.of(context).padding.top,
                  color: Colors.transparent,
                ))),
      ),
      preferredSize: Size(MediaQuery.of(context).size.width, 22),
    ),

Go nuts!!

like image 65
Sarthak Singhal Avatar answered Jun 11 '26 04:06

Sarthak Singhal


  1. Use the flexibleSpace parameter of the AppBar.
  2. Wrap the BackDropFilter with a ClipRect to prevent the blur from getting all over the screen.
  3. Make sure to create a Container as the child of the BackDropFilter

Here is the minimal code you'll need to add to your AppBar:

flexibleSpace: ClipRect(
  child: BackdropFilter(
    filter: ImageFilter.blur(sigmaX: 7, sigmaY: 7),
    child: Container(
      color: Colors.transparent,
    ),
  ),
),
like image 45
DaniyalAhmadSE Avatar answered Jun 11 '26 05:06

DaniyalAhmadSE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!