Skip to content

Commit 608d257

Browse files
committed
增加登陆选择语言
1 parent 22d73eb commit 608d257

File tree

7 files changed

+58
-22
lines changed

7 files changed

+58
-22
lines changed

lib/common/localization/default_localizations.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class GSYLocalizations {
1919
};
2020

2121
GSYStringBase get currentLocalized {
22-
return _localizedValues[locale.languageCode];
22+
if(_localizedValues.containsKey(locale.languageCode)) {
23+
return _localizedValues[locale.languageCode];
24+
}
25+
return _localizedValues["en"];
2326
}
2427

2528
///通过 Localizations 加载当前的 GSYLocalizations

lib/common/style/gsy_string_base.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ abstract class GSYStringBase {
5858
String home_language_default;
5959
String home_language_zh;
6060
String home_language_en;
61+
String switch_language;
6162

6263
String home_theme_default;
6364

lib/common/style/gsy_string_en.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class GSYStringEn extends GSYStringBase {
7575
String home_language_zh= "中文";
7676
@override
7777
String home_language_en= "English";
78+
@override
79+
String switch_language= "select language";
7880

7981
@override
8082
String home_theme_default = "Default";

lib/common/style/gsy_string_zh.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class GSYStringZh extends GSYStringBase {
7676
@override
7777
String home_language_en= "English";
7878

79+
@override
80+
String switch_language= "切换语言";
81+
7982
@override
8083
String home_theme_default = "默认主题";
8184
@override

lib/common/utils/common_utils.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
77
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
88
import 'package:fluttertoast/fluttertoast.dart';
9+
import 'package:gsy_github_app_flutter/common/config/config.dart';
10+
import 'package:gsy_github_app_flutter/common/local/local_storage.dart';
911
import 'package:gsy_github_app_flutter/common/localization/default_localizations.dart';
1012
import 'package:gsy_github_app_flutter/common/net/address.dart';
1113
import 'package:gsy_github_app_flutter/common/redux/gsy_state.dart';
@@ -146,6 +148,19 @@ class CommonUtils {
146148
return ThemeData(primarySwatch: color, platform: TargetPlatform.android);
147149
}
148150

151+
152+
static showLanguageDialog(BuildContext context, Store store) {
153+
List<String> list = [
154+
CommonUtils.getLocale(context).home_language_default,
155+
CommonUtils.getLocale(context).home_language_zh,
156+
CommonUtils.getLocale(context).home_language_en,
157+
];
158+
CommonUtils.showCommitOptionDialog(context, list, (index) {
159+
CommonUtils.changeLocale(store, index);
160+
LocalStorage.save(Config.LOCALE, index.toString());
161+
}, height: 150.0);
162+
}
163+
149164
/**
150165
* 切换语言
151166
*/

lib/page/login_page.dart

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter_redux/flutter_redux.dart';
55
import 'package:gsy_github_app_flutter/common/config/config.dart';
66
import 'package:gsy_github_app_flutter/common/dao/user_dao.dart';
77
import 'package:gsy_github_app_flutter/common/local/local_storage.dart';
8+
import 'package:gsy_github_app_flutter/common/localization/default_localizations.dart';
89
import 'package:gsy_github_app_flutter/common/redux/gsy_state.dart';
910
import 'package:gsy_github_app_flutter/common/style/gsy_style.dart';
1011
import 'package:gsy_github_app_flutter/common/utils/common_utils.dart';
@@ -69,19 +70,25 @@ class _LoginPageState extends State<LoginPage> {
6970
child: SingleChildScrollView(
7071
child: new Card(
7172
elevation: 5.0,
72-
shape: new RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10.0))),
73+
shape: new RoundedRectangleBorder(
74+
borderRadius: BorderRadius.all(Radius.circular(10.0))),
7375
color: Color(GSYColors.cardWhite),
74-
margin: const EdgeInsets.only(left:30.0, right: 30.0),
76+
margin: const EdgeInsets.only(left: 30.0, right: 30.0),
7577
child: new Padding(
76-
padding: new EdgeInsets.only(left: 30.0, top: 40.0, right: 30.0, bottom: 0.0),
78+
padding: new EdgeInsets.only(
79+
left: 30.0, top: 40.0, right: 30.0, bottom: 0.0),
7780
child: new Column(
7881
mainAxisAlignment: MainAxisAlignment.center,
7982
mainAxisSize: MainAxisSize.min,
8083
children: <Widget>[
81-
new Image(image: new AssetImage(GSYICons.DEFAULT_USER_ICON), width: 90.0, height: 90.0),
84+
new Image(
85+
image: new AssetImage(GSYICons.DEFAULT_USER_ICON),
86+
width: 90.0,
87+
height: 90.0),
8288
new Padding(padding: new EdgeInsets.all(10.0)),
8389
new GSYInputWidget(
84-
hintText: CommonUtils.getLocale(context).login_username_hint_text,
90+
hintText: CommonUtils.getLocale(context)
91+
.login_username_hint_text,
8592
iconData: GSYICons.LOGIN_USER,
8693
onChanged: (String value) {
8794
_userName = value;
@@ -90,7 +97,8 @@ class _LoginPageState extends State<LoginPage> {
9097
),
9198
new Padding(padding: new EdgeInsets.all(10.0)),
9299
new GSYInputWidget(
93-
hintText: CommonUtils.getLocale(context).login_password_hint_text,
100+
hintText: CommonUtils.getLocale(context)
101+
.login_password_hint_text,
94102
iconData: GSYICons.LOGIN_PW,
95103
obscureText: true,
96104
onChanged: (String value) {
@@ -111,18 +119,32 @@ class _LoginPageState extends State<LoginPage> {
111119
return;
112120
}
113121
CommonUtils.showLoadingDialog(context);
114-
UserDao.login(_userName.trim(), _password.trim(), store).then((res) {
122+
UserDao.login(
123+
_userName.trim(), _password.trim(), store)
124+
.then((res) {
115125
Navigator.pop(context);
116126
if (res != null && res.result) {
117-
new Future.delayed(const Duration(seconds: 1), () {
127+
new Future.delayed(const Duration(seconds: 1),
128+
() {
118129
NavigatorUtils.goHome(context);
119130
return true;
120131
});
121132
}
122133
});
123134
},
124135
),
125-
new Padding(padding: new EdgeInsets.all(30.0)),
136+
new Padding(padding: new EdgeInsets.all(15.0)),
137+
InkWell(
138+
onTap: () {
139+
CommonUtils.showLanguageDialog(context, store);
140+
},
141+
child: Text(
142+
CommonUtils.getLocale(context).switch_language,
143+
style: TextStyle(
144+
color: Color(GSYColors.subTextColor)),
145+
),
146+
),
147+
new Padding(padding: new EdgeInsets.all(15.0)),
126148
],
127149
),
128150
),

lib/widget/home_drawer.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,7 @@ class HomeDrawer extends StatelessWidget {
5050
}, colorList: CommonUtils.getThemeListColor());
5151
}
5252

53-
showLanguageDialog(BuildContext context, Store store) {
54-
List<String> list = [
55-
CommonUtils.getLocale(context).home_language_default,
56-
CommonUtils.getLocale(context).home_language_zh,
57-
CommonUtils.getLocale(context).home_language_en,
58-
];
59-
CommonUtils.showCommitOptionDialog(context, list, (index) {
60-
CommonUtils.changeLocale(store, index);
61-
LocalStorage.save(Config.LOCALE, index.toString());
62-
}, height: 150.0);
63-
}
53+
6454

6555
@override
6656
Widget build(BuildContext context) {
@@ -163,7 +153,7 @@ class HomeDrawer extends StatelessWidget {
163153
style: GSYConstant.normalText,
164154
),
165155
onTap: () {
166-
showLanguageDialog(context, store);
156+
CommonUtils.showLanguageDialog(context, store);
167157
}),
168158
new ListTile(
169159
title: new Text(

0 commit comments

Comments
 (0)