flutter_ntp 0.0.2 flutter_ntp: ^0.0.2 copied to clipboard
A flutter implementation of (NTP) Network Time Protocol server.
flutter_ntp #
A Flutter package for obtaining accurate time using Network Time Protocol (NTP).
Overview #
flutter_ntp
is a Dart package designed to fetch accurate time information using NTP servers. It supports querying various NTP servers and caching responses to improve performance and reliability.
Features #
- NTP Querying: Fetch accurate time from NTP servers.
- Server Flexibility: Supports querying from a wide range of NTP servers.
- Caching: Optionally caches NTP responses to reduce network calls and improve performance.
- Timeout Handling: Configurable timeout for NTP queries.
- Easy Integration: Simple API for fetching NTP time in your Flutter applications.
Installation #
Add flutter_ntp
to your pubspec.yaml
file:
dependencies:
flutter_ntp: ^version
Install packages from the command line:
flutter pub get
Usage #
Import the package where needed:
import 'package:flutter_ntp/flutter_ntp.dart';
Fetching NTP Time #
DateTime currentTime = await FlutterNTP.now();
print('Current NTP time: $currentTime');
Parameters #
lookUpAddress
: Optional. The NTP server address to query. Default isgoogle
, you can accessNtpServer
and change the address.port
: Optional. The port number for NTP query. Default is123
, which uses default port forgoogle
server.timeout
: Optional. Timeout duration for NTP query. Default isnull
.cacheDuration
: Optional. Duration to cache NTP responses. Default is 1 hour.
Example #
DateTime currentTime = await NTP.now(
lookUpAddress: NtpServer.google.url,
port: 123,
timeout: Duration(seconds: 5),
cacheDuration: Duration(minutes: 30),
);
Support #
If you find this plugin helpful, consider supporting me: