Skip to content

Commit 9d53eff

Browse files
content: remove repetition of code block container
Introduces _CodeBlockContainer
1 parent 16eb0d5 commit 9d53eff

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

lib/widgets/content.dart

+20-19
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,21 @@ Widget _buildCodeBlock({
252252
required CodeBlockNode node,
253253
}) {
254254
if (node.spans.isEmpty) {
255-
return const CodeBlock(text: '');
255+
return const CodeBlockBasic(text: '');
256256
} 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);
258258
} else {
259259
return CodeBlockHighlighted(node: node);
260260
}
261261
}
262262

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;
267266

268267
@override
269268
Widget build(BuildContext context) {
270269
return Container(
271-
padding: const EdgeInsets.fromLTRB(7, 5, 7, 3),
272270
decoration: BoxDecoration(
273271
color: Colors.white,
274272
border: Border.all(
@@ -277,7 +275,20 @@ class CodeBlock extends StatelessWidget {
277275
borderRadius: BorderRadius.circular(4)),
278276
child: SingleChildScrollViewWithScrollbar(
279277
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));
281292
}
282293
}
283294

@@ -291,17 +302,7 @@ class CodeBlockHighlighted extends StatelessWidget {
291302

292303
@override
293304
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()));
305306
}
306307
}
307308

0 commit comments

Comments
 (0)