flutter animation acceleration or speed change

Issue

how can we change the acceleration of the animation in duration or make some stops in it’s duration?
for example scale a widget to 2x in 3 second than stop for a second than scale it for another 2x in 3 seconds.

AnimationController_anim1 = AnimationController(
  vsync: this,
  duration: Duration(milliseconds: 3000),
);
ScaleTransition(
                scale: Tween(begin: 1.0, end: 2).animate(_anim1),
                child: ClipRect(
                  clipBehavior: Clip.hardEdge,
                  child: OverflowBox(
                    maxHeight: 70,
                    maxWidth: 70,
                    child: Center(
                      child: Container(
                        decoration: BoxDecoration(
                          color: Colors.white38,
                          shape: BoxShape.circle,
                        ),
                      ),
                    ),
                  ),
                ),
              )

Solution

as I searched around, I found the solution in two different ways, one is what Amir Hossein Mirzaei mentioned, which use Curve class, it is very powerful and flexible but it is a bit complicated and hard solution (beside being so powerful), but the second way is more handy which handled by TweenSequence as bellow :
1 – make an animation controller 2- make TweenSequence and add TweenSequenceItem for each step of animation 3- set it to widget

AnimationController _anim1 = AnimationController(
  vsync: this,
  duration: Duration(milliseconds: 8500),
  //reverseDuration: Duration(milliseconds: 1000),
)..repeat(reverse: true);


Animation<double> _animation1 = TweenSequence(
  <TweenSequenceItem<double>>[
    TweenSequenceItem<double>(
      tween: Tween<double>(begin: 1.0, end: 1.5),
      weight: 23.5,
    ),
    TweenSequenceItem<double>(
      tween: ConstantTween<double>(1.5),
      weight: 6.0,
    ),
    TweenSequenceItem<double>(
      tween: Tween<double>(begin: 1.5, end: 2.0),
      weight: 23.5,
    ),
    TweenSequenceItem<double>(
      tween: ConstantTween<double>(2.0),
      weight: 47.0,
    ),
  ],
).animate(_anim1);


ScaleTransition(
scale: _animation1,
child: ClipRect(
  clipBehavior: Clip.hardEdge,
  child: OverflowBox(
    maxHeight: 70,
    maxWidth: 70,
    child: Center(
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white38,
          shape: BoxShape.circle,
        ),
      ),
    ),
  ),
),
)

Answered By – Mohammad Hadi

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *