Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Motion blur in Flutter?

I have been using Google Flutter for a recent project. And was wondering if we can apply motion blur in the widget animation. It just makes animations more realistic and soothing. I couldn't find any resources available regarding this.

Has anyone given it a try?

like image 314
Sahaj Rana Avatar asked May 31 '26 06:05

Sahaj Rana


1 Answers

I just gave it a try myself. After finding nothing on the internet about this I came up with my own approach.

I have a spinning Image widget that has sharp edges and thus looks a bit ugly while rotating. I use a RotationTransition widget to animate its rotation.

RotationTransition(
      turns: Tween(begin: 1.0, end: 0.0).animate(
        CurvedAnimation(
          parent: animationController,
          curve: Curves.easeInOutQuad,
        ),
      ),
      child: ...,
),

As A child I put a Stack widget containing two FadeTransition widgets that each contain two Versions of the image. One is the default Image and one has the motion blur already applied to (in Photoshop).

Stack(
        children: [
          FadeTransition(
            opacity: Tween(begin: 1.0, end: 0.0).animate(
              CurvedAnimation(parent: animationController, curve: const FadeCurve(),
              ),
            ),
            child: Image.asset(
              "assets/images/image.png",
            ),
          ),
          FadeTransition(
            opacity: Tween(begin: 0.0, end: 1.0).animate(
              CurvedAnimation(parent: animationController, curve: const FadeCurve(),
              ),
            ),
            child: Image.asset(
              "assets/images/image_withMB.png",
            ),
          ),
        ],
      ),

Then I just created a custom Curve that changes the opacity in relation to the speed of the rotation.

class FadeCurve extends Curve {
  const FadeCurve();
  @override
  double transform(double t) {
    if (t <= 0.5) return pow(2 * t, 2).toDouble();
    return pow(2 - 2 * t, 2).toDouble();
  }
}

This of course only applies for images... and only static ones. But it might be exactly what you need.

like image 51
MindStudio Avatar answered Jun 02 '26 21:06

MindStudio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!