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 = 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);
  }
  if (_bookmark![index] is PdfBookmark) {
    final PdfBookmark current = _bookmark![index];
    if (index == 0) {
      if (current._dictionary!.containsKey(_DictionaryProperties.next)) {
        _dictionary!.setProperty(_DictionaryProperties.first,
            current._dictionary![_DictionaryProperties.next]);
      } else {
        _dictionary!.remove(_DictionaryProperties.first);
        _dictionary!.remove(_DictionaryProperties.last);
      }
    } else if ((current._parent != null) &&
        (current._previous != null) &&
        (current._next != null)) {
      current._previous!._dictionary!.setProperty(_DictionaryProperties.next,
          current._dictionary![_DictionaryProperties.next]);
      current._next!._dictionary!.setProperty(_DictionaryProperties.prev,
          current._dictionary![_DictionaryProperties.prev]);
    } else if ((current._parent != null) &&
        (current._previous != null) &&
        (current._next == null)) {
      current._previous!._dictionary!.remove(_DictionaryProperties.next);
      current._parent!._dictionary!.setProperty(_DictionaryProperties.last,
          current._dictionary![_DictionaryProperties.prev]);
    }
    if (current._parent != null) {
      current._parent!._list.remove(current);
    }
  }
  _bookmark!.clear();
  _updateFields();
}