counter animation added.
parent
328b2fe48d
commit
23e7550212
@ -0,0 +1,40 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue