remove method Null safety

void remove(
  1. {PdfLayer? layer,
  2. String? name,
  3. bool isRemoveGraphicalContent = false}
)

Removes layer from the collection by using layer or layer name and may also remove graphical content, if isRemoveGraphicalContent is true.

Implementation

void remove(
    {PdfLayer? layer, String? name, bool isRemoveGraphicalContent = false}) {
  if (layer != null) {
    _removeLayer(layer, isRemoveGraphicalContent);
    _list.remove(layer);
  } else if (name != null) {
    bool isFind = false;
    for (int i = 0; i < _list.length; i++) {
      final PdfLayer layer = _list[i] as PdfLayer;
      if (layer.name == name) {
        isFind = true;
        _removeLayer(layer, isRemoveGraphicalContent);
        _list.remove(layer);
        i = i - 1;
      }
    }
    if (!isFind) {
      ArgumentError.value('Given layerName is not found');
    }
  } else {
    ArgumentError.value('layer or layerName must be required');
  }
}