Skip to content

Commit 10377ca

Browse files
committed
fix multi language
1 parent 845ef41 commit 10377ca

File tree

13 files changed

+139
-82
lines changed

13 files changed

+139
-82
lines changed

covid_statistic/lib/generated/i18n.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ class S implements WidgetsLocalizations {
2828
String get more => 'More';
2929
String get topInfectedCountries => 'Top Infected Countries';
3030
String get precautions => 'Precautions';
31+
32+
String get protectiveMask => 'Protective Mask';
33+
String get protectiveMaskDesc => 'Always remember to wear a protective mask when stepping out.';
34+
String get washHands => 'Wash Hands';
35+
String get washHandsDesc => 'Wash your hands often with soap and water and for 20 seconds at least.';
36+
String get coverCough => 'Cover Cough';
37+
String get coverCoughDesc => 'Cough or sneeze into your elbow or cover your mouth with a disposable napkin.';
38+
String get sanitizeOften => 'Sanitize Often';
39+
String get sanitizeOftenDesc => 'Use alchohol based sanitizer if water and soap are unavailable.';
40+
String get noFaceTouching => 'No Face Touching';
41+
String get noFaceTouchingDesc => 'Don\'t touch your eyes, nose or mouth often and with unwashed hands.';
42+
String get socialDistancing => 'Social Distancing';
43+
String get socialDistancingDesc => 'Keep 7m distance from other people. Stay at home and avoid gatherings.';
3144
}
3245

3346
class $vi extends S {
@@ -42,11 +55,24 @@ class $vi extends S {
4255
@override String get totalDeaths => 'Đã tử vong';
4356
@override String get recovered => 'Chữa khỏi';
4457
@override String get newCases => 'Mới nhiễm';
45-
@override String get newDeaths => 'Mới tử vong';
58+
@override String get newDeaths => 'Mới báo tử';
4659
@override String get activeCases => 'Đang điều trị';
4760
@override String get more => 'Xem thêm';
4861
@override String get topInfectedCountries => 'Quốc gia lây nhiễm cao';
4962
@override String get precautions => 'Biện pháp phòng ngừa';
63+
64+
@override String get protectiveMask => 'Đeo khẩu trang';
65+
@override String get protectiveMaskDesc => 'Luôn luôn đẹo khẩu trang khi ra ngoài';
66+
@override String get washHands => 'Rửa tay';
67+
@override String get washHandsDesc => 'Rửa tay thường xuyên với xà bông ít nhất 20 giây';
68+
@override String get coverCough => 'Che miệng khi ho';
69+
@override String get coverCoughDesc => 'Dùng khuỷu tay hoặc giấy ăn dùng một lần để che miệng khi ho hoặc hắt hơi';
70+
@override String get sanitizeOften => 'Khử trùng';
71+
@override String get sanitizeOftenDesc => 'Sử dụng chất khử trùng có cồn nếu không có nước và xà phòng.';
72+
@override String get noFaceTouching => 'Tránh đưa tay lên mặt';
73+
@override String get noFaceTouchingDesc => 'Hạn chế đưa tay lên mắt, mũi và miệng.';
74+
@override String get socialDistancing => 'Giữ khoảng cách';
75+
@override String get socialDistancingDesc => 'Giữ khoảng cách 7m với mọi người. Nên ở nhà và tránh tụ tập.';
5076
}
5177

5278
class $en extends S {

covid_statistic/lib/helper/app_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:io';
22

3-
import 'package:covid_statistic/utils/app_theme.dart';
3+
import 'package:covid_statistic/utils/themes/app_theme.dart';
44
import 'package:covid_statistic/utils/custom_colors.dart';
55
import 'package:flutter/material.dart';
66
import 'package:google_fonts/google_fonts.dart';

covid_statistic/lib/helper/locale_dropdown.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:covid_statistic/helper/spinning_widget.dart';
22
import 'package:covid_statistic/model/localization.dart';
3-
import 'package:covid_statistic/utils/app_theme.dart';
3+
import 'package:covid_statistic/utils/themes/app_theme.dart';
44
import 'package:covid_statistic/utils/constant.dart';
55
import 'package:covid_statistic/utils/local_utils.dart';
66
import 'package:covid_statistic/utils/utility.dart';

covid_statistic/lib/helper/title_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:covid_statistic/utils/app_theme.dart';
1+
import 'package:covid_statistic/utils/themes/app_theme.dart';
22
import 'package:flutter/material.dart';
33
import 'package:google_fonts/google_fonts.dart';
44

covid_statistic/lib/main.dart

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:covid_statistic/generated/i18n.dart';
22
import 'package:covid_statistic/provider/language_provider.dart';
33
import 'package:covid_statistic/provider/theme_provider.dart';
44
import 'package:covid_statistic/router/router.dart';
5-
import 'package:covid_statistic/utils/app_theme.dart';
5+
import 'package:covid_statistic/utils/themes/app_theme.dart';
66
import 'package:covid_statistic/utils/constant.dart';
77
import 'package:flutter/material.dart';
88
import 'package:flutter/services.dart';
@@ -38,15 +38,12 @@ class App extends StatelessWidget {
3838
class MyApp extends StatelessWidget {
3939
@override
4040
Widget build(BuildContext context) {
41-
final theme = AppStateProvider.of<AppState>(context).currentTheme;
4241
final language = AppStateProvider.of<AppState>(context).languageCode;
4342

4443
return ValueBuilder<String>(
4544
streamed: language,
46-
// initialData: AppTheme.defaultLight,
4745
builder: (context, snapshot) => MaterialApp(
4846
title: 'Covid-19 Pandemic',
49-
// theme: _buildThemeData(snapshot.data),
5047
localizationsDelegates: const [
5148
S.delegate,
5249
GlobalMaterialLocalizations.delegate,
@@ -61,17 +58,4 @@ class MyApp extends StatelessWidget {
6158
),
6259
);
6360
}
64-
65-
ThemeData _buildThemeData(MyTheme appTheme) {
66-
return ThemeData(
67-
brightness: appTheme.brightness,
68-
backgroundColor: appTheme.backgroundColor,
69-
scaffoldBackgroundColor: appTheme.scaffoldBackgroundColor,
70-
primaryColor: appTheme.primaryColor,
71-
primaryColorBrightness: appTheme.primaryColorBrightness,
72-
accentColor: appTheme.accentColor,
73-
primaryColorLight: appTheme.primaryColorLight,
74-
primaryColorDark: appTheme.primaryColorDark,
75-
);
76-
}
7761
}

covid_statistic/lib/model/app_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:covid_statistic/network/api.dart';
2-
import 'package:covid_statistic/utils/app_theme.dart';
2+
import 'package:covid_statistic/utils/themes/app_theme.dart';
33
import 'package:covid_statistic/utils/constant.dart';
44
import 'package:covid_statistic/utils/utility.dart';
55
import 'package:frideos/frideos.dart';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Prevention {
2+
String prevention, description, imagePath;
3+
4+
Prevention({this.prevention, this.description, this.imagePath});
5+
6+
Prevention.fromJson(Map<String, dynamic> json)
7+
: prevention = json['prevention'],
8+
description = json['desc'],
9+
imagePath = json['imgPath'];
10+
}

covid_statistic/lib/pages/main/main_drop.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:covid_statistic/model/main_info.dart';
2-
import 'package:covid_statistic/utils/app_theme.dart';
2+
import 'package:covid_statistic/utils/themes/app_theme.dart';
33
import 'package:flutter/material.dart';
44
import 'package:google_fonts/google_fonts.dart';
55

covid_statistic/lib/pages/main/main_page.dart

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import 'package:covid_statistic/model/app_state.dart';
88
import 'package:covid_statistic/model/covid_info.dart';
99
import 'package:covid_statistic/model/country_info.dart';
1010
import 'package:covid_statistic/model/main_info.dart';
11+
import 'package:covid_statistic/model/prevention.dart';
1112
import 'package:covid_statistic/pages/main/main_drop.dart';
1213
import 'package:covid_statistic/pages/main/precautions/precaution_grid.dart';
1314
import 'package:covid_statistic/pages/main/stats/pandemic_view.dart';
1415
import 'package:covid_statistic/pages/main/top_country/country_stats.dart';
15-
import 'package:covid_statistic/utils/app_theme.dart';
16+
import 'package:covid_statistic/utils/themes/app_theme.dart';
17+
import 'package:covid_statistic/utils/constant.dart';
1618
import 'package:covid_statistic/utils/local_utils.dart';
1719
import 'package:covid_statistic/utils/utility.dart';
1820
import 'package:covid_statistic/view_model/main_vm.dart';
1921
import 'package:flutter/cupertino.dart';
2022
import 'package:flutter/material.dart';
2123
import 'package:frideos/frideos.dart';
2224
import 'package:google_fonts/google_fonts.dart';
25+
import 'package:shared_preferences/shared_preferences.dart';
2326

2427
class MainPage extends StatefulWidget {
2528
const MainPage({Key key}) : super(key: key);
@@ -50,8 +53,6 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
5053
});
5154

5255
super.initState();
53-
54-
addAllListData();
5556
viewModel.getCountryPandemic();
5657
}
5758

@@ -73,7 +74,7 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
7374
value: snapshot.data,
7475
onChanged: viewModel.mainInfoChanged,
7576
),
76-
subTxt: 'Details',
77+
subTxt: S.of(context).details,
7778
animation: Tween<double>(begin: 0.0, end: 1.0).animate(
7879
CurvedAnimation(
7980
parent: animationController,
@@ -119,7 +120,7 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
119120
builder: (context, AsyncSnapshot<bool> snapshot) {
120121
if (!snapshot.hasData || !snapshot.data) {
121122
return Text(
122-
'Top Infected Countries',
123+
S.of(context).topInfectedCountries,
123124
textAlign: TextAlign.left,
124125
style: GoogleFonts.roboto(
125126
fontWeight: FontWeight.w500,
@@ -136,7 +137,7 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
136137
},
137138
),
138139
),
139-
subTxt: 'More',
140+
subTxt: S.of(context).more,
140141
onViewMore: () {
141142
HUD.showMessage(context, text: 'See more at https://disease.sh/v3');
142143
},
@@ -170,7 +171,7 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
170171
listViews.add(
171172
TitleView(
172173
title: Text(
173-
'Precautions',
174+
S.of(context).precautions,
174175
textAlign: TextAlign.left,
175176
style: GoogleFonts.roboto(
176177
fontWeight: FontWeight.w500,
@@ -179,7 +180,7 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
179180
color: AppTheme.lightText,
180181
),
181182
),
182-
subTxt: 'More',
183+
subTxt: S.of(context).more,
183184
onViewMore: () {
184185
HUD.showMessage(context, text: 'View more');
185186
},
@@ -198,12 +199,40 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
198199
curve:
199200
Interval((1 / count) * 5, 1.0, curve: Curves.fastOutSlowIn))),
200201
animationController: animationController,
202+
preventions: [
203+
Prevention(
204+
prevention: S.of(context).protectiveMask,
205+
description: S.of(context).protectiveMaskDesc,
206+
imagePath: 'assets/prevention/mask.png'),
207+
Prevention(
208+
prevention: S.of(context).washHands,
209+
description: S.of(context).washHandsDesc,
210+
imagePath: 'assets/prevention/wash.png'),
211+
Prevention(
212+
prevention: S.of(context).coverCough,
213+
description: S.of(context).coverCoughDesc,
214+
imagePath: 'assets/prevention/coughCover.png'),
215+
Prevention(
216+
prevention: S.of(context).sanitizeOften,
217+
description: S.of(context).sanitizeOftenDesc,
218+
imagePath: 'assets/prevention/sanitizer.png'),
219+
Prevention(
220+
prevention: S.of(context).noFaceTouching,
221+
description: S.of(context).noFaceTouchingDesc,
222+
imagePath: 'assets/prevention/touch.png'),
223+
Prevention(
224+
prevention: S.of(context).socialDistancing,
225+
description: S.of(context).socialDistancingDesc,
226+
imagePath: 'assets/prevention/socialDistance.png'),
227+
],
201228
),
202229
);
203230
}
204231

205232
@override
206233
Widget build(BuildContext context) {
234+
if (listViews.isEmpty) addAllListData();
235+
207236
final language = AppStateProvider.of<AppState>(context).languageCode;
208237

209238
return WillPopScope(
@@ -220,8 +249,10 @@ class _MainPage extends State<MainPage> with TickerProviderStateMixin {
220249
actions: [
221250
LocaleDropDown(
222251
locale: LocalizationUtils.locale(language.value),
223-
onChanged: (String newValue) {
252+
onChanged: (String newValue) async {
224253
language.value = newValue;
254+
var prefs = await SharedPreferences.getInstance();
255+
prefs.setString(Constant.language, newValue);
225256
},
226257
)
227258
],

0 commit comments

Comments
 (0)