Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make scrolling counter in flutter

I would like to create a scrolling counter and I'm wondering on how to implement this in flutter.

enter image description here

like image 785
Ravi Dhorajiya Avatar asked Jun 15 '19 06:06

Ravi Dhorajiya


3 Answers

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 */
)

AnimatedFlipCounter demo

Decimals:

AnimatedFlipCounter(
  value: _value,
  fractionDigits: 2, // decimal precision
  suffix: "%",
  textStyle: TextStyle(
      fontSize: 40,
      color: _value >= 0 ? Colors.green : Colors.red,
  ),
)

Decimal demo

like image 127
user1032613 Avatar answered Oct 17 '22 05:10

user1032613


i use tween animation with animation builder

IntTween(begin: 0, end: starredCount).animate(
      CurvedAnimation(parent: animationController, curve: Curves.easeOut)
like image 1
Murat Aslan Avatar answered Oct 17 '22 07:10

Murat Aslan


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();
  }
}
like image 1
Nikhil Vadoliya Avatar answered Oct 17 '22 06:10

Nikhil Vadoliya