system_date_time_change 1.0.1 copy "system_date_time_change: ^1.0.1" to clipboard
system_date_time_change: ^1.0.1 copied to clipboard

A Flutter plugin to detect manual changes to device date/time and timezone mismatches across all platforms.

1.0.1 - 2024-12-09 #

🔧 Bug Fixes & Improvements #

  • Added Swift Package Manager (SPM) support for macOS
  • Improved package compatibility and scoring

1.0.0 - 2024-12-09 #

🎉 Stable Release #

First stable release of system_date_time_change plugin for Flutter!

0.0.1 - 2024-12-09 #

🎉 Initial Release #

First stable release of system_date_time_change plugin for Flutter!

✨ Features #

Core Functionality

  • Real-time Detection: Monitor system date/time changes as they happen
  • Event Streaming: Receive instant notifications via onDateTimeChanged stream
  • Manual Polling: Check status on-demand with checkDateTimeStatus()
  • Manual Change Detection: Automatically detect when users manually modify time
  • Timezone Monitoring: Identify timezone mismatches and changes
  • Auto-Time Status: Check if automatic time synchronization is enabled (platform-dependent)

Advanced Capabilities

  • Time Difference Calculation: Calculate the difference between current and expected time
    • timeDifferenceMs: Raw milliseconds difference
    • timeDifference: Convenient Duration object for formatting
  • Device Uptime Tracking: Track how long device has been running since last boot
    • deviceUptimeMs: Raw milliseconds since boot
    • deviceUptime: Convenient Duration object for formatting
  • Expected Time Calculation: Compute expected time based on device boot time and uptime

🎯 Platform Support #

Platform Status Technology
Android ✅ Full Support BroadcastReceivers + Settings API
iOS ✅ Full Support NSNotifications + SystemUptime
macOS ✅ Full Support NSNotifications + SystemUptime
Windows ✅ Full Support WM_TIMECHANGE + GetTickCount64
Linux ✅ Polling-based clock_gettime(CLOCK_MONOTONIC)
Web ⚠️ Limited JavaScript Date API

📦 APIs #

Methods

  • checkDateTimeStatus()Future<DateTimeChangeStatus>
    • Get complete current date/time status
  • onDateTimeChangedStream<DateTimeChangeEvent>
    • Stream of real-time change events
  • startListening()Future<void>
    • Begin monitoring time changes
  • stopListening()Future<void>
    • Stop monitoring time changes

Models

DateTimeChangeEvent

class DateTimeChangeEvent {
  final bool isManualChange;          // Was time manually changed?
  final bool hasTimezoneMismatch;     // Is timezone inconsistent?
  final DateTime currentTime;         // Current device time
  final DateTime expectedTime;        // Expected time based on boot
  final String timezone;              // Current timezone ID
  final int timeDifferenceMs;         // Time difference in ms
  final int deviceUptimeMs;           // Device uptime in ms
  Duration get timeDifference;        // Time difference as Duration
  Duration get deviceUptime;          // Device uptime as Duration
}

DateTimeChangeStatus

class DateTimeChangeStatus {
  final bool isAutoTimeEnabled;       // Is auto-time enabled?
  final bool isAutoTimeZoneEnabled;   // Is auto-timezone enabled?
  final bool hasManualChange;         // Was time manually changed?
  final bool hasTimezoneMismatch;     // Is timezone inconsistent?
  final DateTime currentTime;         // Current device time
  final DateTime expectedTime;        // Expected time based on boot
  final String timezone;              // Current timezone ID
  final int timeDifferenceMs;         // Time difference in ms
  final int deviceUptimeMs;           // Device uptime in ms
  Duration get timeDifference;        // Time difference as Duration
  Duration get deviceUptime;          // Device uptime as Duration
}

🛠️ Technical Details #

Android Implementation

  • Uses SystemClock.elapsedRealtime() for accurate uptime tracking
  • Monitors ACTION_TIME_CHANGED, ACTION_TIMEZONE_CHANGED, ACTION_DATE_CHANGED
  • Checks Settings.Global.AUTO_TIME and AUTO_TIME_ZONE
  • Considers changes >5 seconds as manual modifications

iOS/macOS Implementation

  • Uses ProcessInfo.processInfo.systemUptime for uptime tracking
  • Monitors NSSystemTimeZoneDidChangeNotification
  • iOS: UIApplicationSignificantTimeChangeNotification
  • macOS: NSSystemClockDidChange
  • Considers changes >5 seconds as manual modifications

Windows Implementation

  • Uses GetTickCount64() for accurate uptime tracking
  • Listens to WM_TIMECHANGE window messages
  • Monitors system time changes via Windows APIs
  • Considers changes >5 seconds as manual modifications

Linux Implementation

  • Uses clock_gettime(CLOCK_MONOTONIC) for uptime tracking
  • Polling-based approach (every 60 seconds)
  • Monitors /etc/localtime and /etc/timezone
  • Considers changes >5 seconds as manual modifications

Web Implementation

  • Limited capabilities due to browser restrictions
  • Polling-based approach (every 5 seconds)
  • Cannot reliably detect manual changes
  • Device uptime not available

📝 Examples #

Basic Usage

final plugin = SystemDateTimeChange();
final status = await plugin.checkDateTimeStatus();
print('Time difference: ${status.timeDifference}');
print('Device uptime: ${status.deviceUptime}');

Stream Listening

final subscription = plugin.onDateTimeChanged.listen((event) {
  if (event.isManualChange) {
    print('Time was manually changed!');
    print('Difference: ${event.timeDifference}');
  }
});

🎨 Example App #

Includes a comprehensive example app demonstrating:

  • Real-time status monitoring
  • Event history display
  • Time difference visualization
  • Device uptime tracking
  • Material 3 design

📚 Documentation #

  • Complete README with usage examples
  • API reference documentation
  • Platform-specific implementation notes
  • Use case scenarios
  • Troubleshooting guide

⚡ Performance #

  • Zero external dependencies
  • Minimal memory footprint
  • Efficient native API usage
  • No background services (except listeners)
  • Optimized polling intervals

🔒 Privacy & Security #

  • Uses only native platform APIs
  • No network access required
  • No data collection
  • Respects platform security restrictions
  • No special permissions required (except Android broadcast receivers)

📄 License #

MIT License - Free for commercial and personal use

🙏 Acknowledgments #

Built with native APIs for maximum reliability and performance across all platforms.

3
likes
160
points
183
downloads

Publisher

verified publishertusaway.com

Weekly Downloads

A Flutter plugin to detect manual changes to device date/time and timezone mismatches across all platforms.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on system_date_time_change

Packages that implement system_date_time_change