Last active
September 30, 2019 09:15
-
-
Save trietbui85/dc84cf6488d9defea437b702b13e2749 to your computer and use it in GitHub Desktop.
Blur multiple widgets. The correct Widget tree must be: Stack > [Widget1ToBlur, Widget2ToBlur, …, Positioned > ClipRect > BackdropFilter]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright (c) 2019 - Bui Minh Triet - [email protected] - http://fluttervn.com */ | |
double _sigmaX = 0.0; // from 0-10 | |
double _sigmaY = 0.0; // from 0-10 | |
double _opacity = 0.1; // from 0-1.0 | |
double _width = 350; | |
double _height = 300; | |
double _blurWidth = _width / 2; | |
double _blurHeight = _height / 2; | |
Stack( | |
children: <Widget>[ | |
Image.asset( | |
'assets/images/background.jpg', | |
width: _width, | |
height: _height, | |
fit: BoxFit.cover, | |
), | |
FlutterLogo(size: 80, colors: Colors.red), | |
Positioned( | |
top: 0, | |
left: 0, | |
width: _blurWidth, | |
height: _blurHeight, | |
// Note: without ClipRect, the blur region will be expanded to full | |
// size of the Image instead of custom size | |
child: ClipRect( | |
child: BackdropFilter( | |
filter: ImageFilter.blur(sigmaX: _sigmaX, sigmaY: _sigmaY), | |
child: Container( | |
color: Colors.black.withOpacity(_opacity), | |
), | |
), | |
), | |
) | |
], | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment