@@ -5,12 +5,18 @@ import 'package:flutter_highlighter/flutter_highlighter.dart';
5
5
import 'package:flutter_highlighter/themes/monokai-sublime.dart' ;
6
6
import 'package:flutter_markdown/flutter_markdown.dart' ;
7
7
8
- Widget renderContent (BuildContext context, String text) {
8
+ Widget renderContent (
9
+ BuildContext context,
10
+ String text,
11
+ ) {
9
12
if (text.isEmpty) {
10
13
return const Text ("No content to display." );
11
14
}
12
15
13
- final codeBlockPattern = RegExp (r'```(\w+)?\n([\s\S]*?)```' , multiLine: true );
16
+ final codeBlockPattern = RegExp (
17
+ r'```(\w+)?\n([\s\S]*?)```' ,
18
+ multiLine: true ,
19
+ );
14
20
final matches = codeBlockPattern.allMatches (text);
15
21
16
22
if (matches.isEmpty) {
@@ -22,8 +28,10 @@ Widget renderContent(BuildContext context, String text) {
22
28
23
29
for (var match in matches) {
24
30
if (match.start > lastEnd) {
25
- children
26
- .add (_renderMarkdown (context, text.substring (lastEnd, match.start)));
31
+ children.add (_renderMarkdown (
32
+ context,
33
+ text.substring (lastEnd, match.start),
34
+ ));
27
35
}
28
36
29
37
final language = match.group (1 ) ?? 'text' ;
@@ -43,7 +51,10 @@ Widget renderContent(BuildContext context, String text) {
43
51
);
44
52
}
45
53
46
- Widget _renderMarkdown (BuildContext context, String markdown) {
54
+ Widget _renderMarkdown (
55
+ BuildContext context,
56
+ String markdown,
57
+ ) {
47
58
return MarkdownBody (
48
59
data: markdown,
49
60
selectable: true ,
@@ -53,7 +64,11 @@ Widget _renderMarkdown(BuildContext context, String markdown) {
53
64
);
54
65
}
55
66
56
- Widget _renderCodeBlock (BuildContext context, String language, String code) {
67
+ Widget _renderCodeBlock (
68
+ BuildContext context,
69
+ String language,
70
+ String code,
71
+ ) {
57
72
if (language == 'json' ) {
58
73
try {
59
74
final prettyJson =
@@ -63,7 +78,10 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
63
78
color: Theme .of (context).colorScheme.surfaceContainerLow,
64
79
child: SelectableText (
65
80
prettyJson,
66
- style: const TextStyle (fontFamily: 'monospace' , fontSize: 12 ),
81
+ style: const TextStyle (
82
+ fontFamily: 'monospace' ,
83
+ fontSize: 12 ,
84
+ ),
67
85
),
68
86
);
69
87
} catch (e) {
@@ -78,7 +96,10 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
78
96
code,
79
97
language: language,
80
98
theme: monokaiSublimeTheme,
81
- textStyle: const TextStyle (fontFamily: 'monospace' , fontSize: 12 ),
99
+ textStyle: const TextStyle (
100
+ fontFamily: 'monospace' ,
101
+ fontSize: 12 ,
102
+ ),
82
103
),
83
104
);
84
105
} catch (e) {
@@ -87,14 +108,20 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
87
108
}
88
109
}
89
110
90
- Widget _renderFallbackCode (BuildContext context, String code) {
111
+ Widget _renderFallbackCode (
112
+ BuildContext context,
113
+ String code,
114
+ ) {
91
115
return Container (
92
116
padding: const EdgeInsets .all (8 ),
93
117
color: Theme .of (context).colorScheme.surfaceContainerLow,
94
118
child: SelectableText (
95
119
code,
96
120
style: const TextStyle (
97
- fontFamily: 'monospace' , fontSize: 12 , color: Colors .red),
121
+ fontFamily: 'monospace' ,
122
+ fontSize: 12 ,
123
+ color: Colors .red,
124
+ ),
98
125
),
99
126
);
100
127
}
0 commit comments