@@ -41,27 +41,30 @@ class Sort {
41
41
final bool emptyFirst;
42
42
}
43
43
44
- String alignText (String text, int targetWidth, Side align) {
45
- switch (align) {
46
- case Side .start:
47
- return text.padRight (targetWidth);
48
- case Side .end:
49
- return text.padLeft (targetWidth);
50
- case Side .center:
51
- return alignTextCenter (text, targetWidth);
44
+ class Aligner {
45
+
46
+ String alignText (String text, int targetWidth, Side align) {
47
+ switch (align) {
48
+ case Side .start:
49
+ return text.padRight (targetWidth);
50
+ case Side .end:
51
+ return text.padLeft (targetWidth);
52
+ case Side .center:
53
+ return alignTextCenter (text, targetWidth);
54
+ }
52
55
}
53
- }
54
56
55
- bool centerOdd = true ;
57
+ bool centerOdd = true ; // that's why we need the object
56
58
57
- String alignTextCenter (String text, int targetWidth) {
58
- final halfD = (targetWidth - text.length)/ 2 ;
59
+ String alignTextCenter (String text, int targetWidth) {
60
+ final halfD = (targetWidth - text.length) / 2 ;
59
61
60
- final half = centerOdd ? halfD.ceil () : halfD.floor (); //>> 1;
61
- centerOdd = ! centerOdd;
62
- text = text.padLeft (text.length + half);
63
- text = text.padRight (targetWidth);
64
- return text;
62
+ final half = centerOdd ? halfD.ceil () : halfD.floor (); //>> 1;
63
+ centerOdd = ! centerOdd;
64
+ text = text.padLeft (text.length + half);
65
+ text = text.padRight (targetWidth);
66
+ return text;
67
+ }
65
68
}
66
69
67
70
/// Specifies how to convert the source value of the cell to a [String] .
@@ -435,6 +438,8 @@ String tabular(List<List<dynamic>> rows,
435
438
436
439
final formattedRows = < String > [];
437
440
441
+ final aligner = Aligner ();
442
+
438
443
var iRow = - 1 ;
439
444
for (var row in matrix.rows) {
440
445
iRow++ ;
@@ -458,7 +463,7 @@ String tabular(List<List<dynamic>> rows,
458
463
}
459
464
iCol++ ;
460
465
formatted +=
461
- alignText (cell.toFinalString (), matrix.columns[iCol].textWidth, colToAlign[iCol]);
466
+ aligner. alignText (cell.toFinalString (), matrix.columns[iCol].textWidth, colToAlign[iCol]);
462
467
}
463
468
464
469
if (outerBorder) {
0 commit comments