system_time_change_detector 0.0.2 copy "system_time_change_detector: ^0.0.2" to clipboard
system_time_change_detector: ^0.0.2 copied to clipboard

Detect system time / timezone changes

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:system_time_change_detector/systemtimechangedetector.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = '...';
  String _timeChange = '';
  final _timechangedetectorPlugin = SystemTimeChangeDetector();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _timechangedetectorPlugin.getPlatformVersion() ?? 'Unknown platform version';
      await _timechangedetectorPlugin.getSystemTimeChange(() {
        debugPrint("TIME CHANGING");
        _timeChange = DateTime.now().toIso8601String();
        setState(() {

        });
      });
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    } catch (e) {
      platformVersion = '$e';
      debugPrint("Error $e");
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Running on: $_platformVersion\n'),
              SizedBox(height: 30),
              Text('System Time changed at: $_timeChange'),
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
0
points
388
downloads

Publisher

unverified uploader

Weekly Downloads

Detect system time / timezone changes

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on system_time_change_detector