CoinFlyOverlay class

N icon "coins" fly from a source point to a target's current on-screen position — read from a GlobalKey via RenderBox.localToGlobal, the same technique used elsewhere in Flutter for this — staggered slightly so they read as individual coins instead of one blob. FEAT-12's "coin fly to CurrencyCounter" reward juice.

Design note on onArrive: this widget doesn't know what a "coin" is worth — it just fires onArrive once per coin, coinCount times total. The caller decides the value split, e.g. bump a CurrencyCounter by totalAmount ~/ coinCount on every call, so the running total lands exactly on totalAmount once the last coin arrives.

Implementation note: all coins share a single AnimationController (duration = duration + stagger * (coinCount - 1)) instead of one controller per coin — each coin just occupies its own [start, start + duration] sub-window of that one timeline. One controller/ticker total, no per-coin Future.delayed timers to leak or cancel.

Same self-cleaning static-entry-point convention as FloatingComboText.show/ToastBanner.show: call CoinFlyOverlay.show once, no ambient state to manage — it inserts into the root Overlay and removes itself once the last coin lands.

Inheritance

Constructors

CoinFlyOverlay({Key? key, required Offset from, required Offset to, int coinCount = 5, IconData icon = Icons.monetization_on, Color? color, double coinSize = 22, Duration duration = const Duration(milliseconds: 550), Duration stagger = const Duration(milliseconds: 70), VoidCallback? onArrive, VoidCallback? onDone})
const

Properties

coinCount → int
How many coin icons fly.
final
coinSize → double
final
color → Color?
final
duration → Duration
How long a single coin's own flight takes.
final
from → Offset
Source point, in the Overlay's coordinate space (global).
final
hashCode → int
The hash code for this object.
no setterinherited
icon → IconData
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onArrive → VoidCallback?
Called once per coin, when that coin's flight completes — fires coinCount times total.
final
onDone → VoidCallback?
Called once, right after the last coin arrives, just before the overlay removes/hides itself.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stagger → Duration
Delay between one coin starting and the next.
final
to → Offset
Target point, in the Overlay's coordinate space (global) — usually the center of a GlobalKey's render box, see show.
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<CoinFlyOverlay>
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

Static Methods

show(BuildContext context, {required Offset from, required GlobalKey<State<StatefulWidget>> targetKey, int coinCount = 5, IconData icon = Icons.monetization_on, Color? color, double coinSize = 22, Duration duration = const Duration(milliseconds: 550), Duration stagger = const Duration(milliseconds: 70), VoidCallback? onArrive}) → void
Reads targetKey's current on-screen center and inserts a self-removing CoinFlyOverlay into context's root Overlay, flying coinCount coins from from to it. No-ops if targetKey isn't currently attached to a render object (e.g. its widget isn't on screen) or if coinCount is not positive.