AnimatedCounter class
Animated rolling-digit counter backed by CustomPainter.
Every animation frame updates the persistent CounterPainter in-place and
calls markNeedsPaint() — zero widget builds during animation.
Static decorations (prefix, suffix, signs) are rendered in a lightweight
Row that rebuilds only once per value change.
For custom per-digit widgets or transition builders use AnimatedCounterBuilder.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- AnimatedCounter
Constructors
-
AnimatedCounter({CounterFormat? format, CounterTimeline? timeline, Key? key, AnimatedCounterStyle? style, num? value, AnimatedCounterController? controller, Counter? plugin, double? fps, bool? animateOnce, @Deprecated('改用 timeline: CounterTimeline(duration: ...)') Duration duration = const Duration(milliseconds: 300), Duration negativeSignDuration = const Duration(milliseconds: 150), @Deprecated('改用 timeline: CounterTimeline(curve: ...)') Curve curve = Curves.linear, @Deprecated('改用 style: AnimatedCounterStyle(textStyle: ...)') TextStyle? textStyle, String? prefix, String? infix, String? suffix, @Deprecated('改用 format: CounterFormat(fractionDigits: ...)') int fractionDigits = 0, @Deprecated('改用 format: CounterFormat(wholeDigits: ...)') int wholeDigits = 1, @Deprecated('改用 format: CounterFormat(hideLeadingZeroes: ...)') bool hideLeadingZeroes = true, @Deprecated('改用 style: AnimatedCounterStyle(numberAlignment: ...)') double? numberAlignment, @Deprecated('改用 format: CounterFormat(thousandSeparator: ...)') String? thousandSeparator, @Deprecated('改用 format: CounterFormat(groupingPattern: ...)') List<
int> groupingPattern = const [3], @Deprecated('改用 format: CounterFormat(decimalSeparator: ...)') String decimalSeparator = '.', @Deprecated('改用 style: AnimatedCounterStyle(separatorStyle: ...)') TextStyle? separatorStyle, @Deprecated('改用 style: AnimatedCounterStyle(mainAxisAlignment: ...)') MainAxisAlignment? mainAxisAlignment, @Deprecated('改用 style: AnimatedCounterStyle(crossAxisAlignment: ...)') CrossAxisAlignment? crossAxisAlignment, @Deprecated('改用 style: AnimatedCounterStyle(padding: ...)') EdgeInsets? padding, @Deprecated('改用 style: AnimatedCounterStyle(useTabularFigures: ...)') bool? useTabularFigures, @Deprecated('改用 style: AnimatedCounterStyle(prefixStyle: ...)') TextStyle? prefixStyle, @Deprecated('改用 style: AnimatedCounterStyle(infixStyle: ...)') TextStyle? infixStyle, @Deprecated('改用 style: AnimatedCounterStyle(suffixStyle: ...)') TextStyle? suffixStyle, TextOverflow? prefixOverflow, TextOverflow? infixOverflow, TextOverflow? suffixOverflow, @Deprecated('改用 format: CounterFormat(showPositiveSign: ...)') bool showPositiveSign = false, Duration? positiveSignDuration, String? semanticsLabel, VoidCallback? onAnimationEnd, VoidCallback? onAnimationStart, AxisDirection flipDirection = AxisDirection.up, num? minValue, num? maxValue, @Deprecated('改用 style: AnimatedCounterStyle(increasingColor: ...)') Color? increasingColor, @Deprecated('改用 style: AnimatedCounterStyle(decreasingColor: ...)') Color? decreasingColor, @Deprecated('改用 style: AnimatedCounterStyle(colorFadeDuration: ...)') Duration? colorFadeDuration, Widget? prefixWidget, Widget? infixWidget, Widget? suffixWidget, @Deprecated('AnimatedCounter 的 painter 路径不支持分隔符 widget,请改用 AnimatedCounterBuilder') Widget? thousandSeparatorWidget, @Deprecated('AnimatedCounter 的 painter 路径不支持分隔符 widget,请改用 AnimatedCounterBuilder') Widget? decimalSeparatorWidget, Widget? negativeSignWidget, Widget? positiveSignWidget, @Deprecated('改用 timeline: CounterTimeline(staggerDelay: ...)') Duration? staggerDelay, @Deprecated('改用 timeline: CounterTimeline(staggerDirection: ...)') StaggerDirection staggerDirection = StaggerDirection.rightToLeft, @Deprecated('改用 format: CounterFormat(compactNotation: ...)') bool compactNotation = false, bool triggerHaptics = false, @Deprecated('改用 format: CounterFormat(compactFractionDigits: ...)') int? compactFractionDigits, num initialValue = 0, @Deprecated('改用 format: CounterFormat(numeralSystem: ...)') NumeralSystem numeralSystem = NumeralSystem.latin, @Deprecated('改用 format: CounterFormat(numeralMapper: ...)') String numeralMapper(int digit)?, CounterTransition transition = CounterTransition.slide, @Deprecated('改用 timeline: CounterTimeline(reverseDuration: ...)') Duration? reverseDuration, @Deprecated('改用 timeline: CounterTimeline(reverseCurve: ...)') Curve? reverseCurve, @Deprecated('改用 timeline: CounterTimeline(startDelay: ...)') Duration? startDelay, @Deprecated('改用 timeline: CounterTimeline(speedMultiplier: ...)') double speedMultiplier = 1.0, @Deprecated('改用 format: CounterFormat(compactAbbreviations: ...)') Map<num, String> ? compactAbbreviations, VoidCallback? onPause, VoidCallback? onResume, VoidCallback? onReset, VoidCallback? onRepeat, VoidCallback? onReverse, bool repaintBoundary = true, @Deprecated('改用 timeline: CounterTimeline(autoEaseThreshold: ...)') double autoEaseThreshold = 100000, @Deprecated('改用 timeline: CounterTimeline(curveForDigit: ...)') Curve? curveForDigit(int digitIndex)?, Color? colorResolver(num value)?, @Deprecated('改用 timeline: CounterTimeline(interpolation: ...)') double interpolation(double from, double to, double t)?, @Deprecated('改用 timeline: CounterTimeline(bounceOvershoot: ...)') double bounceOvershoot = 0.0, @Deprecated('No effect; use bounceOvershoot instead') double bounceElasticity = 4.0, @Deprecated('改用 timeline: CounterTimeline(fast: ...)') bool fast = false, CounterPainterBuilder? painterBuilder}) -
创建计数器;
format的非空字段覆盖同名平铺参数,空字段回退。timeline的非空字段同样覆盖同名平铺动画参数,空字段回退。const
Properties
- animateOnce → bool?
-
animate-once 开关:只在 key(需为稳定的 ValueKey)首次出现时播放入场动画,
同一 Provider 下再次挂载直接显示终值。
null(默认)继承最近 CounterProvider.animateOnce。无稳定 key 或没有 Provider 时退化为每次都动画。finalinherited - autoEaseThreshold → double
-
finalinherited
- bounceElasticity → double
-
finalinherited
- bounceOvershoot → double
-
finalinherited
- colorFadeDuration → Duration
-
no setterinherited
- colorResolver → Color? Function(num value)?
-
finalinherited
-
compactAbbreviations
→ Map<
num, String> ? -
finalinherited
- compactFractionDigits → int?
-
finalinherited
- compactNotation → bool
-
finalinherited
- controller → AnimatedCounterController?
-
finalinherited
- crossAxisAlignment → CrossAxisAlignment
-
no setterinherited
- curve → Curve
-
finalinherited
- curveForDigit → Curve? Function(int digitIndex)?
-
finalinherited
- decimalSeparator → String
-
finalinherited
- decimalSeparatorWidget → Widget?
-
finalinherited
- decoration → Decoration?
-
Container decoration drawn around the whole counter (style-only).
no setterinherited
- decreasingColor → Color?
-
no setterinherited
- duration → Duration
-
finalinherited
- fast → bool
-
Fast mode: every digit column does a SINGLE step from its old digit to
its new digit (one slot of movement), regardless of numeric distance —
e.g. 1000 → 9999 slides each column once (1→9, 0→9, …) instead of the
full cascading odometer roll. Applies to every
transition.finalinherited - flipDirection → AxisDirection
-
finalinherited
- format → CounterFormat?
-
聚合格式;非空字段优先于平铺参数。
finalinherited
- fps → double?
-
实例显示刷新上限,返回帧/秒;null 继承插件再到全局。示例:
fps: 30。finalinherited - fractionDigits → int
-
finalinherited
-
groupingPattern
→ List<
int> -
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hideLeadingZeroes → bool
-
finalinherited
- increasingColor → Color?
-
no setterinherited
- infix → String?
-
finalinherited
- infixOverflow → TextOverflow?
-
finalinherited
- infixStyle → TextStyle?
-
no setterinherited
- infixWidget → Widget?
-
finalinherited
- initialValue → num
-
finalinherited
- interpolation → double Function(double from, double to, double t)?
-
finalinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- mainAxisAlignment → MainAxisAlignment
-
no setterinherited
- maxValue → num?
-
finalinherited
- minValue → num?
-
finalinherited
- negativeSignDuration → Duration
-
finalinherited
- negativeSignWidget → Widget?
-
finalinherited
- numberAlignment → double
-
Horizontal alignment of visible digits within the stable full-width slot.
-1.0 = left, 0.0 = center (default), 1.0 = right.
no setterinherited
- numeralMapper → String Function(int digit)?
-
finalinherited
- numeralSystem → NumeralSystem
-
finalinherited
- onAnimationEnd → VoidCallback?
-
finalinherited
- onAnimationStart → VoidCallback?
-
finalinherited
- onPause → VoidCallback?
-
finalinherited
- onRepeat → VoidCallback?
-
finalinherited
- onReset → VoidCallback?
-
finalinherited
- onResume → VoidCallback?
-
finalinherited
- onReverse → VoidCallback?
-
finalinherited
- padding → EdgeInsets
-
no setterinherited
- painterBuilder → CounterPainterBuilder?
-
Optional factory for a custom CounterPainter subclass.
final
- plugin → Counter?
-
动画任务所在的 Counter 插件(分组)。
finalinherited
- positiveSignDuration → Duration?
-
finalinherited
- positiveSignWidget → Widget?
-
finalinherited
- prefix → String?
-
finalinherited
- prefixOverflow → TextOverflow?
-
finalinherited
- prefixStyle → TextStyle?
-
no setterinherited
- prefixWidget → Widget?
-
finalinherited
- repaintBoundary → bool
-
finalinherited
- reverseCurve → Curve?
-
finalinherited
- reverseDuration → Duration?
-
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticsLabel → String?
-
finalinherited
- separatorStyle → TextStyle?
-
no setterinherited
- showPositiveSign → bool
-
finalinherited
- speedMultiplier → double
-
finalinherited
- staggerDelay → Duration?
-
finalinherited
- staggerDirection → StaggerDirection
-
finalinherited
- startDelay → Duration?
-
finalinherited
- style → AnimatedCounterStyle?
-
Aggregate visual style. Overrides the deprecated loose visual params
field-by-field (see the resolving getters below).
finalinherited
- suffix → String?
-
finalinherited
- suffixOverflow → TextOverflow?
-
finalinherited
- suffixStyle → TextStyle?
-
no setterinherited
- suffixWidget → Widget?
-
finalinherited
- textStyle → TextStyle?
-
no setterinherited
- thousandSeparator → String?
-
finalinherited
- thousandSeparatorWidget → Widget?
-
finalinherited
- timeline → CounterTimeline?
-
聚合动画时间轴;非空字段优先于平铺参数,空字段回退。
finalinherited
- transition → CounterTransition
-
finalinherited
- triggerHaptics → bool
-
finalinherited
- useTabularFigures → bool
-
no setterinherited
- value → num?
-
finalinherited
- wholeDigits → int
-
finalinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< AnimatedCounter> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited