Blur Effect On Background Image Using Backdrop Filter In Flutter

admin_img Posted By Bajarangi soft , Posted On 10-10-2020

Flutter BackdropFilter widget is used to make amazing blurring effects on Images, Container and all the widgets. BackdropFilter widget is used with combination of ImageFilter class. It applies filter on current widget and makes the blur effect on beneath present widget. Supposedly we have a Image widget so we put the Image widget first than put the BackdropFilter widget as its child.

Blur Effect On Background Image Using Backdrop Filter In Flutter

Blur Effect On Background Image using Backdrop Filter
Complete Code For Blur Effect On Background Image using Backdrop Filter In Flutter
Main.dart

import 'package:flutter/material.dart';
import 'dart:ui';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.red[300],
                title: Text('Blur Background Image')),
            body: Center(

                child: Container(
                  constraints: BoxConstraints.expand(),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: NetworkImage("https://flutter-examples.com/wp-content/uploads/2020/02/dice.jpg"),
                          fit: BoxFit.cover)
                  ),
                  child: ClipRRect(
                    child: BackdropFilter(
                      filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
                      child: Container(
                        alignment: Alignment.center,
                        color: Colors.grey.withOpacity(0.1),
                        child: Text(
                          "Blur Background Image",
                          textAlign: TextAlign.center,
                          style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
                        ),
                      ),
                    ),

                  ),
                )
            )
        )
    );
  }
}

Related Post