From 32c1e5ef6247257a8fc01618b68954fba12b5bbf Mon Sep 17 00:00:00 2001 From: Brian Kayfitz <71355739+brian-kayfitz@users.noreply.github.com> Date: Thu, 28 Nov 2024 05:53:06 -0500 Subject: [PATCH] Add helper functions to replace text styles and cell content --- pdf/lib/src/widgets/table_helper.dart | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pdf/lib/src/widgets/table_helper.dart b/pdf/lib/src/widgets/table_helper.dart index 3133f6ab..ebc2321d 100644 --- a/pdf/lib/src/widgets/table_helper.dart +++ b/pdf/lib/src/widgets/table_helper.dart @@ -24,6 +24,10 @@ import 'text_style.dart'; import 'theme.dart'; import 'widget.dart'; +typedef OnCell = Widget? Function(int index, dynamic data, int rowNum); +typedef OnCellTextStyle = TextStyle? Function( + int index, dynamic data, int rowNum); + mixin TableHelper { static TextAlign _textAlign(Alignment align) { if (align.x == 0) { @@ -71,6 +75,8 @@ mixin TableHelper { BoxDecoration? oddRowDecoration, TextDirection? headerDirection, TextDirection? tableDirection, + OnCell? cellBuilder, + OnCellTextStyle? textStyleBuilder, }) { assert(headerCount >= 0); @@ -161,14 +167,17 @@ mixin TableHelper { : cellDecoration(tableRow.length, cell, rowNum), child: cell is Widget ? cell - : Text( - cellFormat == null - ? cell.toString() - : cellFormat(tableRow.length, cell), - style: isOdd ? oddCellStyle : cellStyle, - textAlign: _textAlign(align.resolve(textDirection)), - textDirection: tableDirection, - ), + : cellBuilder?.call(tableRow.length, cell, rowNum) ?? + Text( + cellFormat == null + ? cell.toString() + : cellFormat(tableRow.length, cell), + style: textStyleBuilder?.call( + tableRow.length, cell, rowNum) ?? + (isOdd ? oddCellStyle : cellStyle), + textAlign: _textAlign(align.resolve(textDirection)), + textDirection: tableDirection, + ), ), ); }