Skip to content

Commit 218702e

Browse files
committed
注释
1 parent 83dd371 commit 218702e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/common/localization/GSYLocalizationsDelegate.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
55
import 'package:gsy_github_app_flutter/common/localization/DefaultLocalizations.dart';
66

77
/**
8+
* 多语言代理
89
* Created by guoshuyu
910
* Date: 2018-08-15
1011
*/
@@ -14,9 +15,11 @@ class GSYLocalizationsDelegate extends LocalizationsDelegate<GSYLocalizations> {
1415

1516
@override
1617
bool isSupported(Locale locale) {
18+
///支持中文和英语
1719
return ['en', 'zh'].contains(locale.languageCode);
1820
}
1921

22+
///根据locale,创建一个对象用于提供当前locale下的文本显示
2023
@override
2124
Future<GSYLocalizations> load(Locale locale) {
2225
return new SynchronousFuture<GSYLocalizations>(new GSYLocalizations(locale));
@@ -27,5 +30,6 @@ class GSYLocalizationsDelegate extends LocalizationsDelegate<GSYLocalizations> {
2730
return false;
2831
}
2932

33+
///全局静态的代理
3034
static GSYLocalizationsDelegate delegate = new GSYLocalizationsDelegate();
3135
}

lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class FlutterReduxApp extends StatelessWidget {
4747
store: store,
4848
child: new StoreBuilder<GSYState>(builder: (context, store) {
4949
return new MaterialApp(
50+
///多语言实现代理
5051
localizationsDelegates: [
5152
GlobalMaterialLocalizations.delegate,
5253
GlobalWidgetsLocalizations.delegate,
@@ -61,6 +62,7 @@ class FlutterReduxApp extends StatelessWidget {
6162
return WelcomePage();
6263
},
6364
HomePage.sName: (context) {
65+
///通过 Localizations.override 包裹一层,
6466
return new GSYLocalizations(
6567
child: new HomePage(),
6668
);
@@ -95,6 +97,7 @@ class _GSYLocalizations extends State<GSYLocalizations> {
9597
@override
9698
Widget build(BuildContext context) {
9799
return new StoreBuilder<GSYState>(builder: (context, store) {
100+
///通过 StoreBuilder 和 Localizations 实现实时多语言切换
98101
return new Localizations.override(
99102
context: context,
100103
locale: store.state.locale,

0 commit comments

Comments
 (0)