@@ -252,23 +252,21 @@ Widget _buildCodeBlock({
252
252
required CodeBlockNode node,
253
253
}) {
254
254
if (node.spans.isEmpty) {
255
- return const CodeBlock (text: '' );
255
+ return const CodeBlockBasic (text: '' );
256
256
} else if (node.spans.length == 1 && node.spans.first.className == '' ){
257
- return CodeBlock (text: node.spans.first.text);
257
+ return CodeBlockBasic (text: node.spans.first.text);
258
258
} else {
259
259
return CodeBlockHighlighted (node: node);
260
260
}
261
261
}
262
262
263
- class CodeBlock extends StatelessWidget {
264
- const CodeBlock ({super .key, required this .text});
265
-
266
- final String text;
263
+ class _CodeBlockContainer extends StatelessWidget {
264
+ const _CodeBlockContainer ({super .key, required this .child});
265
+ final Widget child;
267
266
268
267
@override
269
268
Widget build (BuildContext context) {
270
269
return Container (
271
- padding: const EdgeInsets .fromLTRB (7 , 5 , 7 , 3 ),
272
270
decoration: BoxDecoration (
273
271
color: Colors .white,
274
272
border: Border .all (
@@ -277,7 +275,20 @@ class CodeBlock extends StatelessWidget {
277
275
borderRadius: BorderRadius .circular (4 )),
278
276
child: SingleChildScrollViewWithScrollbar (
279
277
scrollDirection: Axis .horizontal,
280
- child: Text (text, style: _kCodeBlockStyle)));
278
+ child: Padding (
279
+ padding: const EdgeInsets .fromLTRB (7 , 5 , 7 , 3 ),
280
+ child: child)));
281
+ }
282
+ }
283
+
284
+ class CodeBlockBasic extends StatelessWidget {
285
+ const CodeBlockBasic ({super .key, required this .text});
286
+
287
+ final String text;
288
+
289
+ @override
290
+ Widget build (BuildContext context) {
291
+ return _CodeBlockContainer (child: Text (text, style: _kCodeBlockStyle));
281
292
}
282
293
}
283
294
@@ -291,17 +302,7 @@ class CodeBlockHighlighted extends StatelessWidget {
291
302
292
303
@override
293
304
Widget build (BuildContext context) {
294
- return Container (
295
- padding: const EdgeInsets .fromLTRB (7 , 5 , 7 , 3 ),
296
- decoration: BoxDecoration (
297
- color: Colors .white,
298
- border: Border .all (
299
- width: 1 ,
300
- color: const HSLColor .fromAHSL (0.15 , 0 , 0 , 0 ).toColor ()),
301
- borderRadius: BorderRadius .circular (4 )),
302
- child: SingleChildScrollViewWithScrollbar (
303
- scrollDirection: Axis .horizontal,
304
- child: Text .rich (_builder.build ())));
305
+ return _CodeBlockContainer (child: Text .rich (_builder.build ()));
305
306
}
306
307
}
307
308
0 commit comments