From 9c67e58f18782e416bd64eb49b40dca34410f501 Mon Sep 17 00:00:00 2001 From: Joshua Petitma Date: Tue, 2 May 2023 08:06:58 -0400 Subject: [PATCH 1/5] Add TableCellVerticalAlignment property in markdown stylesheet --- packages/flutter_markdown/lib/src/builder.dart | 2 +- packages/flutter_markdown/lib/src/style_sheet.dart | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/flutter_markdown/lib/src/builder.dart b/packages/flutter_markdown/lib/src/builder.dart index e8521136b84..85e9eb04e5b 100644 --- a/packages/flutter_markdown/lib/src/builder.dart +++ b/packages/flutter_markdown/lib/src/builder.dart @@ -418,7 +418,7 @@ class MarkdownBuilder implements md.NodeVisitor { } else if (tag == 'table') { child = Table( defaultColumnWidth: styleSheet.tableColumnWidth!, - defaultVerticalAlignment: TableCellVerticalAlignment.middle, + defaultVerticalAlignment: styleSheet.tableVerticalAlignment, border: styleSheet.tableBorder, children: _tables.removeLast().rows, ); diff --git a/packages/flutter_markdown/lib/src/style_sheet.dart b/packages/flutter_markdown/lib/src/style_sheet.dart index 31ecc3e5d6d..0282f5a6e51 100644 --- a/packages/flutter_markdown/lib/src/style_sheet.dart +++ b/packages/flutter_markdown/lib/src/style_sheet.dart @@ -42,6 +42,7 @@ class MarkdownStyleSheet { this.tableColumnWidth, this.tableCellsPadding, this.tableCellsDecoration, + this.tableVerticalAlignment = TableCellVerticalAlignment.middle, this.blockquotePadding, this.blockquoteDecoration, this.codeblockPadding, @@ -362,6 +363,7 @@ class MarkdownStyleSheet { TableColumnWidth? tableColumnWidth, EdgeInsets? tableCellsPadding, Decoration? tableCellsDecoration, + TableCellVerticalAlignment? tableVerticalAlignment, EdgeInsets? blockquotePadding, Decoration? blockquoteDecoration, EdgeInsets? codeblockPadding, @@ -414,6 +416,8 @@ class MarkdownStyleSheet { tableColumnWidth: tableColumnWidth ?? this.tableColumnWidth, tableCellsPadding: tableCellsPadding ?? this.tableCellsPadding, tableCellsDecoration: tableCellsDecoration ?? this.tableCellsDecoration, + tableVerticalAlignment: + tableVerticalAlignment ?? this.tableVerticalAlignment, blockquotePadding: blockquotePadding ?? this.blockquotePadding, blockquoteDecoration: blockquoteDecoration ?? this.blockquoteDecoration, codeblockPadding: codeblockPadding ?? this.codeblockPadding, @@ -475,6 +479,7 @@ class MarkdownStyleSheet { tableColumnWidth: other.tableColumnWidth, tableCellsPadding: other.tableCellsPadding, tableCellsDecoration: other.tableCellsDecoration, + tableVerticalAlignment: other.tableVerticalAlignment, blockquotePadding: other.blockquotePadding, blockquoteDecoration: other.blockquoteDecoration, codeblockPadding: other.codeblockPadding, @@ -594,6 +599,9 @@ class MarkdownStyleSheet { /// The decoration to use for `th` and `td` elements. final Decoration? tableCellsDecoration; + /// The [TableCellVerticalAlignment] to use for `th` and `td` elements. + final TableCellVerticalAlignment tableVerticalAlignment; + /// The padding to use for `blockquote` elements. final EdgeInsets? blockquotePadding; @@ -692,6 +700,8 @@ class MarkdownStyleSheet { other.tableColumnWidth == tableColumnWidth && other.tableCellsPadding == tableCellsPadding && other.tableCellsDecoration == tableCellsDecoration && + other.tableVerticalAlignment == tableVerticalAlignment && + other.tableVerticalAlignment == tableVerticalAlignment && other.blockquotePadding == blockquotePadding && other.blockquoteDecoration == blockquoteDecoration && other.codeblockPadding == codeblockPadding && @@ -748,6 +758,7 @@ class MarkdownStyleSheet { tableColumnWidth, tableCellsPadding, tableCellsDecoration, + tableVerticalAlignment, blockquotePadding, blockquoteDecoration, codeblockPadding, From daa8316c5dc751e6a901972636c3ff1453667f95 Mon Sep 17 00:00:00 2001 From: Joshua Petitma Date: Tue, 2 May 2023 08:23:52 -0400 Subject: [PATCH 2/5] Update changelog and version --- packages/flutter_markdown/CHANGELOG.md | 3 ++- packages/flutter_markdown/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/flutter_markdown/CHANGELOG.md b/packages/flutter_markdown/CHANGELOG.md index c9376d87dc0..7283e65d17e 100644 --- a/packages/flutter_markdown/CHANGELOG.md +++ b/packages/flutter_markdown/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.6.15 +* Add tableVerticalAlignment property to allow aligning table cells vertically. * Updates minimum Flutter version to 3.3. * Aligns Dart and Flutter SDK constraints. diff --git a/packages/flutter_markdown/pubspec.yaml b/packages/flutter_markdown/pubspec.yaml index dedd749dc33..4bd0e141c99 100644 --- a/packages/flutter_markdown/pubspec.yaml +++ b/packages/flutter_markdown/pubspec.yaml @@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output, formatted with simple Markdown tags. repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22 -version: 0.6.14 +version: 0.6.15 environment: sdk: ">=2.18.0 <4.0.0" From b9c02d2818bf03162cbc4c8eb996414a8b46f0eb Mon Sep 17 00:00:00 2001 From: Joshua Petitma Date: Tue, 2 May 2023 16:34:35 -0400 Subject: [PATCH 3/5] Add test for table cell vertical alignment --- .../flutter_markdown/test/table_test.dart | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/flutter_markdown/test/table_test.dart b/packages/flutter_markdown/test/table_test.dart index 7d603423f66..46a4363829c 100644 --- a/packages/flutter_markdown/test/table_test.dart +++ b/packages/flutter_markdown/test/table_test.dart @@ -121,6 +121,27 @@ void defineTests() { }, ); + testWidgets( + 'table cell vertical alignment should follow stylesheet', + (WidgetTester tester) async { + final ThemeData theme = + ThemeData.light().copyWith(textTheme: textTheme); + + const String data = '|Header|\n|----|\n|Column|'; + const TableCellVerticalAlignment tableCellVerticalAlignment = + TableCellVerticalAlignment.top; + final MarkdownStyleSheet style = MarkdownStyleSheet.fromTheme(theme) + .copyWith(tableVerticalAlignment: tableCellVerticalAlignment); + + await tester.pumpWidget( + boilerplate(MarkdownBody(data: data, styleSheet: style))); + + final Table table = tester.widget(find.byType(Table)); + + expect(table.defaultVerticalAlignment, tableCellVerticalAlignment); + }, + ); + testWidgets( 'table with last row of empty table cells', (WidgetTester tester) async { From 4f8039f01f948127e3289612f8d7ebfc0e9c33ce Mon Sep 17 00:00:00 2001 From: Joshua Petitma Date: Mon, 15 May 2023 06:34:21 -0700 Subject: [PATCH 4/5] Address PR requests --- packages/flutter_markdown/CHANGELOG.md | 2 +- .../flutter_markdown/lib/src/style_sheet.dart | 1 - .../flutter_markdown/test/table_test.dart | 39 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/flutter_markdown/CHANGELOG.md b/packages/flutter_markdown/CHANGELOG.md index 7283e65d17e..88ba83bc3b5 100644 --- a/packages/flutter_markdown/CHANGELOG.md +++ b/packages/flutter_markdown/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.6.15 -* Add tableVerticalAlignment property to allow aligning table cells vertically. +* Adds `tableVerticalAlignment` property to allow aligning table cells vertically. * Updates minimum Flutter version to 3.3. * Aligns Dart and Flutter SDK constraints. diff --git a/packages/flutter_markdown/lib/src/style_sheet.dart b/packages/flutter_markdown/lib/src/style_sheet.dart index 0282f5a6e51..7b84b6f6cad 100644 --- a/packages/flutter_markdown/lib/src/style_sheet.dart +++ b/packages/flutter_markdown/lib/src/style_sheet.dart @@ -701,7 +701,6 @@ class MarkdownStyleSheet { other.tableCellsPadding == tableCellsPadding && other.tableCellsDecoration == tableCellsDecoration && other.tableVerticalAlignment == tableVerticalAlignment && - other.tableVerticalAlignment == tableVerticalAlignment && other.blockquotePadding == blockquotePadding && other.blockquoteDecoration == blockquoteDecoration && other.codeblockPadding == codeblockPadding && diff --git a/packages/flutter_markdown/test/table_test.dart b/packages/flutter_markdown/test/table_test.dart index 46a4363829c..19bf0841a7c 100644 --- a/packages/flutter_markdown/test/table_test.dart +++ b/packages/flutter_markdown/test/table_test.dart @@ -121,6 +121,24 @@ void defineTests() { }, ); + testWidgets( + 'table cell vertical alignment should default to middle', + (WidgetTester tester) async { + final ThemeData theme = + ThemeData.light().copyWith(textTheme: textTheme); + + const String data = '|Header|\n|----|\n|Column|'; + final MarkdownStyleSheet style = MarkdownStyleSheet.fromTheme(theme); + await tester.pumpWidget( + boilerplate(MarkdownBody(data: data, styleSheet: style))); + + final Table table = tester.widget(find.byType(Table)); + + expect( + table.defaultVerticalAlignment, TableCellVerticalAlignment.middle); + }, + ); + testWidgets( 'table cell vertical alignment should follow stylesheet', (WidgetTester tester) async { @@ -142,6 +160,27 @@ void defineTests() { }, ); + testWidgets( + 'table cell vertical alignment should follow stylesheet', + (WidgetTester tester) async { + final ThemeData theme = + ThemeData.light().copyWith(textTheme: textTheme); + + const String data = '|Header|\n|----|\n|Column|'; + const TableCellVerticalAlignment tableCellVerticalAlignment = + TableCellVerticalAlignment.bottom; + final MarkdownStyleSheet style = MarkdownStyleSheet.fromTheme(theme) + .copyWith(tableVerticalAlignment: tableCellVerticalAlignment); + + await tester.pumpWidget( + boilerplate(MarkdownBody(data: data, styleSheet: style))); + + final Table table = tester.widget(find.byType(Table)); + + expect(table.defaultVerticalAlignment, tableCellVerticalAlignment); + }, + ); + testWidgets( 'table with last row of empty table cells', (WidgetTester tester) async { From 5d44a3ff9188beddfb8f235f5af1d7fef8a1ca19 Mon Sep 17 00:00:00 2001 From: Joshua Petitma Date: Thu, 29 Jun 2023 21:40:27 -0700 Subject: [PATCH 5/5] Address pr comment --- packages/flutter_markdown/test/table_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_markdown/test/table_test.dart b/packages/flutter_markdown/test/table_test.dart index 19bf0841a7c..324aec97b0d 100644 --- a/packages/flutter_markdown/test/table_test.dart +++ b/packages/flutter_markdown/test/table_test.dart @@ -161,7 +161,7 @@ void defineTests() { ); testWidgets( - 'table cell vertical alignment should follow stylesheet', + 'table cell vertical alignment should follow stylesheet for different values', (WidgetTester tester) async { final ThemeData theme = ThemeData.light().copyWith(textTheme: textTheme);