Skip to content

[webview_flutter_platform_interface] Adds support to track url changes in the platform interface #3323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.1.0

* Adds support to track url changes. See `PlatformNavigationDelegate.setOnUrlChange`.
* Aligns Dart and Flutter SDK constraints.

## 2.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ typedef ProgressCallback = void Function(int progress);
/// Signature for callbacks that report a resource loading error.
typedef WebResourceErrorCallback = void Function(WebResourceError error);

/// Signature for callbacks that notify the host application of a change to the
/// url of the web view.
typedef UrlChangeCallback = void Function(UrlChange change);

/// An interface defining navigation events that occur on the native platform.
///
/// The [PlatformWebViewController] is notifying this delegate on events that
Expand Down Expand Up @@ -105,4 +109,13 @@ abstract class PlatformNavigationDelegate extends PlatformInterface {
throw UnimplementedError(
'setOnWebResourceError is not implemented on the current platform.');
}

/// Invoked when the underlying web view changes to a new url.
///
/// See [PlatformWebViewController.setPlatformNavigationDelegate].
Future<void> setOnUrlChange(UrlChangeCallback onUrlChange) {
throw UnimplementedError(
'setOnUrlChange is not implemented on the current platform.',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export 'platform_navigation_delegate_creation_params.dart';
export 'platform_webview_controller_creation_params.dart';
export 'platform_webview_cookie_manager_creation_params.dart';
export 'platform_webview_widget_creation_params.dart';
export 'url_change.dart';
export 'web_resource_error.dart';
export 'webview_cookie.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/cupertino.dart';

/// Details of the change to a web view's url.
///
/// Platform specific implementations can add additional fields by extending
/// this class.
///
/// This example demonstrates how to extend the [UrlChange] to provide
/// additional platform specific parameters:
///
/// ```dart
/// class AndroidUrlChange extends UrlChange {
/// const AndroidUrlChange({required super.url, required this.isReload});
///
/// final bool isReload;
/// }
/// ```
@immutable
class UrlChange {
/// Creates a new [UrlChange].
const UrlChange({required this.url});

/// The new url of the web view.
final String? url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.0.2
version: 2.1.0

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setOnNavigationRequest should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
Expand All @@ -66,7 +65,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setOnPageStarted should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
Expand All @@ -80,7 +78,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setOnPageFinished should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
Expand All @@ -94,7 +91,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setOnProgress should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
Expand All @@ -108,7 +104,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setOnWebResourceError should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
Expand All @@ -120,6 +115,19 @@ void main() {
throwsUnimplementedError,
);
});

test(
'Default implementation of setOnUrlChange should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
ExtendsPlatformNavigationDelegate(
const PlatformNavigationDelegateCreationParams());

expect(
() => callbackDelegate.setOnUrlChange((UrlChange change) {}),
throwsUnimplementedError,
);
});
}

class MockWebViewPlatformWithMixin extends MockWebViewPlatform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ void main() {
isNotNull);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of loadFile should throw unimplemented error',
test('Default implementation of loadFile should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -72,7 +70,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of loadFlutterAsset should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -86,7 +83,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of loadHtmlString should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -99,9 +95,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of loadRequest should throw unimplemented error',
test('Default implementation of loadRequest should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -113,9 +107,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of currentUrl should throw unimplemented error',
test('Default implementation of currentUrl should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -127,9 +119,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of canGoBack should throw unimplemented error',
test('Default implementation of canGoBack should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -142,7 +132,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of canGoForward should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -155,9 +144,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of goBack should throw unimplemented error', () {
test('Default implementation of goBack should throw unimplemented error', () {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
const PlatformWebViewControllerCreationParams());
Expand All @@ -168,9 +155,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of goForward should throw unimplemented error',
test('Default implementation of goForward should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -182,9 +167,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of reload should throw unimplemented error', () {
test('Default implementation of reload should throw unimplemented error', () {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
const PlatformWebViewControllerCreationParams());
Expand All @@ -195,9 +178,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of clearCache should throw unimplemented error',
test('Default implementation of clearCache should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -210,7 +191,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of clearLocalStorage should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand Down Expand Up @@ -239,7 +219,6 @@ void main() {
);

test(
// ignore: lines_longer_than_80_chars
'Default implementation of runJavaScript should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -253,7 +232,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of runJavaScriptReturningResult should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -267,7 +245,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of addJavaScriptChannel should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -286,7 +263,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of removeJavaScriptChannel should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -299,9 +275,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of getTitle should throw unimplemented error',
test('Default implementation of getTitle should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -313,9 +287,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of scrollTo should throw unimplemented error',
test('Default implementation of scrollTo should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -327,9 +299,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of scrollBy should throw unimplemented error',
test('Default implementation of scrollBy should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -342,7 +312,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of getScrollPosition should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -355,9 +324,7 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of enableZoom should throw unimplemented error',
test('Default implementation of enableZoom should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
Expand All @@ -370,7 +337,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setBackgroundColor should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -384,7 +350,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setJavaScriptMode should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand All @@ -398,7 +363,6 @@ void main() {
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of setUserAgent should throw unimplemented error',
() {
final PlatformWebViewController controller =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ class MockPlatformNavigationDelegate extends _i1.Mock
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);
@override
_i4.Future<void> setOnUrlChange(_i3.UrlChangeCallback? onUrlChange) =>
(super.noSuchMethod(
Invocation.method(
#setOnUrlChange,
[onUrlChange],
),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);
}
Loading