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]Support UserAgent setting for webview_flutter #968
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73551b8
Add UserAgent setting
YukiOya d901714
Add UserAgent getter
YukiOya f527cbb
Add test UserAgent
YukiOya d1ff6c6
Fix support target for setting UserAgent
YukiOya 9d10411
Add e2e test
YukiOya ec1a90a
Fix getter docs
YukiOya 01dd5ad
Fix getter name
YukiOya 92a27f8
Add rebuild test case
YukiOya 7d40cd1
Fix format
YukiOya 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,7 @@ class WebView extends StatefulWidget { | |
| this.javascriptMode = JavascriptMode.disabled, | ||
| this.javascriptChannels, | ||
| this.navigationDelegate, | ||
| this.userAgent, | ||
| this.gestureRecognizers, | ||
| this.onPageFinished, | ||
| this.debuggingEnabled = false, | ||
|
|
@@ -256,6 +257,9 @@ class WebView extends StatefulWidget { | |
| /// By default `debuggingEnabled` is false. | ||
| final bool debuggingEnabled; | ||
|
|
||
| /// The custom UserAgent. | ||
|
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. We should have more information in this Dartdoc, some question I think I might be having if I were looking here:
In general I recommend reading the documentation section in the Flutter style guide which we should follow here. |
||
| final String userAgent; | ||
|
|
||
| @override | ||
| State<StatefulWidget> createState() => _WebViewState(); | ||
| } | ||
|
|
@@ -349,25 +353,29 @@ class _WebSettings { | |
| this.javascriptMode, | ||
| this.hasNavigationDelegate, | ||
| this.debuggingEnabled, | ||
| this.userAgent, | ||
| }); | ||
|
|
||
| static _WebSettings fromWidget(WebView widget) { | ||
| return _WebSettings( | ||
| javascriptMode: widget.javascriptMode, | ||
| hasNavigationDelegate: widget.navigationDelegate != null, | ||
| debuggingEnabled: widget.debuggingEnabled, | ||
| userAgent: widget.userAgent, | ||
| ); | ||
| } | ||
|
|
||
| final JavascriptMode javascriptMode; | ||
| final bool hasNavigationDelegate; | ||
| final bool debuggingEnabled; | ||
| final String userAgent; | ||
|
|
||
| Map<String, dynamic> toMap() { | ||
| return <String, dynamic>{ | ||
| 'jsMode': javascriptMode.index, | ||
| 'hasNavigationDelegate': hasNavigationDelegate, | ||
| 'debuggingEnabled': debuggingEnabled, | ||
| 'userAgent': userAgent, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -384,6 +392,9 @@ class _WebSettings { | |
| updates['debuggingEnabled'] = newSettings.debuggingEnabled; | ||
| } | ||
|
|
||
| if (userAgent != newSettings.userAgent) { | ||
| updates['userAgent'] = newSettings.userAgent; | ||
| } | ||
| return updates; | ||
| } | ||
| } | ||
|
|
@@ -529,6 +540,11 @@ class WebViewController { | |
| return _channel.invokeMethod("reload"); | ||
| } | ||
|
|
||
| /// Returns the User-Agent value that will be used for subsequent HTTP requests. | ||
| Future<String> getUserAgent() async { | ||
| return await _channel.invokeMethod('getUserAgent'); | ||
| } | ||
|
|
||
| /// Clears all caches used by the [WebView]. | ||
| /// | ||
| /// The following caches are cleared: | ||
|
|
||
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
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.
Please add a test that rebuilds a WebView with a different user agent.