cleanup method

Future<void> cleanup()

Implementation

Future<void> cleanup() {
  _flushPolicyExecuter.cleanup();
  Future<void>? future = _appStateSubscription?.cancel();
  if (_deepLinkDataListener != null) {
    _deepLinkDataListener!();
  }
  _appState = null;
  if (_appStateSubscription != null) {
    final f = _appStateSubscription!.cancel();
    if (future != null) {
      future = Future.wait([future, f]);
    } else {
      future = f;
    }
    _appStateSubscription = null;
  }
  if (_deepLinkDataListener != null) {
    _deepLinkDataListener!();
    _deepLinkDataListener = null;
  }
  _pendingEvents.clear();
  _pluginsToAdd.clear();

  _timeline.apply((plugin) {
    plugin.clear();
  });

  _destroyed = true;
  _isInitialized = false;
  return future ?? Future.value();
}