Skip to content

Commit aec3fa3

Browse files
committed
add readme
1 parent c8e05da commit aec3fa3

6 files changed

Lines changed: 97 additions & 9 deletions

File tree

‎lib/common/dao/ReposDao.dart‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,16 @@ class ReposDao {
333333
}
334334
return new DataResult(null, false);
335335
}
336+
337+
/**
338+
* 详情的remde数据
339+
*/
340+
static getRepositoryDetailReadmeDao(userName, reposName, branch) async {
341+
String url = Address.readmeFile(userName + '/' + reposName, branch);
342+
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, new Options(contentType: ContentType.TEXT));
343+
if (res != null && res.result) {
344+
return new DataResult(res.data, true);
345+
}
346+
return new DataResult(null, false);
347+
}
336348
}

‎lib/common/net/Api.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class HttpManager {
3333

3434
Map<String, String> headers = new HashMap();
3535
if (header != null) {
36-
headers.addAll(headers);
36+
headers.addAll(header);
3737
}
3838

3939
//授权码
@@ -76,6 +76,7 @@ class HttpManager {
7676

7777
if (Config.DEBUG) {
7878
print('请求url: ' + url);
79+
print('请求头: ' + option.headers.toString());
7980
if (params != null) {
8081
print('请求参数: ' + params.toString());
8182
}

‎lib/page/RepositoryDetailPage.dart‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
4848

4949
GlobalKey<ReposDetailInfoPageState> infoListKey = new GlobalKey<ReposDetailInfoPageState>();
5050

51+
GlobalKey<RepositoryDetailReadmePageState> readmeKey = new GlobalKey<RepositoryDetailReadmePageState>();
52+
5153
List<String> branchList = new List();
5254

5355
_RepositoryDetailPageState(this.userName, this.reposName);
@@ -198,6 +200,9 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
198200
if (fileListKey.currentState != null && fileListKey.currentState.mounted) {
199201
fileListKey.currentState.showRefreshLoading();
200202
}
203+
if (readmeKey.currentState != null && readmeKey.currentState.mounted) {
204+
readmeKey.currentState.refreshReadme();
205+
}
201206
}),
202207
];
203208
return bottomWidget;
@@ -214,20 +219,21 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
214219
Widget build(BuildContext context) {
215220
fileListKey = new GlobalKey<RepositoryDetailFileListPageState>();
216221
infoListKey = new GlobalKey<ReposDetailInfoPageState>();
222+
readmeKey = new GlobalKey<RepositoryDetailReadmePageState>();
217223
return new GSYTabBarWidget(
218224
type: GSYTabBarWidget.TOP_TAB,
219225
tarWidgetControl: tarBarControl,
220226
tabItems: [
221227
new Tab(text: GSYStrings.repos_tab_info),
228+
new Tab(text: GSYStrings.repos_tab_readme),
222229
new Tab(text: GSYStrings.repos_tab_issue),
223230
new Tab(text: GSYStrings.repos_tab_file),
224-
new Tab(text: GSYStrings.repos_tab_readme),
225231
],
226232
tabViews: [
227233
new ReposDetailInfoPage(reposDetailInfoPageControl, userName, reposName, branchControl, key: infoListKey),
234+
new RepositoryDetailReadmePage(userName, reposName, branchControl, key: readmeKey),
228235
new RepositoryDetailIssuePage(userName, reposName),
229236
new RepositoryDetailFileListPage(userName, reposName, branchControl, key: fileListKey),
230-
new RepositoryDetailReadmePage(),
231237
],
232238
backgroundColor: GSYColors.primarySwatch,
233239
indicatorColor: Colors.white,
Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,72 @@
11
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
23
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
4+
import 'package:flutter_markdown/flutter_markdown.dart';
5+
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
36

47
/**
8+
* Readme
59
* Created by guoshuyu
610
* Date: 2018-07-18
711
*/
812

9-
class RepositoryDetailReadmePage extends StatelessWidget {
13+
class RepositoryDetailReadmePage extends StatefulWidget {
14+
final String userName;
15+
16+
final String reposName;
17+
18+
final BranchControl branchControl;
19+
20+
RepositoryDetailReadmePage(this.userName, this.reposName, this.branchControl, { Key key }) : super(key: key);
21+
22+
@override
23+
RepositoryDetailReadmePageState createState() => RepositoryDetailReadmePageState(userName, reposName, branchControl);
24+
}
25+
26+
class RepositoryDetailReadmePageState extends State<RepositoryDetailReadmePage> {
27+
final String userName;
28+
29+
final String reposName;
30+
31+
final BranchControl branchControl;
32+
33+
bool isShow = false;
34+
35+
String markdownData = "";
36+
37+
RepositoryDetailReadmePageState(this.userName, this.reposName, this.branchControl);
38+
39+
refreshReadme() {
40+
ReposDao.getRepositoryDetailReadmeDao(userName, reposName, branchControl.currentBranch).then((res) {
41+
if (res != null && res.result) {
42+
if (isShow) {
43+
setState(() {
44+
markdownData = res.data;
45+
});
46+
}
47+
}
48+
});
49+
}
50+
51+
@override
52+
void initState() {
53+
isShow = true;
54+
super.initState();
55+
refreshReadme();
56+
}
57+
58+
@override
59+
void dispose() {
60+
isShow = false;
61+
super.dispose();
62+
}
63+
1064
@override
1165
Widget build(BuildContext context) {
1266
return Container(
13-
child: new Center(
14-
child: new Text("Flutter现在没有WebView!!\n残念!!!", style: GSYConstant.largeText, textAlign:TextAlign.center),
15-
),
67+
child: SingleChildScrollView(
68+
child: new MarkdownBody(data: markdownData),
69+
)
1670
);
1771
}
1872
}

‎pubspec.lock‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ packages:
6363
name: built_collection
6464
url: "https://pub.flutter-io.cn"
6565
source: hosted
66-
version: "3.1.1"
66+
version: "3.1.3"
6767
built_value:
6868
dependency: transitive
6969
description:
7070
name: built_value
7171
url: "https://pub.flutter-io.cn"
7272
source: hosted
73-
version: "5.5.3"
73+
version: "5.5.5"
7474
charcode:
7575
dependency: transitive
7676
description:
@@ -174,6 +174,13 @@ packages:
174174
description: flutter
175175
source: sdk
176176
version: "0.0.0"
177+
flutter_markdown:
178+
dependency: "direct main"
179+
description:
180+
name: flutter_markdown
181+
url: "https://pub.flutter-io.cn"
182+
source: hosted
183+
version: "0.1.5"
177184
flutter_redux:
178185
dependency: "direct main"
179186
description:
@@ -284,6 +291,13 @@ packages:
284291
url: "https://pub.flutter-io.cn"
285292
source: hosted
286293
version: "0.11.3+1"
294+
markdown:
295+
dependency: transitive
296+
description:
297+
name: markdown
298+
url: "https://pub.flutter-io.cn"
299+
source: hosted
300+
version: "1.1.1"
287301
matcher:
288302
dependency: transitive
289303
description:

‎pubspec.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies:
1515
flutter_redux: ^0.5.2
1616
device_info: ^0.2.1
1717
connectivity: ^0.3.1
18+
flutter_markdown: ^0.1.5
1819

1920
dev_dependencies:
2021
build_runner: ^0.7.6

0 commit comments

Comments
 (0)