Showing
5 changed files
with
44 additions
and
4 deletions
@@ -2,6 +2,10 @@ | @@ -2,6 +2,10 @@ | ||
2 | 2 | ||
3 | ## 1.11.1 | 3 | ## 1.11.1 |
4 | 4 | ||
5 | +- Fix Table.fromTextArray vertical alignment | ||
6 | + | ||
7 | +## 1.11.1 | ||
8 | + | ||
5 | - Fix Table.fromTextArray alignments with multi-lines text | 9 | - Fix Table.fromTextArray alignments with multi-lines text |
6 | - Fix parameter type typo in Table.fromTextArray [Uli Prantz] | 10 | - Fix parameter type typo in Table.fromTextArray [Uli Prantz] |
7 | 11 |
@@ -39,7 +39,7 @@ class TableRow { | @@ -39,7 +39,7 @@ class TableRow { | ||
39 | final TableCellVerticalAlignment verticalAlignment; | 39 | final TableCellVerticalAlignment verticalAlignment; |
40 | } | 40 | } |
41 | 41 | ||
42 | -enum TableCellVerticalAlignment { bottom, middle, top } | 42 | +enum TableCellVerticalAlignment { bottom, middle, top, full } |
43 | 43 | ||
44 | enum TableWidth { min, max } | 44 | enum TableWidth { min, max } |
45 | 45 | ||
@@ -345,6 +345,7 @@ class Table extends Widget implements SpanningWidget { | @@ -345,6 +345,7 @@ class Table extends Widget implements SpanningWidget { | ||
345 | children: rows, | 345 | children: rows, |
346 | columnWidths: columnWidths, | 346 | columnWidths: columnWidths, |
347 | defaultColumnWidth: defaultColumnWidth, | 347 | defaultColumnWidth: defaultColumnWidth, |
348 | + defaultVerticalAlignment: TableCellVerticalAlignment.full, | ||
348 | ); | 349 | ); |
349 | } | 350 | } |
350 | 351 | ||
@@ -471,6 +472,25 @@ class Table extends Widget implements SpanningWidget { | @@ -471,6 +472,25 @@ class Table extends Widget implements SpanningWidget { | ||
471 | n++; | 472 | n++; |
472 | } | 473 | } |
473 | 474 | ||
475 | + final TableCellVerticalAlignment align = | ||
476 | + row.verticalAlignment ?? defaultVerticalAlignment; | ||
477 | + | ||
478 | + if (align == TableCellVerticalAlignment.full) { | ||
479 | + // Compute the layout again to give the full height to all cells | ||
480 | + n = 0; | ||
481 | + x = 0; | ||
482 | + for (Widget child in row.children) { | ||
483 | + final BoxConstraints childConstraints = | ||
484 | + BoxConstraints.tightFor(width: _widths[n], height: lineHeight); | ||
485 | + child.layout(context, childConstraints); | ||
486 | + assert(child.box != null); | ||
487 | + child.box = | ||
488 | + PdfRect(x, totalHeight, child.box.width, child.box.height); | ||
489 | + x += _widths[n]; | ||
490 | + n++; | ||
491 | + } | ||
492 | + } | ||
493 | + | ||
474 | if (totalHeight + lineHeight > constraints.maxHeight) { | 494 | if (totalHeight + lineHeight > constraints.maxHeight) { |
475 | index--; | 495 | index--; |
476 | break; | 496 | break; |
@@ -504,6 +524,7 @@ class Table extends Widget implements SpanningWidget { | @@ -504,6 +524,7 @@ class Table extends Widget implements SpanningWidget { | ||
504 | (_heights[heightIndex] + child.box.height) / 2; | 524 | (_heights[heightIndex] + child.box.height) / 2; |
505 | break; | 525 | break; |
506 | case TableCellVerticalAlignment.top: | 526 | case TableCellVerticalAlignment.top: |
527 | + case TableCellVerticalAlignment.full: | ||
507 | childY = totalHeight - child.box.y - child.box.height; | 528 | childY = totalHeight - child.box.y - child.box.height; |
508 | break; | 529 | break; |
509 | } | 530 | } |
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | ||
4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf | 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf |
5 | repository: https://github.com/DavBfr/dart_pdf | 5 | repository: https://github.com/DavBfr/dart_pdf |
6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
7 | -version: 1.11.1 | 7 | +version: 1.11.2 |
8 | 8 | ||
9 | environment: | 9 | environment: |
10 | sdk: ">=2.3.0 <3.0.0" | 10 | sdk: ">=2.3.0 <3.0.0" |
@@ -253,6 +253,21 @@ void main() { | @@ -253,6 +253,21 @@ void main() { | ||
253 | )); | 253 | )); |
254 | }); | 254 | }); |
255 | 255 | ||
256 | + test('Table fromTextArray with alignment', () { | ||
257 | + pdf.addPage( | ||
258 | + Page( | ||
259 | + build: (Context context) => Table.fromTextArray( | ||
260 | + cellAlignment: Alignment.center, | ||
261 | + data: <List<String>>[ | ||
262 | + <String>['line 1', 'Text\n\n\ntext'], | ||
263 | + <String>['line 2', 'Text\n\n\ntext'], | ||
264 | + <String>['line 3', 'Text\n\n\ntext'], | ||
265 | + ], | ||
266 | + ), | ||
267 | + ), | ||
268 | + ); | ||
269 | + }); | ||
270 | + | ||
256 | tearDownAll(() { | 271 | tearDownAll(() { |
257 | final File file = File('widgets-table.pdf'); | 272 | final File file = File('widgets-table.pdf'); |
258 | file.writeAsBytesSync(pdf.save()); | 273 | file.writeAsBytesSync(pdf.save()); |
No preview for this file type
-
Please register or login to post a comment