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.
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),
),
),
)
],
),
);
}
}
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.
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.
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.
(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() .
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.
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.
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:
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.
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'),
),
),
),
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With