NtpClient class

A web-based implementation of an NTP (Network Time Protocol) client.

This implementation retrieves the current server time via an HTTP API rather than using a raw UDP socket (which is not available in web environments).

By default, it queries the Postman Echo /time/now endpoint, which returns the current GMT time as a string (e.g. "Thu, 17 Jul 2025 12:34:56 GMT"). The response is then parsed into a UTC DateTime instance.

Inheritance

Constructors

NtpClient({String server = 'pool.ntp.org', int port = 123, int timeout = 5})
Creates a new NtpClient instance with optional configuration parameters.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
port int
The UDP port used to communicate with the NTP server.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
server String
The hostname or IP address of the NTP server to query.
finalinherited
timeout int
The timeout in seconds for the time retrieval operation.
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
now() Future<DateTime>
Fetches the current server time from the configured HTTP API.
override
toString() String
A string representation of this object.
inherited

Operators

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