-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
44 lines (40 loc) · 1.33 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
}
}