This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] onPageStarted, onPageReceiveError callbacks. #1788
Closed
just-kip
wants to merge
9
commits into
flutter:master
from
just-kip:feature/web_view_failure_listener
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8aed88e
Add onReceiveError feature to android code.
just-kip a3b3a24
Implement onReceiveHttpError.
just-kip 13d1d3f
Flutter tests.
just-kip 52e57ff
Add description.
just-kip 0affc51
Implement IOS error delegate.
just-kip 01b34e7
Implement onPageStarted callback in ios.
just-kip 7cc039f
OnPageStarted android callbacks and dart tests.
just-kip c65c100
Format flutter files.
just-kip e5a52f7
Format Objective-C and Java files.
just-kip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,14 @@ typedef NavigationDecision NavigationDelegate(NavigationRequest navigation); | |
| /// Signature for when a [WebView] has finished loading a page. | ||
| typedef void PageFinishedCallback(String url); | ||
|
|
||
| /// Signature for when a [WebView] receive a error. | ||
| /// Code may be NSURLErrorDomain code or const from Android WebViewClient or http status code. | ||
| /// Description is optional | ||
| typedef void PageReceiveErrorCallback(String url, int code, String description); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a guarantee that no WebResourceError code will ever be a valid HTTP response code? I think we should give developers a single way to detect errors that are the same on all platforms (e.g too many redirects). |
||
|
|
||
| /// Signature for when a [WebView] has started loading a page. | ||
| typedef void PageStartedCallback(String url); | ||
|
|
||
| final RegExp _validChannelNames = RegExp('^[a-zA-Z_][a-zA-Z0-9]*\$'); | ||
|
|
||
| /// A named channel for receiving messaged from JavaScript code running inside a web view. | ||
|
|
@@ -121,6 +129,8 @@ class WebView extends StatefulWidget { | |
| this.gestureRecognizers, | ||
| this.onPageFinished, | ||
| this.debuggingEnabled = false, | ||
| this.onPageReceiveError, | ||
| this.onPageStarted, | ||
| }) : assert(javascriptMode != null), | ||
| super(key: key); | ||
|
|
||
|
|
@@ -255,6 +265,10 @@ class WebView extends StatefulWidget { | |
| /// By default `debuggingEnabled` is false. | ||
| final bool debuggingEnabled; | ||
|
|
||
| final PageReceiveErrorCallback onPageReceiveError; | ||
|
|
||
| final PageStartedCallback onPageStarted; | ||
|
|
||
| @override | ||
| State<StatefulWidget> createState() => _WebViewState(); | ||
| } | ||
|
|
@@ -397,6 +411,20 @@ class _PlatformCallbacksHandler implements WebViewPlatformCallbacksHandler { | |
| } | ||
| } | ||
|
|
||
| @override | ||
| void onPageReceiveError({String url, int code, String description}) { | ||
| if (_widget.onPageReceiveError != null) { | ||
| _widget.onPageReceiveError(url, code, description); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| void onPageStarted(String url) { | ||
| if (_widget.onPageStarted != null) { | ||
| _widget.onPageStarted(url); | ||
| } | ||
| } | ||
|
|
||
| void _updateJavascriptChannelsFromSet(Set<JavascriptChannel> channels) { | ||
| _javascriptChannels.clear(); | ||
| if (channels == null) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs Dartdoc