Skip to content

About

Flutter widget that animates numeric changes with a smooth slot-machine roll effect

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

digit_roller

A Flutter widget that animates numeric changes with a smooth slot-machine roll effect — each digit rolls independently up or down, making counters, prices, scores, and dashboards feel alive.

Features

  • Per-digit animation — only changed digits roll; unchanged digits stay still
  • Automatic direction — rolls up when the value increases, down when it decreases
  • Rich formatting — built-in IntFormatter, DecimalFormatter, and CurrencyFormatter
  • Extensible — implement NumberFormatter to use any custom format
  • Zero extra dependencies — uses only the Flutter SDK
  • All platforms — Android, iOS, Web, macOS, Windows, Linux

Getting started

Add the dependency to your pubspec.yaml:

dependencies:
  digit_roller: ^1.0.0

Then run:

flutter pub get

Usage

Simple integer counter

import 'package:digit_roller/digit_roller.dart';

// In your widget tree:
DigitRoller(
  value: _counter,          // change this value to trigger the animation
  textStyle: const TextStyle(
    fontSize: 48,
    fontWeight: FontWeight.bold,
    color: Colors.black,
  ),
)

Currency display

DigitRoller(
  value: _price,
  formatter: CurrencyFormatter(symbol: '\$'),
  textStyle: const TextStyle(fontSize: 32, color: Colors.green),
)

Decimal with custom precision

DigitRoller(
  value: _temperature,
  formatter: const DecimalFormatter(decimalPlaces: 1),
  textStyle: const TextStyle(fontSize: 40),
  duration: const Duration(milliseconds: 300),
  curve: Curves.elasticOut,
)

Custom formatter

class PercentFormatter implements NumberFormatter {
  @override
  String format(num value) => '${value.toStringAsFixed(1)}%';
}

DigitRoller(
  value: _progress * 100,
  formatter: PercentFormatter(),
  textStyle: const TextStyle(fontSize: 36),
)

Full StatefulWidget example

class CounterPage extends StatefulWidget {
  const CounterPage({super.key});

  @override
  State<CounterPage> createState() => _CounterPageState();
}

class _CounterPageState extends State<CounterPage> {
  int _count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: DigitRoller(
          value: _count,
          textStyle: const TextStyle(fontSize: 72, fontWeight: FontWeight.w900),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => setState(() => _count++),
        child: const Icon(Icons.add),
      ),
    );
  }
}

Parameters

Parameter Type Default Description
value num required The numeric value to display
textStyle TextStyle required Style applied to every digit
formatter NumberFormatter? auto (Int/Decimal based on type) Controls the display string format
duration Duration 500ms Duration of each digit roll animation
curve Curve Curves.easeOutCubic Animation curve for each digit roll
rollDirection DigitRollDirection? inferred from value change Force roll direction (up or down)
mainAxisAlignment MainAxisAlignment MainAxisAlignment.center Alignment of the digit row

Formatters

Class Description
IntFormatter Integer with optional thousands separator
DecimalFormatter Decimal with configurable places + separators
CurrencyFormatter Currency symbol + decimal, symbol before or after
NumberFormatter Abstract base — implement for fully custom formatting

Platform support

Android iOS Web macOS Windows Linux
✅ ✅ ✅ ✅ ✅ ✅

Contributing

Issues and pull requests are welcome at github.com/tejapunna/digit_roller.

License

MIT — see LICENSE.

About

Flutter widget that animates numeric changes with a smooth slot-machine roll effect

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages