Skip to content

Commit d8ca335

Browse files
author
yangshangzhi
committed
Merge branch 'ysz' into test
2 parents d46db76 + 8bfa937 commit d8ca335

File tree

12 files changed

+98
-69
lines changed

12 files changed

+98
-69
lines changed

lib/components/widgetComp.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:efox_flutter/lang/app_translations.dart' show AppTranslations;
55
import 'package:efox_flutter/components/baseComp.dart' as BaseComp;
66
import 'package:efox_flutter/components/exampleComp.dart' as ExampleComp;
77
import 'package:efox_flutter/utils/file.dart' as FileUtils;
8+
import 'package:efox_flutter/utils/loadAsset.dart' as LoadAssetUtils;
89
import 'package:efox_flutter/router/index.dart' show FluroRouter;
910

1011
class Index extends StatefulWidget {
@@ -92,9 +93,9 @@ class IndexState extends State<Index> {
9293

9394
openPage(context, model, String url) async {
9495
// 加载页面
95-
if (model.configInfo.isPro) {
96+
if (model.config.state.isPro) {
9697
FluroRouter.router.navigateTo(context,
97-
'/webview?url=${Uri.encodeComponent(this.model.configInfo.config['GitHubAssetOrigin'] + url)}');
98+
'/webview?url=${Uri.encodeComponent(model.config.state.env.GithubAssetOrigin + url)}');
9899
} else {
99100
// 加载本地
100101
String mdStr = await FileUtils.readLocaleFile(url);
@@ -112,7 +113,7 @@ class IndexState extends State<Index> {
112113
}
113114

114115
Future getMdFile(url) async {
115-
String mdStr = await FileUtils.readLocaleFile(url);
116+
String mdStr = await LoadAssetUtils.loadMarkdownAssets(url);
116117
return mdStr;
117118
}
118119

lib/config/development.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
Map<String ,dynamic> Config = {
2-
'GitHubAssetOrigin': 'https://github.com/efoxTeam/flutter-ui/blob/master/'
3-
};
1+
class Config {
2+
String GithubAssetOrigin =
3+
'https://github.com/efoxTeam/flutter-ui/blob/master/';
4+
String GithubMarkdownOrigin =
5+
'https://raw.githubusercontent.com/efoxTeam/flutter-ui/master/';
6+
}

lib/config/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import 'production.dart' as Production;
33

44
const bool isPro = false;
55

6-
Map<String, dynamic> env = isPro ? Production.Config : Development.Config;
6+
Object env = isPro ? Production.Config() : Development.Config();

lib/config/production.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
Map<String ,dynamic> Config = {
2-
'GitHubAssetOrigin': 'https://github.com/efoxTeam/flutter-ui/blob/master/'
3-
};
1+
class Config {
2+
String GithubAssetOrigin =
3+
'https://github.com/efoxTeam/flutter-ui/blob/master/';
4+
String GithubMarkdownOrigin =
5+
'https://raw.githubusercontent.com/efoxTeam/flutter-ui/master/';
6+
}

lib/main.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
44
import 'package:efox_flutter/lang/application.dart';
55
import 'package:efox_flutter/lang/app_translations_delegate.dart';
66
//引用Store 层
7-
import 'package:efox_flutter/store/store.dart';
7+
import 'package:efox_flutter/store/store.dart' show model, STORE;
88
//路由
99
import 'package:efox_flutter/router/index.dart';
1010
void main() => runApp(MainApp());
@@ -18,8 +18,6 @@ class MainApp extends StatefulWidget {
1818
}
1919

2020
class MainAppState extends State<MainApp> {
21-
//实例化 model
22-
final model = MainStateModel();
2321
// 定义全局 语言代理
2422
AppTranslationsDelegate _newLocaleDelegate;
2523

lib/page/mine/index.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import 'package:flutter/material.dart';
2-
import 'package:efox_flutter/store/models/main_state_model.dart';
3-
42

53
class Index extends StatelessWidget {
6-
final MainStateModel model;
4+
final dynamic model;
75
Index({Key key, this.model}):super(key: key);
86

97
@override
108
Widget build (BuildContext context) {
119
return Container(
1210
child: Center(
13-
child: Text('a'),
11+
child: RaisedButton(
12+
child: Text('当前为${model.config.state.isPro ? '线上' : '线下'}环境,点击进行切换'),
13+
onPressed: () {
14+
model.dispatch('config', 'setEnv');
15+
},
16+
),
1417
),
1518
);
1619
}

lib/store/STORE.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import 'package:scoped_model/scoped_model.dart';
22
import './models/main_state_model.dart';
33
export './models/main_state_model.dart';
44

5+
/**
6+
* import 'package:efox_flutter/store/STORE.dart' as Store;
7+
* Store.model.config.state.isPro
8+
*/
59
class STORE {
610
static init({model, child}) {
711
return ScopedModel<MainStateModel>(model: model, child: child);
812
}
913

1014
static get(context) => ScopedModel.of<MainStateModel>(context);
15+
1116
static connect({
1217
builder,
1318
child,

lib/store/http.dart

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
import 'package:dio/dio.dart';
22

3-
class RestApi {
4-
RestApi();
5-
static Dio _dio;
6-
static getDio([options]) {
7-
if (RestApi._dio != null) {
8-
return RestApi._dio;
9-
}
10-
Dio dio = new Dio(options);
11-
RestApi._dio = dio;
12-
return dio;
13-
}
3+
request() async {
4+
Dio dio = new Dio(); // with default Options
145

15-
static request({method, url, data}) async {
16-
Response<dynamic> response;
17-
if (method == 'get') {
18-
response = await RestApi.getDio().get(url, data: data);
19-
} else {
20-
response = await RestApi.getDio().post(url, data: data);
21-
}
22-
return response.data;
23-
}
24-
25-
// dio.post('/test', data: {id:'123'})
26-
static Future post(url, [data]) async{
27-
return await RestApi.getDio().post(url, data: data);
28-
}
29-
30-
// dio.get('/test', {data: {}})
31-
// dio.get('/test?id=123')
32-
static Future get(url, [data]) async {
33-
return await RestApi.getDio().get(url, data: data);
34-
}
356
}

lib/store/models/config_state_model.dart

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
import 'package:scoped_model/scoped_model.dart';
21
import 'package:efox_flutter/config/index.dart' as Config;
32

43
class ConfigInfo {
54
bool isPro = Config.isPro;
6-
dynamic config = Config.env;
5+
dynamic env = Config.env;
6+
}
7+
8+
ConfigInfo _appConfigInfo = new ConfigInfo();
9+
10+
class ConfigModel {
11+
get state => _appConfigInfo;
12+
13+
methods(name, payload) {
14+
print('payload= $payload');
15+
16+
switch (name) {
17+
case 'setEnv':
18+
_appConfigInfo.isPro = !_appConfigInfo.isPro;
19+
break;
20+
}
21+
}
722
}
8-
mixin ConfigModel on Model {
9-
ConfigInfo _appConfigInfo = new ConfigInfo();
10-
get configInfo => _appConfigInfo;
11-
}

lib/store/models/main_state_model.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,33 @@ import 'user_model.dart' show UserModel;
33
import 'theme_model.dart' show AppThemeModel;
44
import 'config_state_model.dart' show ConfigModel;
55

6+
/**
7+
* get state: model.modelName.state.xxx
8+
* dispatch method: model.dispatch('modelName', 'methodsName', payload)
9+
*
10+
* import 'package:efox_flutter/store/STORE.dart' as Store;
11+
* Store.model.config.state.isPro
12+
*/
13+
614
///主数据模型,需要全局使用的数据在这里添加模型
7-
class MainStateModel extends Model with UserModel, AppThemeModel, ConfigModel {
15+
class MainStateModel extends Model with UserModel, AppThemeModel {
16+
Map<String, dynamic> state = {};
17+
ConfigModel config = ConfigModel();
18+
819
MainStateModel() {
920
// 初始化实例数据
21+
// order for dispatch to get destination model's methods
22+
this.state = {
23+
'config': config,
24+
};
25+
}
26+
/**
27+
* dispatch method: model.dispatch('modelName', 'methodsName', payload)
28+
*/
29+
dispatch(nameSpace, method, [payload]) async {
30+
this.state[nameSpace].methods(method, payload);
31+
notifyListeners();
1032
}
1133
}
34+
35+
MainStateModel model = MainStateModel();

0 commit comments

Comments
 (0)