David PHAM-VAN

Fix Table.fromTextArray vertical alignment

... ... @@ -2,6 +2,10 @@
## 1.11.1
- Fix Table.fromTextArray vertical alignment
## 1.11.1
- Fix Table.fromTextArray alignments with multi-lines text
- Fix parameter type typo in Table.fromTextArray [Uli Prantz]
... ...
... ... @@ -39,7 +39,7 @@ class TableRow {
final TableCellVerticalAlignment verticalAlignment;
}
enum TableCellVerticalAlignment { bottom, middle, top }
enum TableCellVerticalAlignment { bottom, middle, top, full }
enum TableWidth { min, max }
... ... @@ -345,6 +345,7 @@ class Table extends Widget implements SpanningWidget {
children: rows,
columnWidths: columnWidths,
defaultColumnWidth: defaultColumnWidth,
defaultVerticalAlignment: TableCellVerticalAlignment.full,
);
}
... ... @@ -471,6 +472,25 @@ class Table extends Widget implements SpanningWidget {
n++;
}
final TableCellVerticalAlignment align =
row.verticalAlignment ?? defaultVerticalAlignment;
if (align == TableCellVerticalAlignment.full) {
// Compute the layout again to give the full height to all cells
n = 0;
x = 0;
for (Widget child in row.children) {
final BoxConstraints childConstraints =
BoxConstraints.tightFor(width: _widths[n], height: lineHeight);
child.layout(context, childConstraints);
assert(child.box != null);
child.box =
PdfRect(x, totalHeight, child.box.width, child.box.height);
x += _widths[n];
n++;
}
}
if (totalHeight + lineHeight > constraints.maxHeight) {
index--;
break;
... ... @@ -504,6 +524,7 @@ class Table extends Widget implements SpanningWidget {
(_heights[heightIndex] + child.box.height) / 2;
break;
case TableCellVerticalAlignment.top:
case TableCellVerticalAlignment.full:
childY = totalHeight - child.box.y - child.box.height;
break;
}
... ...
... ... @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 1.11.1
version: 1.11.2
environment:
sdk: ">=2.3.0 <3.0.0"
... ...
... ... @@ -253,6 +253,21 @@ void main() {
));
});
test('Table fromTextArray with alignment', () {
pdf.addPage(
Page(
build: (Context context) => Table.fromTextArray(
cellAlignment: Alignment.center,
data: <List<String>>[
<String>['line 1', 'Text\n\n\ntext'],
<String>['line 2', 'Text\n\n\ntext'],
<String>['line 3', 'Text\n\n\ntext'],
],
),
),
);
});
tearDownAll(() {
final File file = File('widgets-table.pdf');
file.writeAsBytesSync(pdf.save());
... ...