Add stylesheet option listBulletPadding (#306)

This commit is contained in:
Markus Wendorf
2021-01-26 23:30:34 +01:00
committed by GitHub
parent 3c7a32eff4
commit a21cd7f462
3 changed files with 53 additions and 7 deletions

View File

@ -337,7 +337,9 @@ class MarkdownBuilder implements md.NodeVisitor {
: CrossAxisAlignment.baseline, : CrossAxisAlignment.baseline,
children: <Widget>[ children: <Widget>[
SizedBox( SizedBox(
width: styleSheet.listIndent, width: styleSheet.listIndent +
styleSheet.listBulletPadding.left +
styleSheet.listBulletPadding.right,
child: bullet, child: bullet,
), ),
Expanded(child: child) Expanded(child: child)
@ -459,7 +461,7 @@ class MarkdownBuilder implements md.NodeVisitor {
return checkboxBuilder(checked); return checkboxBuilder(checked);
} }
return Padding( return Padding(
padding: const EdgeInsets.only(right: 4), padding: styleSheet.listBulletPadding,
child: Icon( child: Icon(
checked ? Icons.check_box : Icons.check_box_outline_blank, checked ? Icons.check_box : Icons.check_box_outline_blank,
size: styleSheet.checkbox.fontSize, size: styleSheet.checkbox.fontSize,
@ -470,16 +472,19 @@ class MarkdownBuilder implements md.NodeVisitor {
Widget _buildBullet(String listTag) { Widget _buildBullet(String listTag) {
if (listTag == 'ul') { if (listTag == 'ul') {
return Text( return Padding(
'', padding: styleSheet.listBulletPadding,
textAlign: TextAlign.center, child: Text(
style: styleSheet.listBullet, '',
textAlign: TextAlign.center,
style: styleSheet.listBullet,
),
); );
} }
final int index = _blocks.last.nextListIndex; final int index = _blocks.last.nextListIndex;
return Padding( return Padding(
padding: const EdgeInsets.only(right: 4), padding: styleSheet.listBulletPadding,
child: Text( child: Text(
'${index + 1}.', '${index + 1}.',
textAlign: TextAlign.right, textAlign: TextAlign.right,

View File

@ -27,6 +27,7 @@ class MarkdownStyleSheet {
this.blockSpacing, this.blockSpacing,
this.listIndent, this.listIndent,
this.listBullet, this.listBullet,
this.listBulletPadding,
this.tableHead, this.tableHead,
this.tableBody, this.tableBody,
this.tableHeadAlign, this.tableHeadAlign,
@ -102,6 +103,7 @@ class MarkdownStyleSheet {
blockSpacing: 8.0, blockSpacing: 8.0,
listIndent: 24.0, listIndent: 24.0,
listBullet: theme.textTheme.bodyText2, listBullet: theme.textTheme.bodyText2,
listBulletPadding: const EdgeInsets.only(right: 4),
tableHead: const TextStyle(fontWeight: FontWeight.w600), tableHead: const TextStyle(fontWeight: FontWeight.w600),
tableBody: theme.textTheme.bodyText2, tableBody: theme.textTheme.bodyText2,
tableHeadAlign: TextAlign.center, tableHeadAlign: TextAlign.center,
@ -190,6 +192,7 @@ class MarkdownStyleSheet {
blockSpacing: 8, blockSpacing: 8,
listIndent: 24, listIndent: 24,
listBullet: theme.textTheme.textStyle, listBullet: theme.textTheme.textStyle,
listBulletPadding: const EdgeInsets.only(right: 4),
tableHead: theme.textTheme.textStyle.copyWith( tableHead: theme.textTheme.textStyle.copyWith(
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
@ -266,6 +269,7 @@ class MarkdownStyleSheet {
blockSpacing: 8.0, blockSpacing: 8.0,
listIndent: 24.0, listIndent: 24.0,
listBullet: theme.textTheme.bodyText2, listBullet: theme.textTheme.bodyText2,
listBulletPadding: const EdgeInsets.only(right: 4),
tableHead: const TextStyle(fontWeight: FontWeight.w600), tableHead: const TextStyle(fontWeight: FontWeight.w600),
tableBody: theme.textTheme.bodyText2, tableBody: theme.textTheme.bodyText2,
tableHeadAlign: TextAlign.center, tableHeadAlign: TextAlign.center,
@ -317,6 +321,7 @@ class MarkdownStyleSheet {
double blockSpacing, double blockSpacing,
double listIndent, double listIndent,
TextStyle listBullet, TextStyle listBullet,
EdgeInsets listBulletPadding,
TextStyle tableHead, TextStyle tableHead,
TextStyle tableBody, TextStyle tableBody,
TextAlign tableHeadAlign, TextAlign tableHeadAlign,
@ -361,6 +366,7 @@ class MarkdownStyleSheet {
blockSpacing: blockSpacing ?? this.blockSpacing, blockSpacing: blockSpacing ?? this.blockSpacing,
listIndent: listIndent ?? this.listIndent, listIndent: listIndent ?? this.listIndent,
listBullet: listBullet ?? this.listBullet, listBullet: listBullet ?? this.listBullet,
listBulletPadding: listBulletPadding ?? this.listBulletPadding,
tableHead: tableHead ?? this.tableHead, tableHead: tableHead ?? this.tableHead,
tableBody: tableBody ?? this.tableBody, tableBody: tableBody ?? this.tableBody,
tableHeadAlign: tableHeadAlign ?? this.tableHeadAlign, tableHeadAlign: tableHeadAlign ?? this.tableHeadAlign,
@ -412,6 +418,7 @@ class MarkdownStyleSheet {
blockSpacing: other.blockSpacing, blockSpacing: other.blockSpacing,
listIndent: other.listIndent, listIndent: other.listIndent,
listBullet: listBullet.merge(other.listBullet), listBullet: listBullet.merge(other.listBullet),
listBulletPadding: other.listBulletPadding,
tableHead: tableHead.merge(other.tableHead), tableHead: tableHead.merge(other.tableHead),
tableBody: tableBody.merge(other.tableBody), tableBody: tableBody.merge(other.tableBody),
tableHeadAlign: other.tableHeadAlign, tableHeadAlign: other.tableHeadAlign,
@ -493,6 +500,9 @@ class MarkdownStyleSheet {
/// The [TextStyle] to use for bullets. /// The [TextStyle] to use for bullets.
final TextStyle listBullet; final TextStyle listBullet;
/// The padding to use for bullets.
final EdgeInsets listBulletPadding;
/// The [TextStyle] to use for `th` elements. /// The [TextStyle] to use for `th` elements.
final TextStyle tableHead; final TextStyle tableHead;
@ -592,6 +602,7 @@ class MarkdownStyleSheet {
typedOther.blockSpacing == blockSpacing && typedOther.blockSpacing == blockSpacing &&
typedOther.listIndent == listIndent && typedOther.listIndent == listIndent &&
typedOther.listBullet == listBullet && typedOther.listBullet == listBullet &&
typedOther.listBulletPadding == listBulletPadding &&
typedOther.tableHead == tableHead && typedOther.tableHead == tableHead &&
typedOther.tableBody == tableBody && typedOther.tableBody == tableBody &&
typedOther.tableHeadAlign == tableHeadAlign && typedOther.tableHeadAlign == tableHeadAlign &&
@ -639,6 +650,7 @@ class MarkdownStyleSheet {
blockSpacing, blockSpacing,
listIndent, listIndent,
listBullet, listBullet,
listBulletPadding,
tableHead, tableHead,
tableBody, tableBody,
tableHeadAlign, tableHeadAlign,

View File

@ -271,5 +271,34 @@ void defineTests() {
expect(text1.text, isNot(text2.text)); expect(text1.text, isNot(text2.text));
}, },
); );
testWidgets(
'use stylesheet option listBulletPadding',
(WidgetTester tester) async {
final paddingX = 20.0;
final MarkdownStyleSheet style = MarkdownStyleSheet(
listBulletPadding: EdgeInsets.symmetric(horizontal: paddingX));
await tester.pumpWidget(
boilerplate(
Markdown(
data: '1. Bullet\n 2. Bullet\n * Bullet',
styleSheet: style,
),
),
);
List<Padding> paddings =
tester.widgetList<Padding>(find.byType(Padding)).toList();
expect(paddings.length, 3);
expect(
paddings.every(
(p) => p.padding.along(Axis.horizontal) == paddingX * 2,
),
true,
);
},
);
}); });
} }