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

A flutter plugin for getting the local timezone of the device.

example/lib/main.dart

import 'dart:async';
import 'dart:developer';

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

void main() => runApp(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 FlutterNativeTimezoneLatest.getLocalTimezone();
    } catch (e) {
      log('Could not get the local timezone');
    }
    try {
      _availableTimezones =
          await FlutterNativeTimezoneLatest.getAvailableTimezones();
      _availableTimezones.sort();
    } catch (e) {
      log('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'),
            Text('Available timezones:'),
            Expanded(
              child: ListView.builder(
                itemCount: _availableTimezones.length,
                itemBuilder: (_, index) => Text(_availableTimezones[index]),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
140
points
158
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter plugin for getting the local timezone of the device.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, js

More

Packages that depend on flutter_native_timezone_latest