ntp 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

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.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/README.md

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:


dependencies:
  ntp: ^1.0.4

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
88
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:ntp/ntp.dart with components: io.

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.

Dependencies

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