[webview_flutter_platform_interface] Adds support for retrieving user agent (#4563)

Platform interface portion of https://github.com/flutter/packages/pull/4472
This commit is contained in:
Maurice Parrish
2023-08-15 15:20:28 -04:00
committed by GitHub
parent 003a6c0827
commit 93455e07f7
4 changed files with 25 additions and 1 deletions

View File

@ -1,3 +1,7 @@
## 2.5.0
* Adds support to retrieve the user agent. See `PlatformWebViewController.getUserAgent`.
## 2.4.0
* Adds support to retrieve the url from a web resource loading error. See `WebResourceError.url`.

View File

@ -270,6 +270,13 @@ abstract class PlatformWebViewController extends PlatformInterface {
'setOnPermissionRequest is not implemented on the current platform',
);
}
/// Gets the value used for the HTTP `User-Agent:` request header.
Future<String?> getUserAgent() {
throw UnimplementedError(
'getUserAgent is not implemented on the current platform',
);
}
}
/// Describes the parameters necessary for registering a JavaScript channel.

View File

@ -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.4.0
version: 2.5.0
environment:
sdk: ">=2.18.0 <4.0.0"

View File

@ -387,6 +387,19 @@ void main() {
throwsUnimplementedError,
);
});
test(
'Default implementation of getUserAgent should throw unimplemented error',
() {
final PlatformWebViewController controller =
ExtendsPlatformWebViewController(
const PlatformWebViewControllerCreationParams());
expect(
() => controller.getUserAgent(),
throwsUnimplementedError,
);
});
}
class MockWebViewPlatformWithMixin extends MockWebViewPlatform