I added a new widget called AnimateWidget that allows for implicit without limitation.
Let's reproduce the AnimatedContainer example in official Flutter docs. (link here).
In Flutter AnimatedContainer example, we see:
Center(
child: AnimatedContainer(
duration: const Duration(seconds: 2),
curve: Curves.fastOutSlowIn,
width: selected ? 200.0 : 100.0,
height: selected ? 100.0 : 200.0,
color: selected ? Colors.red : Colors.blue,
alignment: selected ? Alignment.center : AlignmentDirectional.topCenter,
child: const FlutterLogo(size: 75),
),
),
With animateWidget, we simply use the Container` widget :
Center(
child: AnimatedWidget(
duration: const Duration(seconds: 2),
curve: Curves.fastOutSlowIn,
(context, animate) => Container(
// Animate is a callable class
width: animate.call(selected ? 200.0 : 100.0),
height: animate(selected ? 100.0 : 200.0, 'height'),
color: animate(selected ? Colors.red : Colors.blue),
alignment: animate(selected ? Alignment.center : AlignmentDirectional.topCenter),
child: const FlutterLogo(size: 75),
),
);
),
- Using the exposed
animate function, we set the animation start and end values.
- As the width and height are the same type (double), we need to add a name to distinguish them.
You can implicitly animate any type. Here we implicitly animated a double, Color, and Alignment values. If you want to animate two parameters of the same type, you just add a dummy name to distinguish them.
That's all, you are not limited to use a widget that starts with Animated prefix to use implicit animation.
Here is the full working example.
I added a new widget called AnimateWidget that allows for implicit without limitation.
Let's reproduce the
AnimatedContainerexample in official Flutter docs. (link here).In Flutter
AnimatedContainerexample, we see:With
animateWidget, we simply use theContainer` widget :animatefunction, we set the animation start and end values.That's all, you are not limited to use a widget that starts with Animated prefix to use implicit animation.
Here is the full working example.