Committed by
GitHub
Add helper functions to replace text styles and cell content
Showing
1 changed file
with
17 additions
and
8 deletions
@@ -24,6 +24,10 @@ import 'text_style.dart'; | @@ -24,6 +24,10 @@ import 'text_style.dart'; | ||
24 | import 'theme.dart'; | 24 | import 'theme.dart'; |
25 | import 'widget.dart'; | 25 | import 'widget.dart'; |
26 | 26 | ||
27 | +typedef OnCell = Widget? Function(int index, dynamic data, int rowNum); | ||
28 | +typedef OnCellTextStyle = TextStyle? Function( | ||
29 | + int index, dynamic data, int rowNum); | ||
30 | + | ||
27 | mixin TableHelper { | 31 | mixin TableHelper { |
28 | static TextAlign _textAlign(Alignment align) { | 32 | static TextAlign _textAlign(Alignment align) { |
29 | if (align.x == 0) { | 33 | if (align.x == 0) { |
@@ -71,6 +75,8 @@ mixin TableHelper { | @@ -71,6 +75,8 @@ mixin TableHelper { | ||
71 | BoxDecoration? oddRowDecoration, | 75 | BoxDecoration? oddRowDecoration, |
72 | TextDirection? headerDirection, | 76 | TextDirection? headerDirection, |
73 | TextDirection? tableDirection, | 77 | TextDirection? tableDirection, |
78 | + OnCell? cellBuilder, | ||
79 | + OnCellTextStyle? textStyleBuilder, | ||
74 | }) { | 80 | }) { |
75 | assert(headerCount >= 0); | 81 | assert(headerCount >= 0); |
76 | 82 | ||
@@ -161,14 +167,17 @@ mixin TableHelper { | @@ -161,14 +167,17 @@ mixin TableHelper { | ||
161 | : cellDecoration(tableRow.length, cell, rowNum), | 167 | : cellDecoration(tableRow.length, cell, rowNum), |
162 | child: cell is Widget | 168 | child: cell is Widget |
163 | ? cell | 169 | ? cell |
164 | - : Text( | ||
165 | - cellFormat == null | ||
166 | - ? cell.toString() | ||
167 | - : cellFormat(tableRow.length, cell), | ||
168 | - style: isOdd ? oddCellStyle : cellStyle, | ||
169 | - textAlign: _textAlign(align.resolve(textDirection)), | ||
170 | - textDirection: tableDirection, | ||
171 | - ), | 170 | + : cellBuilder?.call(tableRow.length, cell, rowNum) ?? |
171 | + Text( | ||
172 | + cellFormat == null | ||
173 | + ? cell.toString() | ||
174 | + : cellFormat(tableRow.length, cell), | ||
175 | + style: textStyleBuilder?.call( | ||
176 | + tableRow.length, cell, rowNum) ?? | ||
177 | + (isOdd ? oddCellStyle : cellStyle), | ||
178 | + textAlign: _textAlign(align.resolve(textDirection)), | ||
179 | + textDirection: tableDirection, | ||
180 | + ), | ||
172 | ), | 181 | ), |
173 | ); | 182 | ); |
174 | } | 183 | } |
-
Please register or login to post a comment