AccurateTime class

A static class to manage accurate UTC time using HTTP/UDP synchronization and local caching.

Constructors

AccurateTime()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

cachedOffset Duration?
Returns the current accurate cached offset (server time - local time).
no setter
lastSyncTime DateTime?
Returns the local time when the last successful synchronization occurred.
no setter
ntpClientFactory NtpClient Function({bool isUtc, int port, String server, int timeout})?
Factory function to create an NtpClient instance. Primarily used to inject mock/stub clients during unit testing.
getter/setter pair

Static Methods

clearCache() → void
Clears the cached NTP offset and synchronization time.
now({bool isUtc = false, NtpServer server = NtpServer.google, String? customServer, int port = 123, int timeout = 5, bool forceRefresh = false, bool allowFallback = true}) Future<DateTime>
Returns the current accurate time.
nowSync({bool isUtc = false, NtpServer server = NtpServer.google, String? customServer, int port = 123, int timeout = 5}) DateTime
Returns the current accurate time synchronously using the cached offset.
nowToIsoString({bool isUtc = true}) Future<String>
Returns the current accurate time as an ISO 8601 string.
setSyncInterval(Duration newInterval) → void
Updates the duration used to determine when to resync the time.