I would like to create a scrolling counter and I'm wondering on how to implement this in flutter.
I wanted to do this in a project, so I create an implicit animation widget, called AnimatedFlipCounter
, that achieves similar effect.
I have published it as a package: https://pub.dev/packages/animated_flip_counter
Usage:
AnimatedFlipCounter(
duration: Duration(milliseconds: 500),
value: _value, /* pass in a number like 2014 */
)
Decimals:
AnimatedFlipCounter(
value: _value,
fractionDigits: 2, // decimal precision
suffix: "%",
textStyle: TextStyle(
fontSize: 40,
color: _value >= 0 ? Colors.green : Colors.red,
),
)
i use tween animation with animation builder
IntTween(begin: 0, end: starredCount).animate(
CurvedAnimation(parent: animationController, curve: Curves.easeOut)
You should be implement below ways
class ValueChangeAnimationWidget extends StatefulWidget {
@override
ValueChangeAnimationWidgetState createState() =>
ValueChangeAnimationWidgetState();
}
class ValueChangeAnimationWidgetState
extends State<ValueChangeAnimationWidget> with TickerProviderStateMixin {
AnimationController controller;
Animation animation;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 1000), vsync: this);
final Animation curve =
CurvedAnimation(parent: controller, curve: Curves.easeOut);
animation = IntTween(begin: 0, end: 10).animate(curve)
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
controller.reverse();
}
if (status == AnimationStatus.dismissed) {
Navigator.pop(context);
}
});
}
@override
Widget build(BuildContext context) {
controller.forward();
return AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child) {
return Scaffold(
body: new Center(
child: Text(animation.value.toString(), style: TextStyle(fontSize: 48.0)),
));
});
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With