Skip to main content

Command Palette

Search for a command to run...

BackdropFilter widget and Attributes

Published
2 min read
BackdropFilter widget and Attributes
V

"Hello World, I'm Vinit Mepani, a coding virtuoso driven by passion, fueled by curiosity, and always poised to conquer challenges. Picture me as a digital explorer, navigating through the vast realms of code, forever in pursuit of innovation.

In the enchanting kingdom of algorithms and syntax, I wield my keyboard as a magical wand, casting spells of logic and crafting solutions to digital enigmas. With each line of code, I embark on an odyssey of learning, embracing the ever-evolving landscape of technology.

Eager to decode the secrets of the programming universe, I see challenges not as obstacles but as thrilling quests, opportunities to push boundaries and uncover new dimensions in the realm of possibilities.

In this symphony of zeros and ones, I am Vinit Mepani, a coder by passion, an adventurer in the digital wilderness, and a seeker of knowledge in the enchanting world of code. Join me on this quest, and let's create digital wonders together!"

The BackdropFilter widget in Flutter is used to apply filter effects to its child widget, typically used to blur or apply color effects to the background. It's commonly used to create visually appealing effects such as blurring the background behind a dialog or overlaying color filters on images.

Attributes:

  1. filter (ui.ImageFilter):

    • The filter to apply to the child widget. It's typically a ui.ImageFilter object representing the desired filter effect, such as ui.ImageFilter.blur() for blurring.
  2. child (Widget):

    • The widget on which the filter effect should be applied.

Example:

import 'package:flutter/material.dart';

class BackdropFilterExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('BackdropFilter Widget Example'),
      ),
      body: Center(
        child: Stack(
          fit: StackFit.expand,
          children: <Widget>[
            Image.network(
              'https://via.placeholder.com/400',
              fit: BoxFit.cover,
            ),
            Center(
              child: Container(
                width: 200,
                height: 200,
                child: BackdropFilter(
                  filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
                  child: Center(
                    child: Text(
                      'Blurry Text',
                      style: TextStyle(
                        fontSize: 24,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

void main() {
  runApp(MaterialApp(
    home: BackdropFilterExample(),
  ));
}

Explanation:

  • In this example, a BackdropFilter widget is used to apply a blur effect to its child widget.

  • The child widget is a Text widget displaying "Blurry Text".

  • The BackdropFilter widget is wrapped around the Text widget, and the filter attribute is set to ImageFilter.blur(sigmaX: 5, sigmaY: 5) to create a blur effect with a sigma value of 5 in both horizontal and vertical directions.

  • As a result, the text appears blurry, creating a visually appealing effect on top of the background image.

More from this blog

Vinit Mepani (Flutter Developer)

270 posts

"Vinit Mepani, passionate coder! Dive into my Dart and Flutter journey on the blog. Let's master these tech wonders together. Happy coding! 🚀"