Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I blur a widget in Flutter

Tags:

flutter

dart

blur

I need to blur a widget, for example, a simple Container. How do I blur it?

new Container(
  child: new Text('hello I am here'),
  height: 100.0,
  width: 100.0,
  color: Colors.red,
)

Consider the above Container.

like image 535
Pooja Patil Avatar asked Nov 16 '17 11:11

Pooja Patil


1 Answers

Here is sample code:

import 'dart:ui' as ui;

 Widget backdropFilterExample(BuildContext context, Widget child) {
    return Stack(
      fit: StackFit.expand,
      children: <Widget>[
        child,
        BackdropFilter(
          filter: ui.ImageFilter.blur(
            sigmaX: 8.0,
            sigmaY: 8.0,
          ),
          child: Container(
            color: Colors.transparent,
          ),
        )
      ],
    );
  }

Google also has sample code on:

https://api.flutter.dev/flutter/widgets/BackdropFilter-class.html

like image 63
Kristopher Andrews Avatar answered Oct 16 '22 20:10

Kristopher Andrews