David PHAM-VAN

Fix Table.fromTextArray alignments with multi-lines text

1 # Changelog 1 # Changelog
2 2
  3 +## 1.11.1
  4 +
  5 +- Fix Table.fromTextArray alignments with multi-lines text
  6 +
3 ## 1.11.0 7 ## 1.11.0
4 8
5 - Fix mixing Arabic with English [Anas Altair] 9 - Fix mixing Arabic with English [Anas Altair]
@@ -286,9 +286,13 @@ class Table extends Widget implements SpanningWidget { @@ -286,9 +286,13 @@ class Table extends Widget implements SpanningWidget {
286 286
287 if (rowNum < headerCount) { 287 if (rowNum < headerCount) {
288 for (final dynamic cell in row) { 288 for (final dynamic cell in row) {
  289 + final Alignment align =
  290 + headerAlignments[tableRow.length] ?? headerAlignment;
  291 + final TextAlign textAlign = _textAlign(align);
  292 +
289 tableRow.add( 293 tableRow.add(
290 Container( 294 Container(
291 - alignment: headerAlignments[tableRow.length] ?? headerAlignment, 295 + alignment: align,
292 padding: headerPadding, 296 padding: headerPadding,
293 constraints: BoxConstraints(minHeight: headerHeight), 297 constraints: BoxConstraints(minHeight: headerHeight),
294 child: Text( 298 child: Text(
@@ -296,15 +300,19 @@ class Table extends Widget implements SpanningWidget { @@ -296,15 +300,19 @@ class Table extends Widget implements SpanningWidget {
296 ? cell.toString() 300 ? cell.toString()
297 : headerFormat(tableRow.length, cell), 301 : headerFormat(tableRow.length, cell),
298 style: headerStyle, 302 style: headerStyle,
  303 + textAlign: textAlign,
299 ), 304 ),
300 ), 305 ),
301 ); 306 );
302 } 307 }
303 } else { 308 } else {
304 for (final dynamic cell in row) { 309 for (final dynamic cell in row) {
  310 + final Alignment align =
  311 + cellAlignments[tableRow.length] ?? cellAlignment;
  312 + final TextAlign textAlign = _textAlign(align);
305 tableRow.add( 313 tableRow.add(
306 Container( 314 Container(
307 - alignment: cellAlignments[tableRow.length] ?? cellAlignment, 315 + alignment: align,
308 padding: cellPadding, 316 padding: cellPadding,
309 constraints: BoxConstraints(minHeight: cellHeight), 317 constraints: BoxConstraints(minHeight: cellHeight),
310 child: Text( 318 child: Text(
@@ -312,6 +320,7 @@ class Table extends Widget implements SpanningWidget { @@ -312,6 +320,7 @@ class Table extends Widget implements SpanningWidget {
312 ? cell.toString() 320 ? cell.toString()
313 : cellFormat(tableRow.length, cell), 321 : cellFormat(tableRow.length, cell),
314 style: isOdd ? oddCellStyle : cellStyle, 322 style: isOdd ? oddCellStyle : cellStyle,
  323 + textAlign: textAlign,
315 ), 324 ),
316 ), 325 ),
317 ); 326 );
@@ -585,4 +594,14 @@ class Table extends Widget implements SpanningWidget { @@ -585,4 +594,14 @@ class Table extends Widget implements SpanningWidget {
585 border.paint(context, box, _widths, _heights); 594 border.paint(context, box, _widths, _heights);
586 } 595 }
587 } 596 }
  597 +
  598 + static TextAlign _textAlign(Alignment align) {
  599 + if (align.x == 0) {
  600 + return TextAlign.center;
  601 + } else if (align.x < 0) {
  602 + return TextAlign.left;
  603 + } else {
  604 + return TextAlign.right;
  605 + }
  606 + }
588 } 607 }
@@ -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.0 7 +version: 1.11.1
8 8
9 environment: 9 environment:
10 sdk: ">=2.3.0 <3.0.0" 10 sdk: ">=2.3.0 <3.0.0"