restart method

String restart(
  1. String? webOrigin
)

Restarts the web app.

The webOrigin parameter is optional. If it's null, the method uses the window.origin to get the site origin. This parameter should only be filled when your current origin is different than the app's origin. It defaults to null.

This method replaces the current location with the given webOrigin (or window.origin if webOrigin is null), effectively reloading the web app.

Implementation

String restart(String? webOrigin) {
  try {
    final origin =
        (webOrigin != null && webOrigin.isNotEmpty) ? webOrigin : null;
    if (origin != null && origin.startsWith('#')) {
      web.window.location.hash = origin;
      web.window.location.reload();
    } else if (origin != null) {
      web.window.location.replace(origin);
    } else {
      // window.origin returns the literal string "null" in sandboxed iframes,
      // so we avoid passing it to replace() and fall back to a simple reload.
      final windowOrigin = web.window.origin.toString();
      if (windowOrigin.isNotEmpty && windowOrigin != 'null') {
        web.window.location.replace(windowOrigin);
      } else {
        web.window.location.reload();
      }
    }
    return 'ok';
  } catch (e) {
    throw PlatformException(
      code: 'RESTART_FAILED',
      message: 'Failed to reload the page: $e',
    );
  }
}