11import 'package:flutter/material.dart' ;
22import 'package:flutter_markdown/flutter_markdown.dart' ;
3+ import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart' ;
34import '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';
1011class 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