clearEverything static method

Future<void> clearEverything()

Clears all persistent state, including cookies, caches, and local storage.

Implementation

static Future<void> clearEverything() async {
  if (kIsWeb) {
    return;
  }
  // Combine multiple calls into one.
  return _stateClearingFuture ??= () async {
    try {
      // Increment state so caches will be cleared
      _globalStateVersion++;

      // Reset stopwatch
      _globalStateExpirationStopwatch.reset();

      // Clear cookies in all web view instances.
      try {
        final instance = WebViewPlatform.instance;
        if (instance != null) {
          final cookieManager = instance.createPlatformCookieManager(
            const PlatformWebViewCookieManagerCreationParams(),
          );
          await cookieManager.clearCookies();
        }
      } catch (error, stackTrace) {
        assert(false, '$error\n\n$stackTrace');
        // Ignore error
      }
    } finally {
      _stateClearingFuture = null;
    }
  }();
}