ntp 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 95

pub package

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.5] - 13.01.2019.

  • Move test to example (since it uses Flutter dependency)
  • Update package

[1.0.4] - 12.07.2019.

  • Fix now() function

[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.5

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub 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';
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 Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/ntp/ntp_message.dart. (-1 points)

Analysis of lib/ntp/ntp_message.dart reported 2 hints:

line 252 col 7: DO use curly braces for all flow control structures.

line 254 col 7: DO use curly braces for all flow control structures.

Format lib/ntp/ntp.dart.

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


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
Dev dependencies
test any