Search packages, repositories and app categories

Package detailsv2.0.0

ntp

Fetch accurate time or current DateTime object from (NTP) Network Time Protocol server.

AndroidiOSmacOSWindowsLinux
30-day downloads
177K
Likes
261
Pub points
150

Install package

flutter pub add ntp

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The ntp package provides a simple way to fetch accurate system time from Network Time Protocol (NTP) servers. It enables applications to obtain precise DateTime values synchronized with global time standards, which is especially useful for time-sensitive operations like logging, scheduling, or syncing across devices. The package supports multiple platforms including Android, iOS, macOS, Windows, and Linux, ensuring consistent behavior across environments. It uses standard NTP protocols and offers an easy-to-use API for retrieving current time without relying on local device clocks.

Use cases

  • Synchronizing app timestamps with global time
  • Improving accuracy in time-based logging
  • Enabling reliable task scheduling
  • Validating device clock drift
  • Supporting distributed systems requiring precise timing

Key features

  • Fetches real-time data from NTP servers
  • Cross-platform compatibility
  • Simple synchronous and asynchronous APIs
  • High precision time retrieval
  • Minimal dependencies

Suitable for

  • Applications needing high-accuracy time
  • Time-critical services
  • IoT and backend systems
  • Mobile and desktop apps requiring synced clocks
  • Development tools for time validation

Considerations

  • Requires internet access to function
  • May have latency depending on network conditions
  • Not suitable for offline use
  • Server availability affects reliability
  • Time zone handling must be managed separately

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

pub package CodeFactor

NTP

Plugin that allows you to get precise time from Network Time Protocol (NTP). It implements whole NTP protocol in dart.

This is useful for time-based events since DateTime.now() returns the time of the device. Users sometimes change their internal clock and using DateTime.now() can give wrong result. You can just get clock offset [NTP.getNtpTime] and apply it manually to DateTime.now() object when needed (just add offset as milliseconds duration), or you can get already formatted [DateTime] object from [NTP.now].

By default lookup address for NTP is: time.google.com

For example on how to use look in github library repository example/ folder.

How it works

Using int offset from getNtpTime()

  • default localTime is DateTime.now()
  • default lookUpAddress is 'time.google.com'
  • default port is 123
  DateTime startDate = new DateTime.now().toLocal();
  int offset = await NTP.getNtpOffset(localTime: startDate);
  print('NTP DateTime offset align: ${startDate.add(new Duration(milliseconds: offset))}');

Using DateTime from now

  DateTime startDate = await NTP.now();
  print('NTP DateTime: ${startDate}');
NTP Functions
  Future<int> getNtpOffset({
    String lookUpAddress: 'time.google.com',
    int port: 123,
    DateTime localTime,
    Duration timeout,
  });
  Future<DateTime> now();

Categories

Source repository

Projects using this package