-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.dart
119 lines (106 loc) 路 3.15 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Dart imports:
import 'dart:async';
// Flutter imports:
import 'package:flutter/material.dart';
// Package imports:
import 'package:dash_flags/dash_flags.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Dash Flags - Example',
theme: ThemeData(useMaterial3: true),
home: const FlagsScreen(),
);
}
}
class FlagsScreen extends StatefulWidget {
const FlagsScreen({
Key? key,
}) : super(key: key);
@override
State<FlagsScreen> createState() => _FlagsScreenState();
}
class _FlagsScreenState extends State<FlagsScreen> {
static const flagHeight = 120.0;
final List<Country> _countries = Country.values;
final List<Language> _languages = Language.values;
final List<Timezone> _timezones = Timezone.values;
int _selectedCountryIndex = 0;
int _selectedLanguageIndex = 0;
int _selectedTimezoneIndex = 0;
@override
void initState() {
super.initState();
Timer.periodic(
const Duration(seconds: 1),
(timer) {
setState(() {
_selectedCountryIndex == _countries.length - 1
? _selectedCountryIndex = 0
: _selectedCountryIndex++;
_selectedLanguageIndex == _languages.length - 1
? _selectedLanguageIndex = 0
: _selectedLanguageIndex++;
_selectedTimezoneIndex == _timezones.length - 1
? _selectedTimezoneIndex = 0
: _selectedTimezoneIndex++;
});
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Dash Flags - Example'),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(24),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildLabel(
'Country: ${_countries[_selectedCountryIndex].name.toUpperCase()}'),
const SizedBox(height: 24),
CountryFlag(
country: _countries[_selectedCountryIndex],
height: flagHeight,
),
const SizedBox(height: 48),
_buildLabel(
'Language: ${_languages[_selectedLanguageIndex].name.toUpperCase()}'),
const SizedBox(height: 24),
LanguageFlag(
language: _languages[_selectedLanguageIndex],
height: flagHeight,
),
const SizedBox(height: 48),
_buildLabel(
'Timezone:\n${_timezones[_selectedTimezoneIndex].name.toUpperCase()}'),
const SizedBox(height: 24),
TimezoneFlag(
timezone: _timezones[_selectedTimezoneIndex],
height: flagHeight,
),
],
),
),
),
);
}
Text _buildLabel(String text) {
return Text(
text,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500,
),
);
}
}