From f1d5b451ae64faa62d44ee9dd957942e53a470b1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 14 Jun 2022 20:13:12 -0700 Subject: [PATCH] [webview_flutter_wkwebview] Implements `currentUrl` (#5974) --- .../lib/src/web_kit_webview_widget.dart | 3 +++ .../test/src/web_kit_webview_widget_test.dart | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index b193fa8c1fac..a5c7c8f86ab6 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -354,6 +354,9 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { @override Future getTitle() => webView.getTitle(); + @override + Future currentUrl() => webView.getUrl(); + @override Future scrollTo(int x, int y) async { webView.scrollView.setContentOffset(Point( diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart index 905fdb542063..a1656badad01 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart @@ -783,6 +783,14 @@ void main() { expect(testController.getTitle(), completion('Web Title')); }); + testWidgets('currentUrl', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.getUrl()) + .thenAnswer((_) => Future.value('myUrl.com')); + expect(testController.currentUrl(), completion('myUrl.com')); + }); + testWidgets('scrollTo', (WidgetTester tester) async { await buildWidget(tester);