Skip to content

Commit

Permalink
Add helper functions to replace text styles and cell content
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-kayfitz authored Nov 28, 2024
1 parent 030912d commit 32c1e5e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pdf/lib/src/widgets/table_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -71,6 +75,8 @@ mixin TableHelper {
BoxDecoration? oddRowDecoration,
TextDirection? headerDirection,
TextDirection? tableDirection,
OnCell? cellBuilder,
OnCellTextStyle? textStyleBuilder,
}) {
assert(headerCount >= 0);

Expand Down Expand Up @@ -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,
),
),
);
}
Expand Down

0 comments on commit 32c1e5e

Please sign in to comment.