applyStyle method

void applyStyle(
  1. PdfGridStyleBase style
)

Enables you to set the appearance of the header row in a PdfGrid.

//Create a new PDF document
PdfDocument document = PdfDocument();
//Create a PdfGrid
PdfGrid grid = PdfGrid();
//Add columns to grid
grid.columns.add(count: 3);
//Gets the headers collection from the grid
PdfGridHeaderCollection headers = grid.headers;
//Add headers to grid
headers.add(1);
headers[0].cells[0].value = 'Employee ID';
headers[0].cells[1].value = 'Employee Name';
headers[0].cells[2].value = 'Salary';
//Create the header row style. Assign to whole headers
PdfGridRowStyle headerStyle = PdfGridRowStyle(
    backgroundBrush: PdfBrushes.lightGoldenrodYellow,
    textPen: PdfPens.indianRed,
    textBrush: PdfBrushes.lightYellow,
    font: PdfStandardFont(PdfFontFamily.timesRoman, 12));
headers.applyStyle(headerStyle);
//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';
//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 applyStyle(PdfGridStyleBase style) {
  if (style is PdfGridCellStyle) {
    for (int i = 0; i < _rows.length; i++) {
      final PdfGridRow row = _rows[i];
      for (int j = 0; j < row.cells.count; j++) {
        row.cells[j].style = style;
      }
    }
  } else if (style is PdfGridRowStyle) {
    for (int i = 0; i < _rows.length; i++) {
      _rows[i].style = style;
    }
  }
}