cancel method

void cancel()

Cancels the operation and signals the cancellation listener. If the operation has not yet started, then it will be canceled as soon as it does.

Implementation

void cancel() {
  if (_cancelled || _disposed) {
    return;
  }
  _cancelled = true;
  _cancelListener?.call();
  _initCompleter.operation.then((_) async {
    try {
      await _methodChannel.invokeMethod<void>('cancel', {'id': id});
    } catch (e) {
      // Ignore because the signal might be already disposed on native side
    } finally {
      dispose();
    }
  });
}