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?
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.
In order to create blur effects in Flutter, you can use BackdropFilter and ImageFilter. blur.
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.
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:
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), ), ), ), ), )
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