You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/animations/number_incremental_animatio...

41 lines
963 B
Dart

import 'package:flutter/material.dart';
class CounterAnimatedText extends ImplicitlyAnimatedWidget {
final int value;
final TextStyle? style;
const CounterAnimatedText({
super.key,
super.duration = const Duration(milliseconds: 750),
required this.value,
this.style,
});
@override
ImplicitlyAnimatedWidgetState<CounterAnimatedText> createState() => _CounterTextState();
}
class _CounterTextState extends AnimatedWidgetBaseState<CounterAnimatedText> {
late IntTween _counter;
@override
void initState() {
_counter = IntTween(begin: widget.value, end: widget.value);
super.initState();
}
@override
Widget build(BuildContext context) {
return Text('${_counter.evaluate(animation)}', style: widget.style);
}
@override
void forEachTween(TweenVisitor<dynamic> visitor) {
_counter = visitor(
_counter,
widget.value,
(dynamic value) => IntTween(begin: value),
) as IntTween;
}
}