Skip to content
pubscout

clock

1.1.3, released 3 months ago by tools.dart.dev

A fakeable wrapper for dart:core clock APIs.

WASM-readyRock solid
$ flutter pub add clock
Source repository

What it does

Encapsulates the notion of the current time using a Clock class. Allows swapping out the default top-level clock to reliably test timing-dependent code.

AI-written summary of version 1.1.3, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to test timing-dependent code reliably
  • You want to mock time or use fake_async for tests

Skip it when

  • You only need standard DateTime functionality without mocking or testing requirements

Strengths

  • Integrates seamlessly with the fake_async package
  • Provides a top-level clock field for default usage

Weaknesses

  • Requires using the wrapper instead of direct dart:core DateTime calls

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
import 'package:clock/clock.dart';

T runWithTiming<T>(T Function() callback) {
  var stopwatch = clock.stopwatch()..start();
  var result = callback();
  print('It took ${stopwatch.elapsed}!');
  return result;
}

Works with

Packages commonly used together with clock: ones it builds on, ones built on it, and its own family.