flutter_timezone_observer 1.0.0 copy "flutter_timezone_observer: ^1.0.0" to clipboard
flutter_timezone_observer: ^1.0.0 copied to clipboard

Get and observe the device's IANA timezone. Includes mixins to automatically sync the timezone when the app resumes.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_timezone_observer/app_lifecycle_aware_timezone_observer_mixin.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp>
    with AppLifecycleAwareTimezoneObserverMixin {
  @override
  void onTimezoneChanged(String newZone) {
    if (!mounted) return;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData.dark(),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Timezone Observer Example'),
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(24),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                const Text(
                  'Current device timezone (via Mixin):',
                  style: TextStyle(fontSize: 16),
                ),
                const SizedBox(height: 8),
                Text(
                  currentZone ?? 'Loading...',
                  style: const TextStyle(
                    fontSize: 24,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 32),
                const Text(
                  'To test: Background the app, '
                  'change your device timezone in settings, '
                  'and return to the app.',
                  textAlign: TextAlign.center,
                  style: TextStyle(color: Colors.grey),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
160
points
30
downloads

Publisher

verified publisherkalaganov.dev

Weekly Downloads

Get and observe the device's IANA timezone. Includes mixins to automatically sync the timezone when the app resumes.

Repository (GitHub)
View/report issues

Topics

#timezone #zone #time #observer #native

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_timezone_observer

Packages that implement flutter_timezone_observer