layoutSpan method
Splits a tall table across MultiPage pages, repeating repeat header rows.
Implementation
@override
SpanSlice? layoutSpan(Context context, BoxConstraints constraints) {
if (children.isEmpty) {
return SpanSlice(EmptyBox(), null);
}
if (!constraints.hasBoundedHeight) {
return SpanSlice(layout(context, constraints), null);
}
final List<TableRow> headers = <TableRow>[
for (final TableRow row in children)
if (row.repeat) row,
];
final List<TableRow> body = <TableRow>[
for (final TableRow row in children)
if (!row.repeat) row,
];
if (body.isEmpty) {
return SpanSlice(layout(context, constraints), null);
}
final double maxW =
constraints.hasBoundedWidth ? constraints.maxWidth : 400;
final List<double> headerH = _rowHeights(context, headers, maxW);
final List<double> bodyH = _rowHeights(context, body, maxW);
var chrome = 0.0;
for (final double h in headerH) {
chrome += h;
}
final double limit = constraints.maxHeight;
var take = 0;
var used = chrome;
for (int i = 0; i < body.length; i++) {
final double next = used + bodyH[i];
if (take > 0 && next > limit + 0.5) {
break;
}
used = next;
take++;
if (take == 1 && used > limit) {
break;
}
}
if (take <= 0) {
take = 1;
}
if (take >= body.length) {
return SpanSlice(layout(context, constraints), null);
}
final Table slice = _copyWith(<TableRow>[
...headers,
...body.take(take),
]);
final Table rest = _copyWith(<TableRow>[
...headers,
...body.skip(take),
]);
return SpanSlice(
slice.layout(
context,
BoxConstraints(maxWidth: maxW),
),
rest,
);
}