clock
1.1.3, released 3 months ago by tools.dart.dev
A fakeable wrapper for dart:core clock APIs.
WASM-readyRock solid
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.
- intlBuilt on clockA Dart library for internationalization and localization, providing message translation, plural/gender handling, and date/number formatting.
- leak_trackerBuilt on clockFramework to detect memory leaks in Dart and Flutter applications
- fake_asyncBuilt on clockFake asynchronous events like timers and microtasks for deterministic testing.
- package_info_plusBuilt on clockFlutter plugin to query app package info like version, build number and installer store.
- flutter_cache_managerBuilt on clockGeneric cache manager for saving web files and cache info on device storage.
- riverpodBuilt on clockA reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
- flutter_local_notificationsBuilt on clockCross-platform plugin for displaying and scheduling local notifications.
- loggerBuilt on clockAn extensible logger for printing formatted logs with levels, custom filters, and printers.