my_timezone 0.0.4 copy "my_timezone: ^0.0.4" to clipboard
my_timezone: ^0.0.4 copied to clipboard

A Flutter plugin for reading local and available IANA time zone identifiers on Android, iOS, macOS, and web.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:my_timezone/my_timezone.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 _timezone = 'Unknown';
  List<String> _availableTimezones = <String>[];

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

  Future<void> _initData() async {
    try {
      _timezone = await MyTimezone.getLocalTimezone();
    } on PlatformException catch (error) {
      debugPrint('Could not get the local timezone: $error');
    }
    try {
      _availableTimezones = await MyTimezone.getAvailableTimezones();
      _availableTimezones.sort();
    } on PlatformException catch (error) {
      debugPrint('Could not get available timezones: $error');
    }
    if (mounted) {
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Local timezone app')),
        body: Column(
          children: <Widget>[
            Text('Local timezone: $_timezone\n'),
            const Text('Available timezones:'),
            Expanded(
              child: ListView.builder(
                itemCount: _availableTimezones.length,
                itemBuilder: (_, index) => Text(_availableTimezones[index]),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
160
points
55
downloads
screenshot

Documentation

API reference

Publisher

verified publisherwongcoupon.com

Weekly Downloads

A Flutter plugin for reading local and available IANA time zone identifiers on Android, iOS, macOS, and web.

Repository (GitHub)
View/report issues

Topics

#timezone #local-time #device-info #flutter-plugin #cross-platform

Funding

Consider supporting this project:

buymeacoffee.com
ko-fi.com
github.com
paypal.me

License

MIT (license)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on my_timezone

Packages that implement my_timezone