ntp 1.0.3

  • README.md
  • Example
  • Installing
  • Versions
  • 92

[pub package] (https://pub.dartlang.org/packages/ntp)

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: pool.ntp.org

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 'pool.ntp.org'
  • default port is 123
  DateTime startDate = new DateTime().now().toLocal();
  int offset = await NTP.getNtpTime(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> getNtpTime({
    String lookUpAddress: 'pool.ntp.org',
    int port: 123,
    DateTime localTime,
  Future<DateTime> now();

[1.0.3] - 25.03.2019.

  • Fix returning future, may fix #1

[1.0.2] - 22.10.2018.

  • Updated description and code cleanup

[1.0.1] - 22.07.2018.

  • Added example
  • Updated README.md

[1.0.0] - 18.07.2018.

  • Methods in NTP are now static.

  • Added now() for returning current DateTime object with calculated NTP offset

  • getNtpTime was renamed to getNtpOffset (since it is returning int offset in milliseconds)

[0.0.1] - 16.04.2018.

  • Get NTP clock offset


example #

A new Flutter project.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  ntp: ^1.0.3

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:ntp/ntp.dart';
Version Uploaded Documentation Archive
1.0.3 Mar 25, 2019 Go to the documentation of ntp 1.0.3 Download ntp 1.0.3 archive
1.0.2 Oct 22, 2018 Go to the documentation of ntp 1.0.2 Download ntp 1.0.2 archive
1.0.1 Jul 22, 2018 Go to the documentation of ntp 1.0.1 Download ntp 1.0.1 archive
1.0.0 Jul 18, 2018 Go to the documentation of ntp 1.0.0 Download ntp 1.0.0 archive
0.0.2 Jun 8, 2018 Go to the documentation of ntp 0.0.2 Download ntp 0.0.2 archive
0.0.1 Apr 16, 2018 Go to the documentation of ntp 0.0.1 Download ntp 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 25, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/ntp/ntp.dart.

Run flutter format to format lib/ntp/ntp.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies