timezone_to_country 2.2.0 copy "timezone_to_country: ^2.2.0" to clipboard
timezone_to_country: ^2.2.0 copied to clipboard

Extension method for translation Time Zone Id to ISO 3166-1 alpha-2 code (e.g. 'Asia/Seoul' to 'KR')

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Local country code app'),
        ),
        body: Center(
          child: FutureBuilder<String>(
            future: TimeZoneToCountry.getLocalCountryCode(),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) {
                return const CircularProgressIndicator.adaptive();
              }
              if (snapshot.hasError) {
                return const Text('Could not get the local country code');
              }

              String countryCode = snapshot.data!;
              return Text(
                'Local country code: ${countryCode} ${EmojiUtils.country(countryCode)}',
                style: Theme.of(context).textTheme.headlineSmall,
              );
            },
          ),
        ),
      ),
    );
  }
}

class EmojiUtils {
  static String country(String countryCode) {
    String flag = countryCode.replaceAllMapped(RegExp(r'[A-Z]'),
        (match) => String.fromCharCode(match.group(0)!.codeUnitAt(0) + 127397));
    return flag;
  }
}
9
likes
140
pub points
91%
popularity

Publisher

unverified uploader

Extension method for translation Time Zone Id to ISO 3166-1 alpha-2 code (e.g. 'Asia/Seoul' to 'KR')

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_timezone, timezone

More

Packages that depend on timezone_to_country