removeAt method Null safety

void removeAt(
  1. int index
)

Remove the bookmark from the document at the specified index.

//Load the PDF document.
PdfDocument document = PdfDocument(inputBytes: inputBytes);
//Remove specified bookmark using index.
document.bookmarks.removeAt(0);
//Save the document.
List<int> bytes = await document.save();
//Dispose the document.
document.dispose();

Implementation

void removeAt(int index) {
  if (_bookmark == null || _bookmark!.length < _list.length) {
    _bookmark = <PdfBookmark>[];
    for (int n = 0; n < _list.length; n++) {
      if (_list[n] is PdfBookmark?) {
        _bookmark!.add(_list[n] as PdfBookmark);
      }
    }
  }
  if (index < 0 || index >= _bookmark!.length) {
    throw RangeError.value(index);
  }
  final PdfBookmark current = _bookmark![index];
  if (index == 0) {
    if (current._helper.dictionary!
        .containsKey(PdfDictionaryProperties.next)) {
      _helper.dictionary!.setProperty(PdfDictionaryProperties.first,
          current._helper.dictionary![PdfDictionaryProperties.next]);
    } else {
      _helper.dictionary!.remove(PdfDictionaryProperties.first);
      _helper.dictionary!.remove(PdfDictionaryProperties.last);
    }
  } else if ((current._parent != null) &&
      (current._previous != null) &&
      (current._next != null)) {
    current._previous!._helper.dictionary!.setProperty(
        PdfDictionaryProperties.next,
        current._helper.dictionary![PdfDictionaryProperties.next]);
    current._next!._helper.dictionary!.setProperty(
        PdfDictionaryProperties.prev,
        current._helper.dictionary![PdfDictionaryProperties.prev]);
  } else if ((current._parent != null) &&
      (current._previous != null) &&
      (current._next == null)) {
    current._previous!._helper.dictionary!
        .remove(PdfDictionaryProperties.next);
    current._parent!._helper.dictionary!.setProperty(
        PdfDictionaryProperties.last,
        current._helper.dictionary![PdfDictionaryProperties.prev]);
  }
  if (current._parent != null) {
    current._parent!._list.remove(current);
  }
  _bookmark!.clear();
  _updateFields();
}