Skip to content

Commit 379f728

Browse files
committed
markdown
1 parent 83ecedb commit 379f728

3 files changed

Lines changed: 81 additions & 6 deletions

File tree

‎lib/common/style/GSYStyle.dart‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ class GSYConstant {
171171
fontSize: bigTextSize,
172172
);
173173

174+
static const largeLargeTextWhite = TextStyle(
175+
color: Color(GSYColors.TextColorWhite),
176+
fontSize: largetTextSize,
177+
);
178+
179+
static const largeLargeText = TextStyle(
180+
color: Color(GSYColors.primaryValue),
181+
fontSize: largetTextSize,
182+
);
183+
174184
static const largeTextWhiteBold = TextStyle(
175185
color: Color(GSYColors.TextColorWhite),
176186
fontSize: bigTextSize,

‎lib/page/CodeDetailPage.dart‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class CodeDetailPage extends StatefulWidget {
3131
CodeDetailPage({this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl});
3232

3333
@override
34-
_CodeDetailPageState createState() => _CodeDetailPageState(this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl);
34+
_CodeDetailPageState createState() =>
35+
_CodeDetailPageState(this.title, this.userName, this.reposName, this.path, this.data, this.branch, this.htmlUrl);
3536
}
3637

3738
class _CodeDetailPageState extends State<CodeDetailPage> {
@@ -70,8 +71,8 @@ class _CodeDetailPageState extends State<CodeDetailPage> {
7071
Widget build(BuildContext context) {
7172
String currentBranch = ((branch == null) ? "" : ("/" + branch));
7273
String url = htmlUrl;
73-
if(htmlUrl == null) {
74-
url = Address.hostWeb + userName + "/" + reposName + "/blob" + currentBranch + path;
74+
if (htmlUrl == null) {
75+
url = Address.hostWeb + userName + "/" + reposName + "/blob" + currentBranch + path;
7576
}
7677
Widget widget = (data == null)
7778
? new Center(
@@ -89,11 +90,14 @@ class _CodeDetailPageState extends State<CodeDetailPage> {
8990
),
9091
),
9192
)
92-
: new GSYMarkdownWidget(markdownData: data);
93+
: new GSYMarkdownWidget(
94+
markdownData: data,
95+
style: 1,
96+
);
9397

9498
return new Scaffold(
9599
appBar: new AppBar(
96-
title: GSYTitleBar(
100+
title: GSYTitleBar(
97101
title,
98102
rightWidget: new GSYCommonOptionWidget(url),
99103
needRightLocalIcon: false,

‎lib/widget/GSYMarkdownWidget.dart‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_markdown/flutter_markdown.dart';
3+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
34
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
45

56
/**
@@ -10,14 +11,64 @@ import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
1011
class GSYMarkdownWidget extends StatelessWidget {
1112
final String markdownData;
1213

13-
GSYMarkdownWidget({this.markdownData = ""});
14+
final int style;
15+
16+
GSYMarkdownWidget({this.markdownData = "", this.style = 0});
17+
18+
_getCommonSheet(BuildContext context) {
19+
MarkdownStyleSheet markdownStyleSheet = MarkdownStyleSheet.fromTheme(Theme.of(context));
20+
return markdownStyleSheet
21+
.copyWith(
22+
codeblockDecoration: new BoxDecoration(
23+
borderRadius: BorderRadius.all(Radius.circular(4.0)),
24+
color: Color(GSYColors.primaryValue),
25+
border: new Border.all(color: Color(GSYColors.subTextColor), width: 0.3)))
26+
.copyWith(
27+
blockquoteDecoration: new BoxDecoration(
28+
borderRadius: BorderRadius.all(Radius.circular(4.0)),
29+
color: Color(GSYColors.subTextColor),
30+
border: new Border.all(color: Color(GSYColors.subTextColor), width: 0.3)),
31+
blockquote: GSYConstant.smallTextWhite);
32+
}
33+
34+
_getStyleSheetDark(BuildContext context) {
35+
return _getCommonSheet(context).copyWith(
36+
p: GSYConstant.smallTextWhite,
37+
h1: GSYConstant.largeLargeTextWhite,
38+
h2: GSYConstant.largeTextWhite,
39+
h3: GSYConstant.normalTextWhite,
40+
h4: GSYConstant.middleTextWhite,
41+
h5: GSYConstant.smallTextWhite,
42+
h6: GSYConstant.smallTextWhite,
43+
em: const TextStyle(fontStyle: FontStyle.italic),
44+
strong: GSYConstant.middleTextWhite,
45+
code: GSYConstant.subSmallText,
46+
);
47+
}
48+
49+
_getStyleSheetWhite(BuildContext context) {
50+
return _getCommonSheet(context).copyWith(
51+
p: GSYConstant.smallText,
52+
h1: GSYConstant.largeLargeText,
53+
h2: GSYConstant.largeText,
54+
h3: GSYConstant.normalText,
55+
h4: GSYConstant.middleText,
56+
h5: GSYConstant.smallText,
57+
h6: GSYConstant.smallText,
58+
strong: GSYConstant.middleText,
59+
code: GSYConstant.subSmallText,
60+
);
61+
}
1462

1563
@override
1664
Widget build(BuildContext context) {
1765
return Container(
66+
color: style == 0 ? Color(GSYColors.white) : Color(GSYColors.primaryLightValue),
1867
padding: EdgeInsets.all(5.0),
1968
child: SingleChildScrollView(
2069
child: new MarkdownBody(
70+
styleSheet: style == 0 ? _getStyleSheetWhite(context) : _getStyleSheetDark(context),
71+
syntaxHighlighter: new GSYHighlighter(),
2172
data: markdownData,
2273
onTapLink: (String source) {
2374
CommonUtils.launchUrl(context, source);
@@ -27,3 +78,13 @@ class GSYMarkdownWidget extends StatelessWidget {
2778
);
2879
}
2980
}
81+
82+
class GSYHighlighter extends SyntaxHighlighter {
83+
@override
84+
TextSpan format(String source) {
85+
return new TextSpan(
86+
text: source,
87+
style: GSYConstant.smallTextWhite,
88+
);
89+
}
90+
}

0 commit comments

Comments
 (0)