performLayout method
布局
Implementation
@override
performLayout(PrinterConstraints constraints, PrinterCanvas canvas) {
assert(constraints.maxHeight.isInfinite, '高度必须是浮动的');
cells.clear();
Map<int, TableCellData> mergeColumnMap = <int, TableCellData>{};
List data = this.dataSource!.execExpressionToValue(binding);
_rowCount = data.length;
double bottom = 0;
double rowHeight = this.size!.height ?? 0;
for (int y = 0; y < data.length; y++) {
final rowData = data[y];
var rowDataSource = RowDataSource(rowData, this.dataSource!, y);
if (condition != null && condition != '') {
var value = rowDataSource.execExpressionToValue(condition!);
if (value != true) {
continue;
}
}
double offsetX = 0;
for (int x = 0; x < children.length; x++) {
final child = children[x];
if (child.columnMerge == true) {
var mergeText = child.getDisplayText(rowDataSource);
if (mergeColumnMap.containsKey(x) &&
mergeColumnMap[x]!.mergeText == mergeText) {
mergeColumnMap[x]!.mergeRow++;
mergeColumnMap[x]!.size = PrinterSize(mergeColumnMap[x]!.size!.width,
mergeColumnMap[x]!.size!.height! + rowHeight);
} else {
var cell = TableCellData();
cell.rowData = rowDataSource;
cell.column = child;
cell.mergeRow = 1;
cell.mergeText = mergeText;
cell.rowIndex = y;
cell.columnIndex = x;
cell.offset = PrinterOffset(offsetX, bottom);
cell.size = PrinterSize(child.size!.width, rowHeight);
mergeColumnMap[x] = cell;
cells.add(cell);
}
} else {
var cell = TableCellData();
cell.rowData = rowDataSource;
cell.column = child;
cell.mergeRow = 1;
cell.rowIndex = y;
cell.columnIndex = x;
cell.offset = PrinterOffset(offsetX, bottom);
cell.size = PrinterSize(child.size!.width, rowHeight);
cells.add(cell);
}
offsetX += child.size!.width!;
}
bottom += rowHeight;
}
double rowWidth = 0;
for (var child in this.children) {
rowWidth += child.size!.width!;
}
actualOffset = this.offset;
actualSize = PrinterSize(rowWidth, bottom);
}