Skip to content

Commit de8c4d5

Browse files
author
yangshangzhi
committed
修改加载方式
1 parent 1c84b9d commit de8c4d5

File tree

4 files changed

+26
-45
lines changed

4 files changed

+26
-45
lines changed

lib/components/widgetComp.dart

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import 'package:flutter/material.dart';
2-
import 'package:efox_flutter/config/index.dart' as Config;
32
import 'package:efox_flutter/store/STORE.dart' show STORE;
43
import 'package:efox_flutter/components/markdownComp.dart' as MarkDownComp;
54
import 'package:efox_flutter/lang/app_translations.dart' show AppTranslations;
65
import 'package:efox_flutter/components/baseComp.dart' as BaseComp;
76
import 'package:efox_flutter/components/exampleComp.dart' as ExampleComp;
87
import 'package:efox_flutter/utils/file.dart' as FileUtils;
9-
import 'package:efox_flutter/utils/loadAsset.dart' as LoadAssetsUtils;
108
import 'package:efox_flutter/router/index.dart' show FluroRouter;
119

1210
class Index extends StatefulWidget {
@@ -70,34 +68,30 @@ class IndexState extends State<Index> {
7068
this.loading = true;
7169
}
7270
}
73-
74-
void init () async {
71+
72+
void init() async {
7573
this._bodyList.length = 0;
76-
for(var i in mdList) {
77-
print('i $i');
78-
Future res = Future.sync(() {
79-
this.getMdFile(i);
80-
});
81-
res.then((a) {
82-
print('======== $a');
83-
});
84-
// this._bodyList.insert(0, MarkDownComp.Index(await this.getMdFile(i)));
85-
print('=======');
86-
}
87-
// await mdList.reversed.forEach((item) async {
88-
// this._bodyList.insert(0, MarkDownComp.Index(await this.getMdFile(item)));
89-
// });
74+
// for (var i in this.mdList) {
75+
// this
76+
// ._bodyList
77+
// .insert(0, await MarkDownComp.Index(await this.getMdFile(i)));
78+
// }
79+
await this.mdList.reversed.forEach((item) async {
80+
this._bodyList.insert(0, await MarkDownComp.Index(await this.getMdFile(item)));
81+
});
9082

9183
// 增加
9284
if (this.demoChild != null) {
9385
this.demoChild.forEach((Widget item) {
94-
print('======= ${_bodyList}');
9586
this._bodyList.add(ExampleComp.Index(child: item));
9687
});
9788
}
89+
print('end $_bodyList');
90+
setState(() {
91+
this.loading = false;
92+
});
9893
}
9994

100-
10195
openPage(context, model, String url) async {
10296
// 加载页面
10397
if (model.configInfo.isPro) {
@@ -119,7 +113,6 @@ class IndexState extends State<Index> {
119113
}
120114
}
121115

122-
123116
@override
124117
Widget build(BuildContext context) {
125118
return STORE.connect(builder: (context, child, model) {
@@ -129,19 +122,14 @@ class IndexState extends State<Index> {
129122
title: Text(this.name),
130123
actions: this.getActions(context, model),
131124
),
132-
body: this.loading ? this.renderLoading(): this.renderWidget(),
125+
body: this.loading ? this.renderLoading() : this.renderWidget(),
133126
);
134127
});
135128
}
136129

137-
dynamic getMdFile(url) async {
138-
if (Config.isPro) {
139-
String mdr = await LoadAssetsUtils.loadMarkdownAssets(Config.env['GitHubAssetOrigin'] + url, Config.isPro);
140-
return mdr;
141-
} else {
142-
String mdStr = await FileUtils.readLocaleFile(url);
143-
return mdStr;
144-
}
130+
Future getMdFile(url) async {
131+
String mdStr = await FileUtils.readLocaleFile(url);
132+
return mdStr;
145133
}
146134

147135
getActions(context, model) {
@@ -219,7 +207,7 @@ class IndexState extends State<Index> {
219207
];
220208
}
221209

222-
Widget renderLoading () {
210+
Widget renderLoading() {
223211
return Center(
224212
child: Stack(
225213
children: <Widget>[
@@ -250,8 +238,9 @@ class IndexState extends State<Index> {
250238
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0),
251239
child: Text(
252240
AppTranslations.of(context).t('loading'),
253-
style:
254-
TextStyle(color: Color(this.model.theme.secondColor), fontSize: 16.0),
241+
style: TextStyle(
242+
color: Color(this.model.theme.secondColor),
243+
fontSize: 16.0),
255244
),
256245
)
257246
],
@@ -262,6 +251,7 @@ class IndexState extends State<Index> {
262251
),
263252
);
264253
}
254+
265255
Widget renderWidget() {
266256
// 加载完成后返回页面
267257
return Scrollbar(

lib/store/http.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:dio/dio.dart';
2-
import 'dart:io';
32

43
class RestApi {
54
RestApi();
@@ -9,13 +8,6 @@ class RestApi {
98
return RestApi._dio;
109
}
1110
Dio dio = new Dio(options);
12-
// proxy
13-
dio.onHttpClientCreate = (HttpClient client) {
14-
// client.findProxy = (uri) {
15-
// print(Index.proxyUrl);
16-
// return Index.proxyUrl;
17-
// };
18-
};
1911
RestApi._dio = dio;
2012
return dio;
2113
}
@@ -31,13 +23,13 @@ class RestApi {
3123
}
3224

3325
// dio.post('/test', data: {id:'123'})
34-
static post(url, [data]) async{
26+
static Future post(url, [data]) async{
3527
return await RestApi.getDio().post(url, data: data);
3628
}
3729

3830
// dio.get('/test', {data: {}})
3931
// dio.get('/test?id=123')
40-
static get(url, [data]) async {
32+
static Future get(url, [data]) async {
4133
return await RestApi.getDio().get(url, data: data);
4234
}
4335
}

lib/widget/scrollview/gridview/index.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'demo_count.dart' as DemoCount;
44
import 'demo_extent.dart' as DemoExtent;
55
import 'demo_custom.dart' as DemoCustom;
66
import 'demo_builder.dart' as DemoBuilder;
7-
import 'package:efox_flutter/utils/file.dart' as FileUtils;
87

98
String mdUrl = 'docs/widget/scrollview/gridview/index.md';
109
String codeUrl = 'docs/widget/scrollview/gridview/code.md';

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies:
2626
pull_to_refresh: ^1.1.6 #加载更多
2727
shared_preferences: ^0.4.2 #简单数据存储
2828
scoped_model: ^1.0.1
29-
dio: ^1.0.12
29+
dio: ^2.0.14
3030
cached_network_image: ^0.5.1
3131
intl: ^0.15.7
3232
flutter_markdown: ^0.2.0

0 commit comments

Comments
 (0)