screen-locker/stronglift_replacement/workout_app/lib/widgets/animated_counter.dart
Krzysztof kuhy Rudnicki 5d0aa9b57a Add set haptics, finish chime, sound switch
dopamine-ux 05: selectionClick on recording a set or warmup,
mediumImpact + generated chime (music_theory, pinned tag) on
finish, dialog arrival on the slow motion token, AppDuration /
AppCurve in theme.dart, streak card counts up, all of it
collapsing under the OS reduced-motion flag. One Settings
"Sound" switch silences the chime and the break-end cue
(foreground service included, via a silent channel); haptics
stay. Removes the finished dopamine-ux-05 prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWYdwRAtMg7ki6TKxuU
2026-11-01 21:46:09 +01:00

36 lines
1.1 KiB
Dart

/// A whole number that counts to its true value instead of snapping to it.
library;
import 'package:flutter/material.dart';
import 'package:workout_app/ui/theme.dart';
/// Rebuilds [builder] with a number that eases from 0 to [value] on arrival,
/// and from the number on screen to a new [value] when it changes.
///
/// The animation only travels towards the real value and always ends on it;
/// nothing here can show a number the data does not hold. With the OS
/// animations setting off, the duration collapses and the real value shows at
/// once.
class AnimatedCounter extends StatelessWidget {
/// Creates an [AnimatedCounter].
const AnimatedCounter({
required this.value,
required this.builder,
super.key,
});
/// The true value to arrive at.
final int value;
/// Draws the number currently on its way to [value].
final Widget Function(int shown) builder;
@override
Widget build(BuildContext context) => TweenAnimationBuilder<int>(
tween: IntTween(begin: 0, end: value),
duration: motionDuration(context, AppDuration.slow),
curve: AppCurve.decelerate,
builder: (_, shown, _) => builder(shown),
);
}