form property Null safety

PdfForm form

Gets the interactive form of the document.

Implementation

PdfForm get form {
  if (_helper.isLoadedDocument) {
    if (_form == null) {
      if (_helper.catalog.containsKey(PdfDictionaryProperties.acroForm)) {
        final IPdfPrimitive? formDictionary = PdfCrossTable.dereference(
            _helper.catalog[PdfDictionaryProperties.acroForm]);
        if (formDictionary is PdfDictionary) {
          _form = PdfFormHelper.internal(_helper.crossTable, formDictionary);
          if (_form != null && _form!.fields.count != 0) {
            _helper.catalog.form = _form;
            List<int>? widgetReference;
            if (PdfFormHelper.getHelper(_form!).crossTable!.document !=
                null) {
              for (int i = 0;
                  i <
                      PdfFormHelper.getHelper(_form!)
                          .crossTable!
                          .document!
                          .pages
                          .count;
                  i++) {
                final PdfPage page = PdfFormHelper.getHelper(_form!)
                    .crossTable!
                    .document!
                    .pages[i];
                widgetReference ??=
                    PdfPageHelper.getHelper(page).getWidgetReferences();
                if (widgetReference.isNotEmpty) {
                  PdfPageHelper.getHelper(page)
                      .createAnnotations(widgetReference);
                }
              }
              if (widgetReference != null) {
                widgetReference.clear();
              }
              if (!PdfFormHelper.getHelper(_form!).formHasKids) {
                PdfFormFieldCollectionHelper.getHelper(_form!.fields)
                    .createFormFieldsFromWidgets(_form!.fields.count);
              }
            }
          }
        }
      } else {
        _form = PdfFormHelper.internal(_helper.crossTable);
        _helper.catalog.setProperty(
            PdfDictionaryProperties.acroForm, PdfReferenceHolder(_form));
        _helper.catalog.form = _form;
        return _form!;
      }
    } else {
      return _form!;
    }
  } else {
    return _helper.catalog.form ??= PdfForm();
  }
  return _form!;
}