defaultLayerIndex property Null safety

int defaultLayerIndex

Gets or sets index of the default layer (Read only).

//Create a new PDF documentation
PdfDocument document = PdfDocument();
//Create a new PDF page and gets the default layer index
int layerIndex = document.pages.add().defaultLayerIndex;
//Save the document.
List<int> bytes =;
//Dispose the document.


int get defaultLayerIndex {
  if (layers.count == 0 || _defaultLayerIndex == -1) {
    final PdfPageLayer layer = layers.add();
    _defaultLayerIndex = layers.indexOf(layer);
  return _defaultLayerIndex;