setSpan method

void setSpan(
  1. int rowIndex,
  2. int cellIndex,
  3. int rowSpan,
  4. int columnSpan,
)

Sets the row span and column span to a cell.

//Create a new PDF document
PdfDocument document = PdfDocument();
//Create a PdfGrid
PdfGrid grid = PdfGrid();
//Add columns to grid
grid.columns.add(count: 3);
//Add headers to grid
grid.headers.add(2);
PdfGridRow header = grid.headers[0];
header.cells[0].value = 'Employee ID';
header.cells[1].value = 'Employee Name';
header.cells[2].value = 'Salary';
//Add rows to grid
PdfGridRow row1 = grid.rows.add();
row1.cells[0].value = 'E01';
row1.cells[1].value = 'Clay';
row1.cells[2].value = '\$10,000';
PdfGridRow row2 = grid.rows.add();
row2.cells[0].value = 'E02';
row2.cells[1].value = 'Simon';
row2.cells[2].value = '\$12,000';
//Set the rows span
grid.rows.setSpan(0, 1, 2, 1);
//Set the row height
row2.height = 20;
//Set the row style
row1.style = PdfGridRowStyle(
    backgroundBrush: PdfBrushes.dimGray,
    textPen: PdfPens.lightGoldenrodYellow,
    textBrush: PdfBrushes.darkOrange,
    font: PdfStandardFont(PdfFontFamily.timesRoman, 12));
//Draw the grid in PDF document page
grid.draw(
    page: document.pages.add(), bounds: Rect.zero);
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

void setSpan(int rowIndex, int cellIndex, int rowSpan, int columnSpan) {
  if (rowIndex > _grid.rows.count) {
    ArgumentError.value(rowIndex, 'rowIndex', 'Index out of range');
  }
  if (cellIndex > _grid.columns.count) {
    ArgumentError.value(cellIndex, 'cellIndex', 'Index out of range');
  }
  final PdfGridCell cell = _grid.rows[rowIndex].cells[cellIndex];
  cell.rowSpan = rowSpan;
  cell.columnSpan = columnSpan;
}