kill method

void kill([
  1. Object? targets
])

Removes a tween or a list of tweens from the timeline.

This method removes a tween or a list of tweens from the timeline, stopping its execution and removing its reference.

If targets is a list of maps or GTweenable targets, all tweens that target those objects will be removed. Otherwise, it will look for the first GTweenable associated with the targets and remove it from the timeline.

If the tween doesn't have any other references, it will be garbage collected.

If targets is not provided, the tween's target will be used as the target to kill.

Implementation

void kill([Object? targets]) {
  targets ??= _targets ?? target;
  var pt = _firstPT;
  if (targets is List) {
    var targetList = targets;
    if (targetList.first is Map<String, dynamic> ||
        targetList.first is GTweenable) {
      var i = targetList.length;
      while (--i > -1) {
        kill(targetList[i]);
      }
      return;
    }
  } else if (_targets != null) {
    var i = _targets!.length;
    if (targets is! GTweenable) {
      targets = _getAnimatable(targets!);
    }
    while (--i > -1) {
      if (targets == _targets![i]) {
        _targets!.removeAt(i);
      }
    }
    while (pt != null) {
      if (pt.t == targets) {
        if (pt._next != null) {
          pt._next!._prev = pt._prev;
        }
        if (pt._prev != null) {
          pt._prev!._next = pt._next;
        } else {
          _firstPT = pt._next;
        }
      }
      pt = pt._next;
    }
  }
  if (_targets == null || _targets!.isEmpty) {
    _gc = true;
    if (_prev != null) {
      _prev!._next = _next;
    } else if (this == _first) {
      _first = _next;
    }
    if (_next != null) {
      _next!._prev = _prev;
    } else if (this == _last) {
      _last = _prev;
    }
    if (target is GTweenable) {
      (target as GTweenable).dispose();
    }
//      nanoVars = null;
//      vars = null;
    _next = _prev = null;
  }
}