Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 968e4b1

Browse files
committed
put webview with transparent background
fix flutter/flutter#29300
1 parent ad6fd0d commit 968e4b1

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebViewClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private void onPageStarted(WebView view, String url) {
7676
private void onPageFinished(WebView view, String url) {
7777
Map<String, Object> args = new HashMap<>();
7878
args.put("url", url);
79+
view.setBackgroundColor(0x00FF0000);
7980
methodChannel.invokeMethod("onPageFinished", args);
8081
}
8182

packages/webview_flutter/example/lib/main.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import 'package:webview_flutter/webview_flutter.dart';
1212
void main() => runApp(MaterialApp(home: WebViewExample()));
1313

1414
const String kNavigationExamplePage = '''
15-
<!DOCTYPE html><html>
15+
<!DOCTYPE html><html style="background-color:transparent;">
1616
<head><title>Navigation Delegate Example</title></head>
17-
<body>
17+
<body style="background-color:transparent;">
1818
<p>
19-
The navigation delegate is set to block navigation to the youtube website.
19+
The navigation delegate is set to block navigation to the youtube website, and as the webview background is transparent, you can see scaffold background.
2020
</p>
2121
<ul>
2222
<ul><a href="https://www.youtube.com/">https://www.youtube.com/</a></ul>
@@ -38,6 +38,7 @@ class _WebViewExampleState extends State<WebViewExample> {
3838
@override
3939
Widget build(BuildContext context) {
4040
return Scaffold(
41+
backgroundColor: Colors.green,
4142
appBar: AppBar(
4243
title: const Text('Flutter WebView example'),
4344
// This drop down menu demonstrates that Flutter widgets can be shown over the web view.

packages/webview_flutter/ios/Classes/FlutterWebView.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ - (instancetype)initWithFrame:(CGRect)frame
9292
inConfiguration:configuration];
9393

9494
_webView = [[FLTWKWebView alloc] initWithFrame:frame configuration:configuration];
95+
_webView.opaque = NO;
96+
_webView.backgroundColor = UIColor.clearColor;
97+
_webView.scrollView.backgroundColor = UIColor.clearColor;
98+
9599
_navigationDelegate = [[FLTWKNavigationDelegate alloc] initWithChannel:_channel];
96100
_webView.UIDelegate = self;
97101
_webView.navigationDelegate = _navigationDelegate;

0 commit comments

Comments
 (0)