setMargins method Null safety

void setMargins(
  1. double all,
  2. [double? top,
  3. double? right,
  4. double? bottom]
)

Sets the margins.

//Create a PDF document.
PdfDocument document = PdfDocument();
//Set margins.
document.pageSettings.setMargins(50);
//Create page and draw text.
document.pages.add().graphics.drawString(
    'Hello World!', PdfStandardFont(PdfFontFamily.helvetica, 12),
    brush: PdfBrushes.black, bounds: Rect.fromLTWH(0, 0, 0, 0));
//Save and dispose document.
List<int> bytes = document.save();
document.dispose();

Implementation

void setMargins(double all, [double? top, double? right, double? bottom]) {
  if (!_isPageAdded) {
    if (top != null && right != null && bottom != null) {
      margins._setMarginsAll(all, top, right, bottom);
    } else if (top != null && right == null) {
      margins._setMarginsLT(all, top);
    } else if (top == null && bottom != null) {
      margins._setMarginsLT(all, bottom);
    } else {
      margins._setMargins(all);
    }
  }
}