my_timezone 0.0.1+4 copy "my_timezone: ^0.0.1+4" to clipboard
my_timezone: ^0.0.1+4 copied to clipboard

A flutter plugin for getting the local timezone of the device on Android, ios, macos.

example/lib/main.dart

import 'dart:async';

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

void main() => runApp(const MyApp());

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

  @override
  _MyAppState 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();
    } catch (e) {
      print('Could not get the local timezone');
    }
    try {
      _availableTimezones = await MyTimezone.getAvailableTimezones();
      _availableTimezones.sort();
    } catch (e) {
      print('Could not get available timezones');
    }
    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
150
points
6
downloads
screenshot

Publisher

verified publisherwongcoupon.com

Weekly Downloads

A flutter plugin for getting the local timezone of the device on Android, ios, macos.

Repository (GitHub)

Topics

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

Documentation

API reference

Funding

Consider supporting this project:

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

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, js, plugin_platform_interface

More

Packages that depend on my_timezone