Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Backdrop filter blur my entire app

I am trying to achieve a very similar effect to what was shown in the widget of the week video on flutter's channel: https://www.youtube.com/watch?v=dYRs7Q1vfYI#t=1m20s

On the right you see the desired result, on the left you see what's currently going on in my app. On the right my app, on the left the wanted result

The code I've been using is pretty similar to the one from the example video, using a Stack to position the Backdrop filter over my image. The rounded image and the blur over it are inside one widget, which will is placed inside another stack (along with the text at the bottom). Since I applied the filter only a small section of the image, I don't understand why entire app is blurred. Here's the code for the Image Widget:

Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size.width - 75;
    return Container(
      height: size,
      width: size,
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          Image(imageUri: "...", size: size - 30), // this is just a container with the image
          Positioned(
            top: 100,
            left: 100,
            bottom: 100,
            right: 100,
            child: BackdropFilter(
              filter: ImageFilter.blur(
                sigmaX: 5,
                sigmaY: 5,
              ),
              child: Container(
                color: Color(0x66FF0000),
              ),
            ),
          )
        ],
      ),
    );
  }
}
like image 328
Philip Feldmann Avatar asked Jun 01 '19 09:06

Philip Feldmann


People also ask

Can I use backdrop filter blur?

The backdrop-filter CSS property lets you apply graphical effects such as blurring or color shifting to the area behind an element. Because it applies to everything behind the element, to see the effect you must make the element or its background at least partially transparent.

How do you use BackdropFilter in flutter?

BackdropFilter is a widget that applies a filter to the current painted substance and afterward paints its child widget. Flutter will apply the filter to all spaces inside its parent widget's clip. That implies if there's no clip, the filter will be applied to the whole screen.

Does Firefox support backdrop filter?

While Firefox does not support the backdrop filter property, you can still test your web pages that use backdrop-filter. You can enable the property manually, however, just enabling it in your browser won't help, because it won't be enabled in your client's browser.

How do I blur the background of a picture in Firefox?

(2) There is also a Firefox-specific implementation that can work with any background graphic (e.g., the image drawn with Canvas API): using -moz-element() to copy the background and blur it with filter: blur() .

Why can't I see the effect of a background filter?

Because it applies to everything behind the element, to see the effect you must make the element or its background at least partially transparent. No filter is applied to the backdrop. A space-separated list of <filter-function> s or an SVG filter that will be applied to the backdrop.

How do I apply multiple filter-function s to a backdrop?

You can apply multiple <filter-function> s to a backdrop, like so: .element { backdrop-filter: grayscale(0.5) opacity(0.8) /* ...and on and on... */; } See the W3C Filter Effects Module Working Draft for acceptable values for each of the filter functions.

What is a backdrop-filter?

The backdrop-filter has the same effect as the filter property, except the filter effects are applied only to the background and instead of to the element’s content. Before backdrop-filter, the only way to add a filtered background was to add a separate “background” element, position it behind the foreground element (s) and filter it like so:

What is a background-filter in CSS?

The backdrop-filter property in CSS is used to apply filter effects ( grayscale, contrast, blur, etc) to the background/backdrop of an element. The backdrop-filter has the same effect as the filter property, except the filter effects are applied only to the background and instead of to the element's content.


2 Answers

It turns out the video is missing an important part from the documentation:

If there's no clip, the filter will be applied to the full screen.

So the solution is to wrap the filter into a ClipRect, as taken from the example:

ClipRect(  // <-- clips to the 200x200 [Container] below
        child: BackdropFilter(
          filter: ui.ImageFilter.blur(
            sigmaX: 5.0,
            sigmaY: 5.0,
          ),
          child: Container(
            alignment: Alignment.center,
            width: 200.0,
            height: 200.0,
            child: Text('Hello World'),
          ),
        ),
      ),
like image 146
Philip Feldmann Avatar answered Sep 27 '22 20:09

Philip Feldmann


Another solution in 2021:

Apply clipBehavior: Clip.hardEdge to parent of BackdropFilter

Container(
  clipBehavior: Clip.hardEdge,
  child: BackdropFilter(
    filter: ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0),
    child: Container(
      color: Colors.black.withOpacity(0.2),
    ),
  ),
)

Explanation:
clipBehavior: Clip.hardEdge means overflow: none
If no clip, filter will overflow upward (in widget tree) until they meet clip.

like image 35
hungtran273 Avatar answered Sep 27 '22 22:09

hungtran273