codecov GitHub Buy Me A Coffee PayPal Sponsor Support Me on Ko-fi

my_timezone is a Flutter plugin that returns the local timezone and available timezones on Android, iOS, macOS, and web.

Features

  • Get the local timezone from the native layer.
  • Get the list of available timezones.
  • Works across Android, iOS, macOS, and web.

Installation

Add the following to your pubspec.yaml:

my_timezone: ^0.0.1+4

Then run:

flutter pub get

Basic usage

import 'package:my_timezone/my_timezone.dart';

final String localTimezone = await MyTimezone.getLocalTimezone();
final List<String> availableTimezones =
    await MyTimezone.getAvailableTimezones();

Example in a widget

class _MyAppState extends State<MyApp> {
  String? _timezone;

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

  Future<void> _loadTimezone() async {
    final timezone = await MyTimezone.getLocalTimezone();
    if (!mounted) return;
    setState(() => _timezone = timezone);
  }
}

Contribution

If you have any suggestions or find any issues, feel free to open an issue or submit a pull request on GitHub.

Developer Team:

Any comments please contact us ThaoDoan and DucNguyen.