-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
105 lines (90 loc) · 2.95 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
import 'dart:ui';
import 'package:simple_localization_example/localizations/example_localization.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter/material.dart';
class MainApp extends StatefulWidget {
const MainApp({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
Locale _locale = window.locale;
Locale get locale => _locale;
@override
Widget build(BuildContext context) {
return MaterialApp(
locale: _locale,
onGenerateTitle: (context) =>
ExampleLocalizations.of(context)[ExampleLocalizationsEnums.appBarTitle],
localizationsDelegates: const [
// ExampleLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: const [
Locale('en', ''),
Locale('es', ''),
Locale('pt', ''),
],
theme: ThemeData(
brightness: Brightness.dark,
primarySwatch: Colors.blue,
),
home: Builder(
builder: buildHome
),
);
}
Widget buildHome(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(ExampleLocalizations.of(context)[ExampleLocalizationsEnums.appBarTitle]),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Text(ExampleLocalizations.of(context)[ExampleLocalizationsEnums.bodyTitle], style: Theme.of(context).textTheme.headline3,),
),
Padding(
padding: const EdgeInsets.only(bottom: 20),
child: Text(ExampleLocalizations.of(context)[ExampleLocalizationsEnums.bodyDescription], style: Theme.of(context).textTheme.headline4, textAlign: TextAlign.center,),
),
ElevatedButton(
style: const ButtonStyle(
tapTargetSize: MaterialTapTargetSize.padded
),
child: Text(ExampleLocalizations.of(context)[ButtonsLocalizationsEnums.en]),
onPressed: () => changeLocale(const Locale('en')),
),
ElevatedButton(
style: const ButtonStyle(
tapTargetSize: MaterialTapTargetSize.padded
),
child: Text(ExampleLocalizations.of(context)[ButtonsLocalizationsEnums.es]),
onPressed: () => changeLocale(const Locale('es')),
),
ElevatedButton(
style: const ButtonStyle(
tapTargetSize: MaterialTapTargetSize.padded
),
child: Text(ExampleLocalizations.of(context)[ButtonsLocalizationsEnums.pt]),
onPressed: () => changeLocale(const Locale('pt')),
),
],
),
),
);
}
void changeLocale(Locale newLocale) {
setState(() {
_locale = newLocale;
});
}
}
void main() => runApp(const MainApp());