@@ -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+
1112class 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) {
0 commit comments