Skip to content

[webview_flutter_platform_interface] Adds WebResourceRequest to HttpResponseError #4025

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

Closed
wants to merge 9 commits into from
Closed
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,3 +1,7 @@
## 2.9.0

* Adds `WebResourceRequest` and `WebResourceResponse` to `HttpResponseError`.

## 2.8.0

* Adds support to track scroll position changes. See `PlatformWebViewController.setOnScrollPositionChange`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import 'package:flutter/foundation.dart';

import 'web_resource_request.dart';
import 'web_resource_response.dart';

/// Error returned in `PlatformNavigationDelegate.setOnHttpError` when an HTTP
/// response error has been received.
///
Expand Down Expand Up @@ -37,9 +40,13 @@ import 'package:flutter/foundation.dart';
class HttpResponseError {
/// Used by the platform implementation to create a new [HttpResponseError].
const HttpResponseError({
required this.statusCode,
this.request,
this.response,
});

/// The HTTP status code.
final int statusCode;
/// The associated request.
final WebResourceRequest? request;

/// The associated response.
final WebResourceResponse? response;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types.dart needs to export both of these new files, unless I'm missing something, since it exports http_response_error.dart and these are now part of that class's public interface.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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/foundation.dart';

/// Defines the parameters of the web resource request from the associated request.
///
/// Platform specific implementations can add additional fields by extending
/// this class.
///
/// This example demonstrates how to extend the [WebResourceRequest] to
/// provide additional platform specific parameters.
///
/// When extending [WebResourceRequest] additional parameters should always
/// accept `null` or have a default value to prevent breaking changes.
///
/// ```dart
/// class AndroidWebResourceRequest extends WebResourceRequest {
/// WebResourceRequest._({
/// required WebResourceRequest request,
/// }) : super(
/// uri: request.uri,
/// );
///
/// factory AndroidWebResourceRequest.fromWebResourceRequest(
/// WebResourceRequest request, {
/// Map<String, String> headers,
/// }) {
/// return AndroidWebResourceRequest._(request, headers: headers);
/// }
///
/// final Map<String, String> headers;
/// }
/// ```
@immutable
class WebResourceRequest {
/// Used by the platform implementation to create a new [WebResourceRequest].
const WebResourceRequest({required this.uri});

/// URI for the request.
final Uri uri;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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/foundation.dart';

/// Contains information about the response for a request.
///
/// Platform specific implementations can add additional fields by extending
/// this class.
///
/// This example demonstrates how to extend the [WebResourceResponse] to
/// provide additional platform specific parameters.
///
/// When extending [WebResourceResponse] additional parameters should always
/// accept `null` or have a default value to prevent breaking changes.
///
/// ```dart
/// class AndroidWebResourceResponse extends WebResourceResponse {
/// WebResourceResponse._({
/// required WebResourceResponse response,
/// }) : super(
/// uri: response.uri,
/// statusCode: response.statusCode,
/// headers: response.headers,
/// );
///
/// factory AndroidWebResourceResponse.fromWebResourceResponse(
/// WebResourceResponse response, {
/// Uri? historyUrl,
/// }) {
/// return AndroidWebResourceResponse._(response, historyUrl: historyUrl);
/// }
///
/// final Uri? historyUrl;
/// }
/// ```
@immutable
class WebResourceResponse {
/// Used by the platform implementation to create a new [WebResourceResponse].
const WebResourceResponse({
required this.uri,
required this.statusCode,
this.headers = const <String, String>{},
});

/// The URI that this response is associated with.
final String? uri;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I know I said we should go back to String? above, but now that I'm looking at it again in the context of not asking it to be changed to a request object: shouldn't it be Uri??


/// The HTTP status code.
final int statusCode;

/// Headers for the request.
final Map<String, String> headers;
}
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.8.0
version: 2.9.0

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down