Skip to content

Commit f635939

Browse files
committed
Merge branch 'test'
2 parents d3b1ecf + 2b8faf9 commit f635939

File tree

26 files changed

+516
-268
lines changed

26 files changed

+516
-268
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## **AnimationController**
2+
3+
>
4+
AnimationController是一个特殊的Animation对象
5+
* 默认情况下,AnimationController在给定的时间段内会线性的生成从0.0到1.0的数字
6+
* 创建一个AnimationController时需要传递一个vsync参数,存在vsync时会防止屏幕外动画(动画的UI不在当前屏幕时)消耗不必要的资源,通过将SingleTickerProviderStateMixin添加到类定义中
7+
* 实例化一个AnimationController不会启动它运行,可以通过 .forward()方法启动动画
8+
* AnimationController的addListener方法可以监听动画每一帧
9+
* AnimationController的addStatusListener方法可以监听动画的状态
10+
11+
12+
### 构造方法
13+
``` dart
14+
AnimationController({
15+
double value,
16+
this.duration,
17+
this.debugLabel,
18+
this.lowerBound = 0.0,
19+
this.upperBound = 1.0,
20+
this.animationBehavior = AnimationBehavior.normal,
21+
@required TickerProvider vsync,
22+
})
23+
```
24+
25+
### 属性介绍
26+
* value: 动画值
27+
* lowerBound: 动画最小值
28+
* upperBound: 动画最大值
29+
* duration: 动画持续时间
30+
* vsync: vsync对象会绑定动画的定时器到一个可视的widget,所以当widget不显示时,动画定时器将会暂停,当widget再次显示时,动画定时器重新恢复执行,这样就可以避免动画相关UI不在当前屏幕时消耗资源。 如果要使用自定义的State对象作为vsync时,请包含TickerProviderStateMixin,因为是当前Widget使用动画,所以一般绑定值为 this

docs/widget/common/text/index.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
## ****
1+
## **Text**
2+
3+
>
4+
单一样式的文本,文本可多行显示,也可能全部显示在同一行上
5+
* 默认会继承最接近控件的DefaultTextStyle
6+
* 最基本的文本组件
7+
8+
### 构造方法
9+
10+
``` dart
11+
Text(this.data, {
12+
Key key,
13+
this.style,
14+
this.textAlign,
15+
this.textDirection,
16+
this.locale,
17+
this.softWrap,
18+
this.overflow,
19+
this.textScaleFactor,
20+
this.maxLines,
21+
this.semanticsLabel,
22+
})
23+
```
24+
25+
### 属性介绍
26+
* data: Text显示的文本,必选参数
27+
* style: 文本样式
28+
* textAlign: 文本对齐方式
29+
* textDirection: 文本显示方向
30+
* maxLines: 文本最多显示几行
31+
* overflow: 文本溢出显示的截断方式
32+
* textScaleFactor: 文本缩放比例

lib/components/widgetComp.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:efox_flutter/store/index.dart' show Store;
33
import 'header.dart' as Header;
44
import 'package:efox_flutter/components/markdownComp.dart' as MarkDownComp;
5-
import 'package:efox_flutter/lang/app_translations.dart' show AppTranslations;
5+
import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
66
import 'package:efox_flutter/components/baseComp.dart' as BaseComp;
77
import 'package:efox_flutter/components/exampleComp.dart' as ExampleComp;
88
import 'package:efox_flutter/utils/file.dart' as FileUtils;
@@ -184,7 +184,7 @@ class IndexState extends State<Index> {
184184
Container(
185185
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0),
186186
child: Text(
187-
AppTranslations.of(context).t('loading'),
187+
AppLocalizations.$t('loading'),
188188
style: TextStyle(
189189
color: Color(AppTheme.secondColor), fontSize: 20.0),
190190
),

lib/lang/Application.dart

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/lang/app_translations.dart

Lines changed: 0 additions & 66 deletions
This file was deleted.

lib/lang/app_translations_delegate.dart

Lines changed: 0 additions & 28 deletions
This file was deleted.

lib/lang/config.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:flutter/material.dart';
2+
3+
class ConfigLanguage {
4+
static List<Locale> supportedLocales = [
5+
Locale('zh', 'CH'),
6+
Locale('en', 'US'),
7+
];
8+
9+
static Map<String, dynamic> sopportLanguage = {
10+
"zh": {"code": "zh", "country_code": "CH"},
11+
"en": {"code": "en", "country_code": "US"}
12+
};
13+
14+
static dynamic defualtLanguage = {
15+
"code": "zh",
16+
"country_code": "CH"
17+
};
18+
}

lib/lang/index.dart

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import 'package:flutter/material.dart';
2+
import 'dart:async';
3+
import 'dart:convert';
4+
import 'package:efox_flutter/lang/config.dart' as I18NConfig;
5+
import 'package:flutter/services.dart' show rootBundle;
6+
7+
class AppLocalizations {
8+
Locale _locale; // language
9+
static Function _setState; // setState
10+
static AppLocalizationsDelegate _delegate;
11+
static Map<String, dynamic> jsonLanguage;
12+
static AppLocalizations _inst; // inst
13+
14+
AppLocalizations(this._locale);
15+
16+
// init localizations
17+
static Future<AppLocalizations> init(Locale locale) async {
18+
_inst = AppLocalizations(locale);
19+
await getLanguageJson();
20+
return _inst;
21+
}
22+
23+
// 设置语言切换代理
24+
static void setProxy(Function setState, AppLocalizationsDelegate delegate) async {
25+
_setState = setState;
26+
_delegate = delegate;
27+
}
28+
29+
static get languageCode => _inst._locale.languageCode;
30+
31+
static void getLanguageJson([Locale locale]) async {
32+
Locale _tmpLocale = _inst._locale;
33+
print(_tmpLocale.languageCode);
34+
String jsonLang;
35+
try {
36+
jsonLang = await rootBundle
37+
.loadString('locale/${_tmpLocale.languageCode}.json');
38+
} catch (e) {
39+
_inst._locale = Locale(I18NConfig.ConfigLanguage.defualtLanguage.code);
40+
jsonLang = await rootBundle
41+
.loadString('locale/${I18NConfig.ConfigLanguage.defualtLanguage.code}.json');
42+
}
43+
json.decode(jsonLang);
44+
jsonLanguage = json.decode(jsonLang);
45+
print("当前语言: ${_inst._locale}");
46+
print("Json数据: ${jsonLanguage}");
47+
}
48+
49+
static void changeLanguage([Locale locale]) {
50+
if (locale == null) {
51+
locale = AppLocalizations.languageCode == 'zh'
52+
? Locale('en', "US")
53+
: Locale("zh", "CH");
54+
}
55+
_inst._locale = locale;
56+
getLanguageJson(); // 根据语言获取对应的国际化文件
57+
_setState(() {
58+
_delegate = AppLocalizationsDelegate(locale);
59+
});
60+
}
61+
62+
// get local language
63+
_t(String key) {
64+
var _array = key.split('.');
65+
var _dict = jsonLanguage;
66+
var retValue = '';
67+
try {
68+
_array.forEach((item) {
69+
if (_dict[item].runtimeType == Null) {
70+
retValue = key;
71+
return;
72+
}
73+
if (_dict[item].runtimeType != String) {
74+
_dict = _dict[item];
75+
} else {
76+
retValue = _dict[item];
77+
}
78+
});
79+
retValue = retValue.isEmpty ? _dict : retValue;
80+
} catch (e) {
81+
print('i18n exception');
82+
print(e);
83+
retValue = key;
84+
}
85+
// print('key ${key} value: ${retValue}');
86+
return retValue ?? '';
87+
}
88+
89+
static String $t(String key) {
90+
return _inst._t(key);
91+
}
92+
}
93+
94+
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
95+
final Locale locale;
96+
97+
AppLocalizationsDelegate ([this.locale]);
98+
99+
@override
100+
bool isSupported(Locale locale) {
101+
return I18NConfig.ConfigLanguage.sopportLanguage.keys.toList().contains(locale.languageCode);
102+
}
103+
104+
@override
105+
Future<AppLocalizations> load(Locale _locale) async {
106+
Locale _tmpLocale = locale ?? _locale;
107+
return await AppLocalizations.init(_tmpLocale);
108+
}
109+
110+
@override
111+
bool shouldReload(LocalizationsDelegate<AppLocalizations> old) {
112+
// false时 不执行上述重写函数
113+
return false;
114+
}
115+
}

0 commit comments

Comments
 (0)