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.
- 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, andCurrencyFormatter - Extensible — implement
NumberFormatterto use any custom format - Zero extra dependencies — uses only the Flutter SDK
- All platforms — Android, iOS, Web, macOS, Windows, Linux
Add the dependency to your pubspec.yaml:
dependencies:
digit_roller: ^1.0.0Then run:
flutter pub getimport '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,
),
)DigitRoller(
value: _price,
formatter: CurrencyFormatter(symbol: '\$'),
textStyle: const TextStyle(fontSize: 32, color: Colors.green),
)DigitRoller(
value: _temperature,
formatter: const DecimalFormatter(decimalPlaces: 1),
textStyle: const TextStyle(fontSize: 40),
duration: const Duration(milliseconds: 300),
curve: Curves.elasticOut,
)class PercentFormatter implements NumberFormatter {
@override
String format(num value) => '${value.toStringAsFixed(1)}%';
}
DigitRoller(
value: _progress * 100,
formatter: PercentFormatter(),
textStyle: const TextStyle(fontSize: 36),
)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),
),
);
}
}| 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 |
| 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 |
| Android | iOS | Web | macOS | Windows | Linux |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Issues and pull requests are welcome at github.com/tejapunna/digit_roller.
MIT — see LICENSE.