diff --git a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart index 38c4ca88c..72518900b 100644 --- a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart @@ -172,6 +172,10 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController props.webMessageChannels as Set; _webMessageListeners = props.webMessageListeners as Set; + // restore the last URL if available + if (props.currentUrl != null) { + loadUrl(urlRequest: URLRequest(url: props.currentUrl)); + } } } } @@ -214,6 +218,18 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController _inAppBrowserEventHandler != null) { String? url = call.arguments["url"]; WebUri? uri = url != null ? WebUri(url) : null; + + // Update the current URL in the keepAlive properties + final keepAlive = webviewParams is PlatformInAppWebViewWidgetCreationParams ? + (webviewParams as PlatformInAppWebViewWidgetCreationParams).keepAlive : null; + if (keepAlive != null && uri != null) { + InAppWebViewControllerKeepAliveProps? props = _keepAliveMap[keepAlive]; + if (props != null) { + props.currentUrl = uri; + _keepAliveMap[keepAlive] = props; + } + } + if (webviewParams != null && webviewParams!.onLoadStop != null) webviewParams!.onLoadStop!(_controllerFromPlatform, uri); else diff --git a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart index f807fb8ff..46543137d 100644 --- a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart @@ -170,6 +170,10 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController props.webMessageChannels as Set; _webMessageListeners = props.webMessageListeners as Set; + // restore the last URL if available + if (props.currentUrl != null) { + loadUrl(urlRequest: URLRequest(url: props.currentUrl)); + } } } } @@ -212,6 +216,18 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController _inAppBrowserEventHandler != null) { String? url = call.arguments["url"]; WebUri? uri = url != null ? WebUri(url) : null; + + // Update the current URL in the keepAlive properties + final keepAlive = webviewParams is PlatformInAppWebViewWidgetCreationParams ? + (webviewParams as PlatformInAppWebViewWidgetCreationParams).keepAlive : null; + if (keepAlive != null && uri != null) { + InAppWebViewControllerKeepAliveProps? props = _keepAliveMap[keepAlive]; + if (props != null) { + props.currentUrl = uri; + _keepAliveMap[keepAlive] = props; + } + } + if (webviewParams != null && webviewParams!.onLoadStop != null) webviewParams!.onLoadStop!(_controllerFromPlatform, uri); else @@ -1605,7 +1621,7 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController html = await (await htmlRequest.close()).transform(Utf8Decoder()).join(); } catch (e) { - developer.log(e.toString(), name: this.runtimeType.toString()); + developer.log(e.toString(), name: runtimeType.toString()); } } diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_keep_alive.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_keep_alive.dart index cd7cff328..6078bed33 100644 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_keep_alive.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_keep_alive.dart @@ -29,6 +29,7 @@ class InAppWebViewControllerKeepAliveProps { Set webMessageChannels = Set(); Set webMessageListeners = Set(); Map devToolsProtocolEventListenerMap; + WebUri? currentUrl; InAppWebViewControllerKeepAliveProps( {this.javaScriptHandlersMap = const {}, @@ -37,5 +38,6 @@ class InAppWebViewControllerKeepAliveProps { this.injectedScriptsFromURL = const {}, this.webMessageChannels = const {}, this.webMessageListeners = const {}, - this.devToolsProtocolEventListenerMap = const {}}); + this.devToolsProtocolEventListenerMap = const {}, + this.currentUrl}); }