The frosted glass effect is a cool UI concept in the flutter that makes our UI look more attractive. It is basically a blurred-out overlay with reduced opacity, to distinguish or diminish a certain view. This feature really looks good but it affects the app’s performance. So, let’s see how can we implement the frosted glass effect in flutter.
Check out more about our Flutter app development services.
It is pretty easy to implement in the flutter by using the BackdropFilter() widget along with the ImageFilter class. BackdropFilter() widget in Flutter is used to blur images, containers, or many other widgets as well. It works both on iOS and android. It is used to highlight the content which needs more focus and blur the content that needs less focus.
Step 1: Create a simple flutter project.
Step 2: Create a container and wrap it up with BackdropFilter and ClipRect. Now add a property of backdrop filter, filter: ImageFilter.blur, and add sigma X, sigmaY. Higher the sigmaX and sigmaY, the higher the blur.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
new Center( child: new ClipRect( child: new BackdropFilter( filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), child: new Container( width: 200.0, height: 200.0, decoration: new BoxDecoration( borderRadius: BorderRadius.circular(20.0), color: Colors.grey.shade200.withOpacity(0.5)), child: Center(child: Text("Censored",style: TextStyle(fontSize: 30),)), ), ), ), ) |
Step 3: Stack up this widget block above an Image to see the effect in work. I used the flutter logo as an image.
1 2 3 4 5 6 7 8 9 |
Center( child: Container( height: 200, width: 200, decoration: new BoxDecoration( borderRadius: BorderRadius.circular(20.0), ), child: FlutterLogo(), )) |
That’s it, you can see a blur effect on your image.
Full code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Demo"), ), body: Stack( children: [ Center( child: Container( height: 200, width: 200, decoration: new BoxDecoration( borderRadius: BorderRadius.circular(20.0), ), child: FlutterLogo(), )), new Center( child: new ClipRect( child: new BackdropFilter( filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), child: new Container( width: 200.0, height: 200.0, decoration: new BoxDecoration( borderRadius: BorderRadius.circular(20.0), color: Colors.grey.shade200.withOpacity(0.5)), child: Center(child: Text("Censored",style: TextStyle(fontSize: 30),)), ), ), ), ), ], ), ); } } |
Thanks for reading this article.
If I got something wrong, let me know in the comments. I would love to improve.
Reference Link: https://mightytechno.com/frosted-glass-effect-in-flutter-app/
You can also checkout more blogs here: https://mobikul.com/blog/