Pub Version GitHub GitHub GitHub

Chronograph is a lightweight, reactive engine for stopwatch and countdown use‑cases in Flutter. It exposes a simple ValueListenable

Features

  • Reactive engine: expose ValueListenable<Chrono> for easy UI updates
  • Three modes: stopwatch, timer(duration), countdown(date)
  • Tiny view helper: ChronoView wraps ValueListenableBuilder<Chrono>
  • Configurable tick interval and display level (days/hours/minutes/seconds)
  • Optional autostart and onCompleted callback for countdowns/timers
  • Immutable Chrono value with padded strings and total time helpers
  • Pure Dart implementation — no platform channels, test‑friendly

Usage

For a complete usage, please see the example.

To read more about classes and other references used by chronograph, see the API Reference.

Stopwatch (count up)

final graph = ChronoGraph.stopwatch(
  level: ChronoLevel.seconds,
  interval: const Duration(seconds: 1),
  autostart: false, // call start() manually
);

// Control
graph.start();
graph.pause();
graph.reset();

// Build UI
ChronoView(
  graph: graph,
  builder: (context, info, _) => Text(
    '${info.paddedMinutes}:${info.paddedSeconds}',
  ),
);

Timer (fixed duration)

final timer = ChronoGraph.timer(
  duration: const Duration(seconds: 10),
  autostart: true,
  onCompleted: () => debugPrint('Timer completed'),
);

ChronoView(
  graph: timer,
  builder: (context, info, _) => Text(
    '${info.paddedMinutes}:${info.paddedSeconds}',
  ),
);

Countdown to a DateTime

final countdown = ChronoGraph.countdown(
  date: DateTime(2025, 1, 1), // target date
  autostart: true,
  onCompleted: () => debugPrint('Happy New Year!'),
);

ChronoView(
  graph: countdown,
  builder: (context, info, _) => Text(
    '${info.paddedMinutes}:${info.paddedSeconds}',
  ),
);

Sponsoring

Buy Me A Coffee Ko-Fi

If this package or any other package I created is helping you, please consider to sponsor me so that I can take time to read the issues, fix bugs, merge pull requests and add features to these packages.

Libraries

chronograph