Skip to content

Commit 3a9ea2d

Browse files
committed
多语言切换完成
1 parent 470975d commit 3a9ea2d

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

lib/common/style/GSYStringEn.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GSYStringEn extends GSYStringBase {
3737
String loading_text = "Loading···";
3838

3939
@override
40-
String option_web = "open browser";
40+
String option_web = "browser";
4141
@override
4242
String option_copy = "copy";
4343
@override

lib/page/HomePage.dart

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,38 @@ class HomePage extends StatelessWidget {
3737
));
3838
}
3939

40+
_renderTab(icon, text) {
41+
return new Tab(
42+
child: new Column(
43+
mainAxisAlignment: MainAxisAlignment.center,
44+
children: <Widget>[new Icon(icon, size: 16.0), new Text(text)],
45+
),
46+
);
47+
}
48+
4049
// This widget is the root of your application.
4150
@override
4251
Widget build(BuildContext context) {
52+
List<Widget> tabs = [
53+
_renderTab(GSYICons.MAIN_DT, CommonUtils.getLocale(context).home_dynamic),
54+
_renderTab(GSYICons.MAIN_QS, CommonUtils.getLocale(context).home_trend),
55+
_renderTab(GSYICons.MAIN_MY, CommonUtils.getLocale(context).home_my),
56+
];
4357
return WillPopScope(
4458
onWillPop: () {
4559
return _dialogExitApp(context);
4660
},
4761
child: new GSYTabBarWidget(
4862
drawer: new HomeDrawer(),
4963
type: GSYTabBarWidget.BOTTOM_TAB,
50-
tabItems: [
51-
new Tab(
52-
child: new Column(
53-
mainAxisAlignment: MainAxisAlignment.center,
54-
children: <Widget>[new Icon(GSYICons.MAIN_DT, size: 16.0), new Text(CommonUtils.getLocale(context).home_dynamic)],
55-
),
56-
),
57-
new Tab(
58-
child: new Column(
59-
mainAxisAlignment: MainAxisAlignment.center,
60-
children: <Widget>[new Icon(GSYICons.MAIN_QS, size: 16.0), new Text(CommonUtils.getLocale(context).home_trend)],
61-
),
62-
),
63-
new Tab(
64-
child: new Column(
65-
mainAxisAlignment: MainAxisAlignment.center,
66-
children: <Widget>[new Icon(GSYICons.MAIN_MY, size: 16.0), new Text(CommonUtils.getLocale(context).home_my)],
67-
),
68-
),
69-
],
64+
tabItems: tabs,
7065
tabViews: [
7166
new DynamicPage(),
7267
new TrendPage(),
7368
new MyPage(),
7469
],
7570
backgroundColor: GSYColors.primarySwatch,
76-
indicatorColor:Color(GSYColors.white),
71+
indicatorColor: Color(GSYColors.white),
7772
title: GSYTitleBar(
7873
GSYLocalizations.of(context).currentLocalized.app_name,
7974
iconData: GSYICons.MAIN_SEARCH,

lib/widget/GSYTabBarWidget.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ class GSYTabBarWidget extends StatefulWidget {
4949
@override
5050
_GSYTabBarState createState() => new _GSYTabBarState(
5151
type,
52-
tabItems,
5352
tabViews,
54-
backgroundColor,
5553
indicatorColor,
5654
title,
5755
drawer,
@@ -66,12 +64,8 @@ class GSYTabBarWidget extends StatefulWidget {
6664
class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderStateMixin {
6765
final int _type;
6866

69-
final List<Widget> _tabItems;
70-
7167
final List<Widget> _tabViews;
7268

73-
final Color _backgroundColor;
74-
7569
final Color _indicatorColor;
7670

7771
final Widget _title;
@@ -86,16 +80,24 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
8680

8781
final ValueChanged<int> _onPageChanged;
8882

89-
_GSYTabBarState(this._type, this._tabItems, this._tabViews, this._backgroundColor, this._indicatorColor, this._title, this._drawer,
90-
this._floatingActionButton, this._tarWidgetControl, this._pageController, this._onPageChanged)
91-
: super();
83+
_GSYTabBarState(
84+
this._type,
85+
this._tabViews,
86+
this._indicatorColor,
87+
this._title,
88+
this._drawer,
89+
this._floatingActionButton,
90+
this._tarWidgetControl,
91+
this._pageController,
92+
this._onPageChanged,
93+
) : super();
9294

9395
TabController _tabController;
9496

9597
@override
9698
void initState() {
9799
super.initState();
98-
_tabController = new TabController(vsync: this, length: _tabItems.length);
100+
_tabController = new TabController(vsync: this, length: widget.tabItems.length);
99101
}
100102

101103
///整个页面dispose时,记得把控制器也dispose掉,释放内存
@@ -117,7 +119,7 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
117119
title: _title,
118120
bottom: new TabBar(
119121
controller: _tabController,
120-
tabs: _tabItems,
122+
tabs: widget.tabItems,
121123
indicatorColor: _indicatorColor,
122124
),
123125
),
@@ -151,7 +153,7 @@ class _GSYTabBarState extends State<GSYTabBarWidget> with SingleTickerProviderSt
151153
child: new TabBar(
152154
//TabBar导航标签,底部导航放到Scaffold的bottomNavigationBar中
153155
controller: _tabController, //配置控制器
154-
tabs: _tabItems,
156+
tabs: widget.tabItems,
155157
indicatorColor: _indicatorColor, //tab标签的下划线颜色
156158
),
157159
));

0 commit comments

Comments
 (0)