How to make scrolling counter in flutter

flutter scrollable example
flutter number picker
flutter animation
flutter animate number increase
flutter countdown timer
flutter scroll controller
flutter animated positioned example
flutter bounce animation

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.

Usage:

AnimatedFlipCounter(
   duration: Duration(milliseconds: 500),
   value: _value, /* pass in a number like 2014 */
   color: Colors.black,
   size: 100,
)

Source code:

Just copy and paste the following into a file, and use the AnimatedFlipCounter like above example.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AnimatedFlipCounter extends StatelessWidget {
  final int value;
  final Duration duration;
  final double size;
  final Color color;

  const AnimatedFlipCounter({
    Key key,
    @required this.value,
    @required this.duration,
    this.size = 72,
    this.color = Colors.black,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<int> digits = value == 0 ? [0] : [];

    int v = value;
    if (v < 0) {
      v *= -1;
    }
    while (v > 0) {
      digits.add(v);
      v = v ~/ 10;
    }

    return Row(
      mainAxisSize: MainAxisSize.min,
      children: List.generate(digits.length, (int i) {
        return _SingleDigitFlipCounter(
          key: ValueKey(digits.length - i),
          value: digits[digits.length - i - 1].toDouble(),
          duration: duration,
          height: size,
          width: size / 1.8,
          color: color,
        );
      }),
    );
  }
}

class _SingleDigitFlipCounter extends StatelessWidget {
  final double value;
  final Duration duration;
  final double height;
  final double width;
  final Color color;

  const _SingleDigitFlipCounter({
    Key key,
    @required this.value,
    @required this.duration,
    @required this.height,
    @required this.width,
    @required this.color,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TweenAnimationBuilder(
      tween: Tween(begin: value, end: value),
      duration: duration,
      builder: (context, value, child) {
        final whole = value ~/ 1;
        final decimal = value - whole;
        return SizedBox(
          height: height,
          width: width,
          child: Stack(
            fit: StackFit.expand,
            children: <Widget>[
              _buildSingleDigit(
                digit: whole % 10,
                offset: height * decimal,
                opacity: 1 - decimal,
              ),
              _buildSingleDigit(
                digit: (whole + 1) % 10,
                offset: height * decimal - height,
                opacity: decimal,
              ),
            ],
          ),
        );
      },
    );
  }

  Widget _buildSingleDigit({int digit, double offset, double opacity}) {
    return Positioned(
      child: SizedBox(
        width: width,
        child: Opacity(
          opacity: opacity,
          child: Text(
            "$digit",
            style: TextStyle(fontSize: height, color: color),
            textAlign: TextAlign.center,
          ),
        ),
      ),
      bottom: offset,
    );
  }
}

Handle scrolling, 1. Create an app with a list of items; 2. Instrument the app; 3. Write a test that scrolls through the list; 4. Run the test. Many apps feature lists of content, from email� SingleChildScrollView. A box in which a single widget can be scrolled. This widget is useful when you have a single box that will normally be entirely visible, for example a clock face in a time picker, but you need to make sure it can be scrolled if the container gets too small in one axis (the scroll direction).

i use tween animation with animation builder

IntTween(begin: 0, end: starredCount).animate(
      CurvedAnimation(parent: animationController, curve: Curves.easeOut)

Creating Scroll Animations in Flutter | by Kenneth Reilly, Build smooth scrolling animations from scratch with Flutter it had with a 1:1 value, and I wanted the gear to scroll counter-clockwise as though� Flutter: 15 Text Style Shadow, Gradient, Opacity, Stroke, Background Color, Spacing, Bold, Italic, etc; Solved: Flutter Text on Image or a Widget on Another – Overlay; Flutter Responsive Height and Width with Screen Size; 5 Ways to Make Scrollable Screen in Flutter; Solved: Digits Only Input Keyboard in Flutter – Only Numbers on Text Field

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();
  }
}

AnimatedList (Flutter Widget of the Week), Use AnimatedList to make your lists more dynamic. You can use it to animate your lists when Duration: 2:57 Posted: May 10, 2019 Instead, consider ListView or GridView, which combine scrolling, viewporting, and a layout model. To combine layout models (or to use a custom layout mode), consider using CustomScrollView . The static Scrollable.of and Scrollable.ensureVisible functions are often used to interact with the Scrollable widget inside a ListView or a GridView .

Flutter - Scroll Effects, Need an app ? - http://rajayogan.com Buy my course - https://www.udemy.com/ learn-flutter-from Duration: 33:58 Posted: Mar 19, 2019 How to handle scrolling in an integration test. 3. Write a test that scrolls through the list. Now, you can write a test. In this example, scroll through the list of items and verify that a particular item exists in the list.

smooth_page_indicator, Customizable animated page indicator with a set of built-in effects. SmoothPageIndicator( controller: controller, // PageController count: 6,� If you ever faced the issue of content going below the screen in your Android or iOS application. If we talk about Android we use ScrollView, our parent element is ScrollView and anything which is under ScrollView becomes scrollable. In iOS, we set content size of UiScrollView. Using Flutter we have SingleChildScrollView Widget. We will …

auto_animated, Auto animated #. Make an animated on scroll widgets in 2 minutes? Easily! #. Showcase #. ListView, GridView, Sliver� In this article, I will show you how the pre-built demo Flutter app, i.e., the “Counter App” works. In my previous article, I had discussed the difference between Stateful and Stateless Widgets.

Comments
  • Thanks for the reply @murat. Can you please explain in brief. I'm not getting your answer.
  • This merely changes the text from 0 to 10, but does not have the scroll animation.