PdfCompositeField constructor Null safety

PdfCompositeField(
  1. {PdfFont? font,
  2. PdfBrush? brush,
  3. String? text,
  4. List<PdfAutomaticField>? fields}
)

Initializes the new instance of the PdfCompositeField class.

font - Specifies the PdfFont to use. brush - Specifies the color and texture to the text. text - The wide-chracter string to be drawn. fields - The list of PdfAutomaticField objects.

//Create a new pdf document
PdfDocument document = PdfDocument();
//Add the pages to the document
for (int i = 1; i <= 5; i++) {
  document.pages.add().graphics.drawString(
      'page$i', PdfStandardFont(PdfFontFamily.timesRoman, 11),
      bounds: Rect.fromLTWH(250, 0, 615, 100));
}
//Create the header with specific bounds
PdfPageTemplateElement header = PdfPageTemplateElement(
    Rect.fromLTWH(0, 0, document.pages[0].getClientSize().width, 300));
//Create the date and time field
PdfDateTimeField dateAndTimeField = PdfDateTimeField(
    font: PdfStandardFont(PdfFontFamily.timesRoman, 19),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)));
//Create the composite field with date field
PdfCompositeField compositefields = PdfCompositeField(
    font: PdfStandardFont(PdfFontFamily.timesRoman, 19),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)),
    text: '{0}      Header',
    fields: <PdfAutomaticField>[dateAndTimeField]);
//Add composite field in header
compositefields.draw(header.graphics,
    Offset(0, 50 - PdfStandardFont(PdfFontFamily.timesRoman, 11).height));
//Add the header at top of the document
document.template.top = header;
//Save the document.
List<int> bytes = document.save();
//Dispose the document.
document.dispose();

Implementation

PdfCompositeField(
    {PdfFont? font,
    PdfBrush? brush,
    String? text,
    List<PdfAutomaticField>? fields})
    : super(font: font, brush: brush) {
  this.text = (text == null) ? '' : text;
  if (fields != null) {
    this.fields = fields;
  }
}