1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_bloc/flutter_bloc.dart' ;
2
3
import 'package:morazan/util/app_theme.dart' ;
3
4
import 'package:morazan/pages/satelites/satelites_widget.dart' ;
4
5
import 'package:morazan/util/constants.dart' ;
6
+ import 'package:morazan/util/language.dart' ;
7
+
5
8
import 'package:string_capitalize/string_capitalize.dart' ;
9
+ import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
10
+ import 'package:morazan/locale_bloc/locale_bloc.dart' ;
11
+
6
12
7
- class MorazanApp extends StatefulWidget {
8
- const MorazanApp ({Key ? key}) : super (key: key);
13
+ class BaseWidget extends StatefulWidget {
14
+ const BaseWidget ({Key ? key}) : super (key: key);
9
15
10
16
@override
11
- State <MorazanApp > createState () => _MorazanAppState ();
17
+ State <BaseWidget > createState () => _BaseWidgetState ();
12
18
}
13
19
14
- class _MorazanAppState extends State <MorazanApp > {
20
+ class _BaseWidgetState extends State <BaseWidget > {
15
21
static const _satelites = Satelites .values;
16
22
var _actualSatelite = _satelites[0 ];
17
23
var _themeMode = ThemeMode .system;
18
24
19
25
@override
20
26
Widget build (BuildContext context) {
27
+ final l10n = AppLocalizations .of (context)! ;
28
+ // String welcomeMessage = l10n.temperatura;
21
29
var colorScheme = Theme .of (context).colorScheme;
22
- var themeIcon = _themeMode == ThemeMode .light
30
+ var themeIcon = Theme . of (context).brightness == Brightness .light
23
31
? Icons .dark_mode
24
32
: Icons .light_mode;
25
33
26
34
return MaterialApp (
35
+ locale: const Locale ("en" ), // Establece el idioma predeterminado a inglés
36
+ supportedLocales: AppLocalizations .supportedLocales,
37
+ localizationsDelegates: AppLocalizations .localizationsDelegates,
38
+ //Fin de local language
27
39
title: 'Morazan' ,
28
40
theme: AppTheme .lightTheme,
29
41
darkTheme: AppTheme .darkTheme,
@@ -33,17 +45,24 @@ class _MorazanAppState extends State<MorazanApp> {
33
45
title: Row (
34
46
mainAxisAlignment: MainAxisAlignment .spaceBetween,
35
47
children: [
36
- Text ("Detalles de ${_actualSatelite .name .capitalize ()}" ),
48
+ Text (" ${l10n .testMedium } ${_actualSatelite .name .capitalize ()}" ),
49
+ BlocBuilder <LocaleBloc , LocaleState >(
50
+ builder: (context, state) {
51
+ return _buildLanguageSwitch (
52
+ context,
53
+ Theme .of (context),
54
+ state,
55
+ );
56
+ },
57
+ ),
37
58
TextButton (
38
- onPressed: () {
39
- setState (() {
40
- _themeMode = _themeMode == ThemeMode .light
41
- ? ThemeMode .dark
42
- : ThemeMode .light;
43
- });
44
- },
59
+ onPressed: () => setState (() {
60
+ _themeMode = Theme .of (context).brightness == Brightness .light
61
+ ? ThemeMode .dark
62
+ : ThemeMode .light;
63
+ }),
45
64
child: Icon (themeIcon, size: 20 , color: colorScheme.onPrimary),
46
- ),
65
+ ),
47
66
],
48
67
),
49
68
),
@@ -56,11 +75,9 @@ class _MorazanAppState extends State<MorazanApp> {
56
75
value: _actualSatelite,
57
76
icon: Icon (Icons .expand_more,
58
77
size: 24 , color: colorScheme.outline),
59
- onChanged: (satelite) {
60
- setState (() {
61
- _actualSatelite = satelite! ;
62
- });
63
- },
78
+ onChanged: (satelite) => setState (() {
79
+ _actualSatelite = satelite! ;
80
+ }),
64
81
items: _satelites
65
82
.map ((satelite) => DropdownMenuItem (
66
83
value: satelite,
@@ -69,11 +86,68 @@ class _MorazanAppState extends State<MorazanApp> {
69
86
.toList (),
70
87
),
71
88
),
72
- SatelitesPage (satelite: _actualSatelite),
89
+ SatelitesPage (satelite: _actualSatelite, key : UniqueKey ()), // Use UniqueKey to force rebuild
73
90
],
74
91
),
75
92
),
76
93
),
77
94
);
78
95
}
96
+
97
+ Widget _buildLanguageSwitch (
98
+ BuildContext context,
99
+ ThemeData theme,
100
+ LocaleState state,
101
+ ) {
102
+ return Stack (
103
+ children: [
104
+ Align (
105
+ alignment: Alignment .topRight,
106
+ child: Padding (
107
+ padding: const EdgeInsets .all (8.0 ),
108
+ child: TextButton (
109
+ onPressed: () {
110
+ context.read <LocaleBloc >().add (
111
+ ChangeLanguage (
112
+ state.selectedLanguage == Language .english
113
+ ? Language .spanish
114
+ : Language .english,
115
+ ),
116
+ );
117
+ },
118
+ child: RichText (
119
+ text: TextSpan (children: [
120
+ TextSpan (
121
+ text: "EN" ,
122
+ style: TextStyle (
123
+ fontSize: 18 ,
124
+ color: state.selectedLanguage == Language .english
125
+ ? Colors .blue
126
+ : const Color .fromARGB (255 , 251 , 250 , 250 ),
127
+ ),
128
+ ),
129
+ const TextSpan (
130
+ text: " | " ,
131
+ style: TextStyle (
132
+ fontSize: 18 ,
133
+ color: Colors .black,
134
+ ),
135
+ ),
136
+ TextSpan (
137
+ text: "ES" ,
138
+ style: TextStyle (
139
+ fontSize: 18 ,
140
+ color: state.selectedLanguage == Language .spanish
141
+ ? Colors .blue
142
+ : const Color .fromARGB (255 , 245 , 245 , 245 ),
143
+ ),
144
+ ),
145
+ ]),
146
+ ),
147
+ ),
148
+ ),
149
+ ),
150
+ ],
151
+ );
152
+ }
79
153
}
0 commit comments