true_time_provider 1.0.2 copy "true_time_provider: ^1.0.2" to clipboard
true_time_provider: ^1.0.2 copied to clipboard

A secure and reliable true time provider for Flutter apps.

⏰ True Time Provider for Flutter #

A secure and reliable time provider for Flutter apps. Fetches accurate time from NTP servers, with Firebase and device time as fallbacks.


Screenshots #

result2     result1


Table of Contents #


✨ Features #

  • ✅ Provides accurate, tamper-resistant current time
  • ✅ Built-in Singleton pattern (global instance)
  • ✅ Multi-source fallback (NTP → Firebase → Device)
  • ✅ Handles network failures gracefully
  • ✅ Supports IPv4 & IPv6
  • ✅ Configurable NTP host, port, and timeout

Installation #

Add this to your pubspec.yaml:

dependencies:
  true_time_provider: latest_version

Install it with:

flutter pub get

Usage #

1. Initialize at app startup #

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize Firebase fallback
  TrueTimeProvider.instance.init(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  runApp(MyApp());
}

2. Fetch secure time #

final DateTime safeNow = await TrueTimeProvider.instance.now();
print("Secure current time: $safeNow");

🛠 How It Works #

Fallback Flow #

try NTP server
   │
   ├── success → return ntpTime
   │
   └── fail → try Firebase
               │
               ├── success → return fireSTime
               │
               └── fail → return DateTime.now() (device)

Class Overview #

  • TrueTimeProvider → Singleton entry point
  • NtpServerProvider → Fetches time via UDP NTP
  • FirebaseCloudProvider → Fetches server time from Firestore
  • Device Time → Final fallback

⚡ Example Use Cases #

  • Banking / Payment apps
  • Event logging / Audit trails
  • Subscription & licensing apps
  • Distributed systems

🔧 Configuration #

Override NTP lookup options:

final time = await TrueTimeProvider.instance.now(
  ntpFetchDuration: Duration(seconds: 20),
  ntoLookUpAddress: "pool.ntp.org",
  ntpLookupPort: 123,
);

Limitations #

  • NTP requires UDP port 123 (may be blocked in some networks)
  • Firebase fallback requires internet access
  • Falls back to device time if both fail
  • Currently only one NTP request per call (no retries)

Roadmap #

  • ❌ Retry mechanism with exponential backoff
  • ❌ Cache last known good offset
  • ❌ Expose NTP sync statistics (delay, jitter)
  • ❌ Add tests with mock NTP responses

License #

This project is licensed under the MIT License.


2
likes
150
points
150
downloads
screenshot

Publisher

verified publisherautoformsai.com

Weekly Downloads

A secure and reliable true time provider for Flutter apps.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

cloud_firestore, firebase_core, firebase_core_web, flutter, http

More

Packages that depend on true_time_provider