page property Null safety

PdfPage? page

Gets the page of the field.

Implementation

PdfPage? get page {
  if (_page == null) {
    final int backUpIndex = _field._defaultIndex;
    _field._defaultIndex = _collectionIndex;
    _page = _field.page;
    final _PdfName pName = _PdfName(_DictionaryProperties.p);
    if (_field._kids != null && _field._kids!.count > 0) {
      final PdfDocument? doc = _field._crossTable!._document;
      if (doc != null && doc._isLoadedDocument) {
        if (_dictionary!.containsKey(pName)) {
          final _IPdfPrimitive? pageRef = _field._crossTable!
              ._getObject(_dictionary![_DictionaryProperties.p]);
          if (pageRef != null && pageRef is _PdfDictionary) {
            final _PdfReference widgetReference =
                _field._crossTable!._getReference(_dictionary);
            for (int i = 0; i < doc.pages.count; i++) {
              final PdfPage loadedPage = doc.pages[i];
              final _PdfArray? lAnnots = loadedPage._obtainAnnotations();
              if (lAnnots != null) {
                for (int i = 0; i < lAnnots.count; i++) {
                  final _IPdfPrimitive? holder = lAnnots[i];
                  if (holder != null &&
                      holder is _PdfReferenceHolder &&
                      holder.reference!._objNum == widgetReference._objNum &&
                      holder.reference!._genNum == widgetReference._genNum) {
                    _page = doc.pages._getPage(pageRef);
                    _field._defaultIndex = backUpIndex;
                    return _page;
                  }
                }
              }
            }
            _field._defaultIndex = backUpIndex;
            _page = null;
          }
        } else {
          final _PdfReference widgetReference =
              _field._crossTable!._getReference(_dictionary);
          for (int i = 0; i < doc.pages.count; i++) {
            final PdfPage loadedPage = doc.pages[i];
            final _PdfArray? lAnnots = loadedPage._obtainAnnotations();
            if (lAnnots != null) {
              for (int i = 0; i < lAnnots.count; i++) {
                final _IPdfPrimitive? holder = lAnnots[i];
                if (holder != null &&
                    holder is _PdfReferenceHolder &&
                    holder.reference!._objNum == widgetReference._objNum &&
                    holder.reference!._genNum == widgetReference._genNum) {
                  return _page = loadedPage;
                }
              }
            }
          }
          _page = null;
        }
      }
    }
    _field._defaultIndex = backUpIndex;
  }
  return _page;
}