Flutter Plugin

Flutter Time Guard stops device clock tampering before it hurts your app.

Install the plugin, validate device time against trusted NTP servers, and receive callbacks the moment a user or the OS adjusts the clock or timezone. Keep authentication windows, subscriptions, and monetization events accurate on every platform.

Latest release: 1.2.2 Platforms: Android · iOS · macOS · Windows · Linux License: MIT

Use Time Guard To

  • Block fraud in timeboxed offers and subscriptions.
  • Protect authentication tokens and refresh cycles.
  • Keep leaderboards, logs, and analytics trustworthy.

Quick Facts

  • NTP validation
  • Background listeners
  • Offline caching
  • Null-safe API

Why teams choose Flutter Time Guard

The plugin is designed for production workloads that cannot afford inaccurate device clocks. Each capability solves a specific pain point found in payment, gaming, compliance, and enterprise apps.

Real-time tamper detection

Subscribe to listenToDateTimeChange to get instant callbacks whenever the user adjusts the date, time, or timezone — even while the app is backgrounded.

NTP-backed validation

Compare device time against trusted NTP servers, validate against the drift tolerance you set, and gracefully handle network outages with cached timestamps.

Cross-platform coverage

Support mobile, desktop, and embedded Flutter runtimes with a single plugin. Time Guard works where your business logic runs.

Production-grade logging

Opt into structured logging to observe anomalies in production, feed dashboards, or pipe the events into your observability tooling.

Integrate in minutes

Follow the core steps below to wire Flutter Time Guard into your application flow. Use the code blocks as a starting point and tighten the tolerance based on your business rules.

1. Add the dependency

flutter pub add flutter_time_guard

Time Guard is null-safe, tested across Flutter stable channels, and adds no post-build configuration.

2. Validate device time

import 'package:flutter_time_guard/flutter_time_guard.dart';

Future<bool> isTimeValid() async {
  FlutterTimeGuard.configureLogging(enableLogs: true);
  return FlutterTimeGuard.isDateTimeValid(
    toleranceInSeconds: 3600, // 1 hour drift tolerance
  );
}

Call during authentication or before unlocking premium content. Pick a tolerance that prevents abuse without blocking legitimate users.

3. React to manual changes

FlutterTimeGuard.listenToDateTimeChange(
  stopListeingAfterFirstChange: true,
  onTimeChanged: () async {
    final isValid = await FlutterTimeGuard.isDateTimeValid(
      toleranceInSeconds: 3600,
    );
    if (!isValid) {
      // Show a blocking dialog, sign the user out, or notify your backend.
    }
  },
);

Re-validate inside the listener to filter out automatic OS synchronizations that keep the device within your allowed drift.

Best practice

If your use case must fail closed when NTP is unreachable, store your own flag after the first successful validation and degrade functionality until the device time is corrected.

Frequently asked questions

Clear answers for product managers, security teams, and Flutter engineers.

Does Flutter Time Guard require constant internet access?

No. The plugin caches the most recent successful NTP lookup and reuses it when the device is offline, falling back to true on first launch so legitimate users are not blocked.

Can I connect to my own NTP servers?

Yes. Pass a custom servers list to isDateTimeValid or configure to target internal or region-specific time authorities.

How should I choose the tolerance window?

Start with one hour (3600 seconds) for general use cases. High-risk financial flows typically rely on 5–15 minute tolerances, while casual gaming can allow more drift for offline players.

Will it work alongside existing analytics or crash reporting?

Yes. Time Guard has no native dependencies that conflict with Firebase, Sentry, or popular analytics SDKs. Use the logging hooks to forward anomalies into your monitoring pipeline.

Need help auditing or extending Flutter Time Guard?

Reach out for security reviews, integration support, or custom enterprise features tailored to your product roadmap.