@@ -48,6 +48,27 @@ const String kLocalExamplePage = '''
4848</html>
4949''' ;
5050
51+ const String kTransparentBackgroundPage = '''
52+ <!DOCTYPE html>
53+ <html>
54+ <head>
55+ <title>Transparent background test</title>
56+ </head>
57+ <style type="text/css">
58+ body { background: transparent; margin: 0; padding: 0; }
59+ #container { position: relative; margin: 0; padding: 0; width: 100vw; height: 100vh; }
60+ #shape { background: red; width: 200px; height: 200px; margin: 0; padding: 0; position: absolute; top: calc(50% - 100px); left: calc(50% - 100px); }
61+ p { text-align: center; }
62+ </style>
63+ <body>
64+ <div id="container">
65+ <p>Transparent background test</p>
66+ <div id="shape"></div>
67+ </div>
68+ </body>
69+ </html>
70+ ''' ;
71+
5172class WebViewExample extends StatefulWidget {
5273 @override
5374 _WebViewExampleState createState () => _WebViewExampleState ();
@@ -68,6 +89,7 @@ class _WebViewExampleState extends State<WebViewExample> {
6889 @override
6990 Widget build (BuildContext context) {
7091 return Scaffold (
92+ backgroundColor: Colors .green,
7193 appBar: AppBar (
7294 title: const Text ('Flutter WebView example' ),
7395 // This drop down menu demonstrates that Flutter widgets can be shown over the web view.
@@ -106,6 +128,7 @@ class _WebViewExampleState extends State<WebViewExample> {
106128 print ('Page finished loading: $url ' );
107129 },
108130 gestureNavigationEnabled: true ,
131+ backgroundColor: const Color (0x00000000 ),
109132 );
110133 }),
111134 floatingActionButton: favoriteButton (),
@@ -155,6 +178,7 @@ enum MenuOptions {
155178 navigationDelegate,
156179 loadLocalFile,
157180 loadHtmlString,
181+ transparentBackground,
158182}
159183
160184class SampleMenu extends StatelessWidget {
@@ -170,6 +194,7 @@ class SampleMenu extends StatelessWidget {
170194 builder:
171195 (BuildContext context, AsyncSnapshot <WebViewController > controller) {
172196 return PopupMenuButton <MenuOptions >(
197+ key: const ValueKey <String >('ShowPopupMenu' ),
173198 onSelected: (MenuOptions value) {
174199 switch (value) {
175200 case MenuOptions .showUserAgent:
@@ -199,6 +224,9 @@ class SampleMenu extends StatelessWidget {
199224 case MenuOptions .loadHtmlString:
200225 _onLoadHtmlStringExample (controller.data! , context);
201226 break ;
227+ case MenuOptions .transparentBackground:
228+ _onTransparentBackground (controller.data! , context);
229+ break ;
202230 }
203231 },
204232 itemBuilder: (BuildContext context) => < PopupMenuItem <MenuOptions >> [
@@ -239,6 +267,11 @@ class SampleMenu extends StatelessWidget {
239267 value: MenuOptions .loadLocalFile,
240268 child: Text ('Load local file' ),
241269 ),
270+ const PopupMenuItem <MenuOptions >(
271+ key: ValueKey <String >('ShowTransparentBackgroundExample' ),
272+ value: MenuOptions .transparentBackground,
273+ child: Text ('Transparent background example' ),
274+ ),
242275 ],
243276 );
244277 },
@@ -327,6 +360,11 @@ class SampleMenu extends StatelessWidget {
327360 await controller.loadHtmlString (kLocalExamplePage);
328361 }
329362
363+ Future <void > _onTransparentBackground (
364+ WebViewController controller, BuildContext context) async {
365+ await controller.loadHtmlString (kTransparentBackgroundPage);
366+ }
367+
330368 Widget _getCookieList (String cookies) {
331369 if (cookies == null || cookies == '""' ) {
332370 return Container ();
0 commit comments