buildExport method

Widget buildExport(
  1. BuildContext context, {
  2. List<int>? rowIndices,
})

Builds all columns and the requested rows at their natural dimensions.

This eager, non-interactive layout is intended for bounded exports, not live scrolling. It reuses cell builders without mounting spreadsheet controllers, selection effects or animations. Builders must not reuse GlobalKeys attached to another tree. rowIndices preserves supplied order.

Zoom is deliberately not applied: an export is the sheet at 100%, at exportSize's natural dimensions, so a PDF or a screenshot never inherits the factor someone set on screen. Only the live widget scales.

Implementation

Widget buildExport(BuildContext context, {List<int>? rowIndices}) {
  final indices = rowIndices ?? List<int>.generate(rowCount, (i) => i);
  for (final index in indices) {
    if (index < 0 || index >= rowCount) {
      throw RangeError.range(index, 0, rowCount - 1, 'rowIndex');
    }
  }
  final outerPadding = padding.resolve(Directionality.of(context));
  final innerPadding = rowPadding.resolve(Directionality.of(context));
  final widths = List<double>.generate(
      columnCount, (i) => columnWidthBuilder?.call(i) ?? 180);
  final headerWidth = rowHeaderBuilder == null ? 0.0 : rowHeaderWidth;
  final width = headerWidth +
      widths.fold(0.0, (a, b) => a + b) +
      innerPadding.horizontal;
  Widget strip(int? row) => SizedBox(
        height:
            row == null ? headerHeight : rowHeightBuilder?.call(row) ?? 92,
        child: Padding(
          padding: row == null ? EdgeInsets.zero : innerPadding,
          child: Row(children: [
            if (rowHeaderBuilder != null)
              SizedBox(
                  width: rowHeaderWidth,
                  child: row == null
                      ? cornerBuilder?.call(context)
                      : rowHeaderBuilder!(context, row)),
            for (var col = 0; col < columnCount; col++)
              SizedBox(
                  width: widths[col],
                  height: double.infinity,
                  child: row == null
                      ? columnHeaderBuilder?.call(context, col)
                      : cellBuilder(context, row, col)),
          ]),
        ),
      );
  return IgnorePointer(
      child: Container(
    color: backgroundColor,
    padding: outerPadding,
    width: width + outerPadding.horizontal,
    child: Column(mainAxisSize: MainAxisSize.min, children: [
      if (showColumnHeader) strip(null),
      for (final row in indices) strip(row),
    ]),
  ));
}