startCountdown method
Starts a reactive countdown.
Returns an LxCountdown object that exposes the LxCountdown.remaining duration and control methods (pause, resume, stop).
duration: The total duration to count down/up.interval: The tick interval (default: 1 second).onTick: Called on every interval.onFinish: Called when the countdown reaches zero.
Implementation
LxCountdown startCountdown({
required Duration duration,
Duration interval = const Duration(seconds: 1),
void Function(Duration remaining)? onTick,
void Function()? onFinish,
}) {
final countdown = LxCountdown(
totalDuration: duration,
interval: interval,
onTick: onTick,
onFinish: onFinish,
);
// Auto-dispose the countdown with the controller
// Note: Since LxCountdown isn't a reactive itself but holds one, we rely on its dispose.
// We can't use autoDispose() directly on it unless it's a Disposable.
// Let's ensure LxCountdown implements Disposable or we track it.
// For now, we return it and let the user manage or we track it internally if we want rigorous safety.
// Better: Add to a list of disposables.
// For simplicity in this mixin, we return it. Ideally, the user calls .dispose() or we track it.
// To be safe, let's track it in a separate list.
_countdowns.add(countdown);
countdown.start();
return countdown;
}