Skip to content

Commit 6459c8c

Browse files
committed
issue使用markdown解析
1 parent 525f1ae commit 6459c8c

5 files changed

Lines changed: 102 additions & 36 deletions

File tree

‎lib/common/dao/IssueDao.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class IssueDao {
7878
static getIssueInfoDao(userName, repository, number) async {
7979
String url = Address.getIssueInfo(userName, repository, number);
8080
//{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
81-
var res = await HttpManager.netFetch(url, null, null, null);
81+
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, null);
8282
if (res != null && res.result) {
8383
return new DataResult(Issue.fromJson(res.data), true);
8484
} else {
@@ -92,7 +92,7 @@ class IssueDao {
9292
static getIssueCommentDao(userName, repository, number, {page: 0}) async {
9393
String url = Address.getIssueComment(userName, repository, number) + Address.getPageParams("?", page);
9494
//{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
95-
var res = await HttpManager.netFetch(url, null, null, null);
95+
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.raw'}, null);
9696
if (res != null && res.result) {
9797
List<Issue> list = new List();
9898
var data = res.data;

‎lib/page/CodeDetailPage.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class _CodeDetailPageState extends State<CodeDetailPage> {
8989
)
9090
: new GSYMarkdownWidget(
9191
markdownData: data,
92-
style: 1,
92+
style: GSYMarkdownWidget.DARK_LIGHT,
9393
);
9494

9595
return new Scaffold(

‎lib/widget/GSYMarkdownWidget.dart‎

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@ import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
88
* Created by guoshuyu
99
* Date: 2018-07-24
1010
*/
11+
1112
class GSYMarkdownWidget extends StatelessWidget {
13+
static const int DARK_WHITE = 0;
14+
15+
static const int DARK_LIGHT = 1;
16+
17+
static const int DARK_THEME = 2;
18+
1219
final String markdownData;
1320

1421
final int style;
1522

16-
GSYMarkdownWidget({this.markdownData = "", this.style = 0});
23+
GSYMarkdownWidget({this.markdownData = "", this.style = DARK_WHITE});
1724

18-
_getCommonSheet(BuildContext context) {
25+
_getCommonSheet(BuildContext context, Color codeBackground) {
1926
MarkdownStyleSheet markdownStyleSheet = MarkdownStyleSheet.fromTheme(Theme.of(context));
2027
return markdownStyleSheet
2128
.copyWith(
2229
codeblockDecoration: new BoxDecoration(
2330
borderRadius: BorderRadius.all(Radius.circular(4.0)),
24-
color: Color(GSYColors.primaryValue),
31+
color: codeBackground,
2532
border: new Border.all(color: Color(GSYColors.subTextColor), width: 0.3)))
2633
.copyWith(
2734
blockquoteDecoration: new BoxDecoration(
@@ -32,7 +39,7 @@ class GSYMarkdownWidget extends StatelessWidget {
3239
}
3340

3441
_getStyleSheetDark(BuildContext context) {
35-
return _getCommonSheet(context).copyWith(
42+
return _getCommonSheet(context, Color(GSYColors.primaryValue)).copyWith(
3643
p: GSYConstant.smallTextWhite,
3744
h1: GSYConstant.largeLargeTextWhite,
3845
h2: GSYConstant.largeTextWhite,
@@ -47,7 +54,7 @@ class GSYMarkdownWidget extends StatelessWidget {
4754
}
4855

4956
_getStyleSheetWhite(BuildContext context) {
50-
return _getCommonSheet(context).copyWith(
57+
return _getCommonSheet(context, Color(GSYColors.primaryValue)).copyWith(
5158
p: GSYConstant.smallText,
5259
h1: GSYConstant.largeLargeText,
5360
h2: GSYConstant.largeText,
@@ -60,14 +67,55 @@ class GSYMarkdownWidget extends StatelessWidget {
6067
);
6168
}
6269

70+
_getStyleSheetTheme(BuildContext context) {
71+
return _getCommonSheet(context, Color(GSYColors.subTextColor)).copyWith(
72+
p: GSYConstant.smallTextWhite,
73+
h1: GSYConstant.largeLargeTextWhite,
74+
h2: GSYConstant.largeTextWhite,
75+
h3: GSYConstant.normalTextWhite,
76+
h4: GSYConstant.middleTextWhite,
77+
h5: GSYConstant.smallTextWhite,
78+
h6: GSYConstant.smallTextWhite,
79+
em: const TextStyle(fontStyle: FontStyle.italic),
80+
strong: GSYConstant.middleTextWhite,
81+
code: GSYConstant.subSmallText,
82+
);
83+
}
84+
85+
_getBackgroundColor() {
86+
Color background = Color(GSYColors.white);
87+
switch (style) {
88+
case DARK_LIGHT:
89+
background = Color(GSYColors.primaryLightValue);
90+
break;
91+
case DARK_THEME:
92+
background = Color(GSYColors.primaryValue);
93+
break;
94+
}
95+
return background;
96+
}
97+
98+
_getStyle(BuildContext context) {
99+
var styleSheet = _getStyleSheetWhite(context);
100+
switch (style) {
101+
case DARK_LIGHT:
102+
styleSheet = _getStyleSheetDark(context);
103+
break;
104+
case DARK_THEME:
105+
styleSheet = _getStyleSheetTheme(context);
106+
break;
107+
}
108+
return styleSheet;
109+
}
110+
63111
@override
64112
Widget build(BuildContext context) {
65113
return Container(
66-
color: style == 0 ? Color(GSYColors.white) : Color(GSYColors.primaryLightValue),
114+
color: _getBackgroundColor(),
67115
padding: EdgeInsets.all(5.0),
68116
child: SingleChildScrollView(
69117
child: new MarkdownBody(
70-
styleSheet: style == 0 ? _getStyleSheetWhite(context) : _getStyleSheetDark(context),
118+
styleSheet: _getStyle(context),
71119
syntaxHighlighter: new GSYHighlighter(),
72120
data: markdownData,
73121
onTapLink: (String source) {

‎lib/widget/IssueHeaderItem.dart‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
55
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
66
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
77
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
8+
import 'package:gsy_github_app_flutter/widget/GSYMarkdownWidget.dart';
89
import 'package:gsy_github_app_flutter/widget/GSYUserIconWidget.dart';
910

1011
/**
@@ -20,9 +21,9 @@ class IssueHeaderItem extends StatelessWidget {
2021

2122
IssueHeaderItem(this.issueHeaderViewModel, {this.onPressed});
2223

23-
@override
24-
Widget build(BuildContext context) {
24+
_renderBottomContainer() {
2525
Color issueStateColor = issueHeaderViewModel.state == "open" ? Colors.green : Colors.red;
26+
2627
///底部Issue状态
2728
Widget bottomContainer = new Row(
2829
children: <Widget>[
@@ -39,9 +40,11 @@ class IssueHeaderItem extends StatelessWidget {
3940
padding: 2.0,
4041
),
4142
new Padding(padding: new EdgeInsets.all(2.0)),
43+
4244
///issue issue编码
4345
new Text(issueHeaderViewModel.issueTag, style: GSYConstant.smallTextWhite),
4446
new Padding(padding: new EdgeInsets.all(2.0)),
47+
4548
///issue 评论数
4649
new GSYIConText(
4750
GSYICons.ISSUE_ITEM_COMMENT,
@@ -53,6 +56,11 @@ class IssueHeaderItem extends StatelessWidget {
5356
),
5457
],
5558
);
59+
return bottomContainer;
60+
}
61+
62+
@override
63+
Widget build(BuildContext context) {
5664
return new GSYCardItem(
5765
color: Color(GSYColors.primaryValue),
5866
child: new FlatButton(
@@ -82,6 +90,7 @@ class IssueHeaderItem extends StatelessWidget {
8290
children: <Widget>[
8391
///名称
8492
new Expanded(child: new Text(issueHeaderViewModel.actionUser, style: GSYConstant.normalTextWhite)),
93+
8594
///时间
8695
new Text(
8796
issueHeaderViewModel.actionTime,
@@ -91,8 +100,11 @@ class IssueHeaderItem extends StatelessWidget {
91100
],
92101
),
93102
new Padding(padding: new EdgeInsets.all(2.0)),
94-
bottomContainer,
103+
104+
///底部Item
105+
_renderBottomContainer(),
95106
new Container(
107+
96108
///评论标题
97109
child: new Text(
98110
issueHeaderViewModel.issueComment,
@@ -108,14 +120,9 @@ class IssueHeaderItem extends StatelessWidget {
108120
),
109121
],
110122
),
111-
new Container(
112-
///评论内容
113-
child: new Text(
114-
issueHeaderViewModel.issueDesHtml,
115-
style: GSYConstant.smallTextWhite,
116-
),
117-
margin: new EdgeInsets.all(10.0),
118-
alignment: Alignment.topLeft)
123+
124+
///评论内容
125+
GSYMarkdownWidget(markdownData: issueHeaderViewModel.issueDesHtml, style: GSYMarkdownWidget.DARK_THEME),
119126
],
120127
),
121128
),

‎lib/widget/IssueItem.dart‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
55
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
66
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
77
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
8+
import 'package:gsy_github_app_flutter/widget/GSYMarkdownWidget.dart';
89
import 'package:gsy_github_app_flutter/widget/GSYUserIconWidget.dart';
910

1011
/**
@@ -29,12 +30,10 @@ class IssueItem extends StatelessWidget {
2930

3031
IssueItem(this.issueItemViewModel, {this.onPressed, this.onLongPress, this.hideBottom = false, this.limitComment = true});
3132

32-
@override
33-
Widget build(BuildContext context) {
33+
///issue 底部状态
34+
_renderBottomContainer() {
3435
Color issueStateColor = issueItemViewModel.state == "open" ? Colors.green : Colors.red;
35-
36-
///issue 底部状态
37-
Widget bottomContainer = (hideBottom)
36+
return (hideBottom)
3837
? new Container()
3938
: new Row(
4039
children: <Widget>[
@@ -68,6 +67,25 @@ class IssueItem extends StatelessWidget {
6867
),
6968
],
7069
);
70+
}
71+
72+
///评论内容
73+
_renderCommentText() {
74+
return (limitComment)
75+
? new Container(
76+
child: new Text(
77+
issueItemViewModel.issueComment,
78+
style: GSYConstant.subSmallText,
79+
maxLines: limitComment ? 2 : 1000,
80+
),
81+
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
82+
alignment: Alignment.topLeft,
83+
)
84+
: GSYMarkdownWidget(markdownData: issueItemViewModel.issueComment);
85+
}
86+
87+
@override
88+
Widget build(BuildContext context) {
7189
return new GSYCardItem(
7290
child: new InkWell(
7391
onTap: onPressed,
@@ -99,20 +117,13 @@ class IssueItem extends StatelessWidget {
99117
),
100118
],
101119
),
102-
new Container(
103120

104-
///评论内容
105-
child: new Text(
106-
issueItemViewModel.issueComment,
107-
style: GSYConstant.subSmallText,
108-
maxLines: limitComment ? 2 : 1000,
109-
),
110-
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
111-
alignment: Alignment.topLeft),
121+
///评论内容
122+
_renderCommentText(),
112123
new Padding(
113124
padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0),
114125
),
115-
bottomContainer,
126+
_renderBottomContainer(),
116127
],
117128
),
118129
),

0 commit comments

Comments
 (0)