mirror of
https://github.com/flutter/packages.git
synced 2025-06-30 23:03:11 +08:00
Add stylesheet option listBulletPadding (#306)
This commit is contained in:
@ -337,7 +337,9 @@ class MarkdownBuilder implements md.NodeVisitor {
|
||||
: CrossAxisAlignment.baseline,
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: styleSheet.listIndent,
|
||||
width: styleSheet.listIndent +
|
||||
styleSheet.listBulletPadding.left +
|
||||
styleSheet.listBulletPadding.right,
|
||||
child: bullet,
|
||||
),
|
||||
Expanded(child: child)
|
||||
@ -459,7 +461,7 @@ class MarkdownBuilder implements md.NodeVisitor {
|
||||
return checkboxBuilder(checked);
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
padding: styleSheet.listBulletPadding,
|
||||
child: Icon(
|
||||
checked ? Icons.check_box : Icons.check_box_outline_blank,
|
||||
size: styleSheet.checkbox.fontSize,
|
||||
@ -470,16 +472,19 @@ class MarkdownBuilder implements md.NodeVisitor {
|
||||
|
||||
Widget _buildBullet(String listTag) {
|
||||
if (listTag == 'ul') {
|
||||
return Text(
|
||||
return Padding(
|
||||
padding: styleSheet.listBulletPadding,
|
||||
child: Text(
|
||||
'•',
|
||||
textAlign: TextAlign.center,
|
||||
style: styleSheet.listBullet,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final int index = _blocks.last.nextListIndex;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
padding: styleSheet.listBulletPadding,
|
||||
child: Text(
|
||||
'${index + 1}.',
|
||||
textAlign: TextAlign.right,
|
||||
|
@ -27,6 +27,7 @@ class MarkdownStyleSheet {
|
||||
this.blockSpacing,
|
||||
this.listIndent,
|
||||
this.listBullet,
|
||||
this.listBulletPadding,
|
||||
this.tableHead,
|
||||
this.tableBody,
|
||||
this.tableHeadAlign,
|
||||
@ -102,6 +103,7 @@ class MarkdownStyleSheet {
|
||||
blockSpacing: 8.0,
|
||||
listIndent: 24.0,
|
||||
listBullet: theme.textTheme.bodyText2,
|
||||
listBulletPadding: const EdgeInsets.only(right: 4),
|
||||
tableHead: const TextStyle(fontWeight: FontWeight.w600),
|
||||
tableBody: theme.textTheme.bodyText2,
|
||||
tableHeadAlign: TextAlign.center,
|
||||
@ -190,6 +192,7 @@ class MarkdownStyleSheet {
|
||||
blockSpacing: 8,
|
||||
listIndent: 24,
|
||||
listBullet: theme.textTheme.textStyle,
|
||||
listBulletPadding: const EdgeInsets.only(right: 4),
|
||||
tableHead: theme.textTheme.textStyle.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@ -266,6 +269,7 @@ class MarkdownStyleSheet {
|
||||
blockSpacing: 8.0,
|
||||
listIndent: 24.0,
|
||||
listBullet: theme.textTheme.bodyText2,
|
||||
listBulletPadding: const EdgeInsets.only(right: 4),
|
||||
tableHead: const TextStyle(fontWeight: FontWeight.w600),
|
||||
tableBody: theme.textTheme.bodyText2,
|
||||
tableHeadAlign: TextAlign.center,
|
||||
@ -317,6 +321,7 @@ class MarkdownStyleSheet {
|
||||
double blockSpacing,
|
||||
double listIndent,
|
||||
TextStyle listBullet,
|
||||
EdgeInsets listBulletPadding,
|
||||
TextStyle tableHead,
|
||||
TextStyle tableBody,
|
||||
TextAlign tableHeadAlign,
|
||||
@ -361,6 +366,7 @@ class MarkdownStyleSheet {
|
||||
blockSpacing: blockSpacing ?? this.blockSpacing,
|
||||
listIndent: listIndent ?? this.listIndent,
|
||||
listBullet: listBullet ?? this.listBullet,
|
||||
listBulletPadding: listBulletPadding ?? this.listBulletPadding,
|
||||
tableHead: tableHead ?? this.tableHead,
|
||||
tableBody: tableBody ?? this.tableBody,
|
||||
tableHeadAlign: tableHeadAlign ?? this.tableHeadAlign,
|
||||
@ -412,6 +418,7 @@ class MarkdownStyleSheet {
|
||||
blockSpacing: other.blockSpacing,
|
||||
listIndent: other.listIndent,
|
||||
listBullet: listBullet.merge(other.listBullet),
|
||||
listBulletPadding: other.listBulletPadding,
|
||||
tableHead: tableHead.merge(other.tableHead),
|
||||
tableBody: tableBody.merge(other.tableBody),
|
||||
tableHeadAlign: other.tableHeadAlign,
|
||||
@ -493,6 +500,9 @@ class MarkdownStyleSheet {
|
||||
/// The [TextStyle] to use for bullets.
|
||||
final TextStyle listBullet;
|
||||
|
||||
/// The padding to use for bullets.
|
||||
final EdgeInsets listBulletPadding;
|
||||
|
||||
/// The [TextStyle] to use for `th` elements.
|
||||
final TextStyle tableHead;
|
||||
|
||||
@ -592,6 +602,7 @@ class MarkdownStyleSheet {
|
||||
typedOther.blockSpacing == blockSpacing &&
|
||||
typedOther.listIndent == listIndent &&
|
||||
typedOther.listBullet == listBullet &&
|
||||
typedOther.listBulletPadding == listBulletPadding &&
|
||||
typedOther.tableHead == tableHead &&
|
||||
typedOther.tableBody == tableBody &&
|
||||
typedOther.tableHeadAlign == tableHeadAlign &&
|
||||
@ -639,6 +650,7 @@ class MarkdownStyleSheet {
|
||||
blockSpacing,
|
||||
listIndent,
|
||||
listBullet,
|
||||
listBulletPadding,
|
||||
tableHead,
|
||||
tableBody,
|
||||
tableHeadAlign,
|
||||
|
@ -271,5 +271,34 @@ void defineTests() {
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user