Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blurred Decoration Image in Flutter

Tags:

flutter

dart

I have the background of my app set like so:

class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return new MaterialApp(       home: new Container(         decoration: new BoxDecoration(           image: new DecorationImage(             image: new ExactAssetImage('assets/lol/aatrox.jpg'),             fit: BoxFit.cover,           ),         ),         child: new BackdropFilter(filter: new ImageFilter.blur(sigmaX: 600.0, sigmaY: 1000.0)),         width: 400.0,       ),     );   } } 

I'm wanting to blur the DecorationImage, so I added a BackdropFilter to the Container, but I don't see any change. What am I doing wrong?

like image 328
ErraticFox Avatar asked Mar 01 '18 17:03

ErraticFox


People also ask

How do you blur an image in Flutter?

Blur the Container with image as decoration. In below image, the left with no blur effect, the central is blur with sigmaX=5.0, sigmaY=5.0 , the right is same as central but with opacity=0.2 . Blur the Container with image as decoration.

How do you get the blur effect in Flutter?

In order to create blur effects in Flutter, you can use BackdropFilter and ImageFilter. blur.

How do I decorate an image in Flutter?

Certain Decoration classes in Flutter allow you to pass an image to use as a decoration. The image needs to be defined as a DecorationImage . It's quite common to use a DecorationImage for setting a background image. Not only defining the image to use, you can also adjust how the image should be painted.


2 Answers

You could do something like this, by blurring the container child instead.

class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return new MaterialApp(       home: new Container(         decoration: new BoxDecoration(           image: new DecorationImage(             image: new ExactAssetImage('assets/dog.png'),             fit: BoxFit.cover,           ),         ),         child: new BackdropFilter(           filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),           child: new Container(             decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),           ),         ),       ),     );   } } 

screenshot

like image 80
Made Baruna Avatar answered Oct 07 '22 19:10

Made Baruna


Screenshot:

enter image description here


Using Stack:

SizedBox(   height: 200,   child: Stack(     fit: StackFit.expand,     children: [       Image.asset('chocolate_image', fit: BoxFit.cover),       ClipRRect( // Clip it cleanly.          child: BackdropFilter(           filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),           child: Container(             color: Colors.grey.withOpacity(0.1),             alignment: Alignment.center,             child: Text('CHOCOLATE'),           ),         ),       ),     ],   ), ) 

Without using Stack:

Container(   height: 200,   width: double.maxFinite,   decoration: BoxDecoration(     image: DecorationImage(       image: ExactAssetImage("your_chocolage_image"),       fit: BoxFit.cover,     ),   ),   child: ClipRRect( // make sure we apply clip it properly     child: BackdropFilter(       filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),       child: Container(         alignment: Alignment.center,         color: Colors.grey.withOpacity(0.1),         child: Text(           "CHOCOLATE",           style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),         ),       ),     ),   ), ) 
like image 40
CopsOnRoad Avatar answered Oct 07 '22 20:10

CopsOnRoad