timeRemaining method

Future<Duration?> timeRemaining()

Calculates and returns the remaining time until the counter auto-resets.

Returns a Duration representing the time left until reset, or null if the last update time is not available.

Implementation

Future<Duration?> timeRemaining() async {
  final last = await lastUpdate.get();
  if (last == null) return null;
  final elapsed = DateTime.now().difference(last);
  final remaining = resetEvery - elapsed;
  return remaining.isNegative ? Duration.zero : remaining;
}