A Flutter package for obtaining accurate time using Network Time Protocol (NTP).
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.
- 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.
Add flutter_ntp to your pubspec.yaml file:
dependencies:
flutter_ntp: ^versionInstall packages from the command line:
flutter pub getImport the package where needed:
import 'package:flutter_ntp/flutter_ntp.dart'; DateTime currentTime = await FlutterNTP.now();
print('Current NTP time: $currentTime');lookUpAddress: Optional. The NTP server address to query. Default isgoogle, you can accessNtpServerand change the address.port: Optional. The port number for NTP query. Default is123, which uses default port forgoogleserver.timeout: Optional. Timeout duration for NTP query. Default isnull.cacheDuration: Optional. Duration to cache NTP responses. Default is 1 hour.
DateTime currentTime = await NTP.now(
lookUpAddress: NtpServer.google.url,
port: 123,
timeout: Duration(seconds: 5),
cacheDuration: Duration(minutes: 30),
);If you find this plugin helpful, consider supporting me: