Skip to content

Commit

Permalink
Add javascript alert example on android project
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharp83 committed Jul 27, 2023
1 parent 831a80a commit 5875cf9
Showing 1 changed file with 31 additions and 0 deletions.
Expand Up @@ -73,6 +73,25 @@ const String kTransparentBackgroundPage = '''
</html>
''';

const String kAlertTestPage = '''
<html>
<head>
<script type = "text/javascript">
function showAlert() {
alert ("This is an alert dialog box");
}
</script>
</head>
<body>
<p> Click the following button to see the effect </p>
<form>
<input type = "button" value = "Click me" onclick = "showAlert();" />
</form>
</body>
</html>
''';

class WebViewExample extends StatefulWidget {
const WebViewExample({super.key, this.cookieManager});

Expand Down Expand Up @@ -201,6 +220,7 @@ enum MenuOptions {
loadHtmlString,
transparentBackground,
setCookie,
javaScriptAlert
}

class SampleMenu extends StatelessWidget {
Expand Down Expand Up @@ -261,6 +281,9 @@ class SampleMenu extends StatelessWidget {
case MenuOptions.setCookie:
_onSetCookie();
break;
case MenuOptions.javaScriptAlert:
_onJavaScriptAlertExample(context);
break;
}
},
itemBuilder: (BuildContext context) => <PopupMenuItem<MenuOptions>>[
Expand Down Expand Up @@ -317,6 +340,10 @@ class SampleMenu extends StatelessWidget {
value: MenuOptions.transparentBackground,
child: Text('Transparent background example'),
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.javaScriptAlert,
child: Text('JavaScript Alert Example'),
),
],
);
}
Expand Down Expand Up @@ -441,6 +468,10 @@ class SampleMenu extends StatelessWidget {
return webViewController.loadHtmlString(kTransparentBackgroundPage);
}

Future<void> _onJavaScriptAlertExample(BuildContext context) {
return webViewController.loadHtmlString(kAlertTestPage);
}

Widget _getCookieList(String cookies) {
if (cookies == '""') {
return Container();
Expand Down

0 comments on commit 5875cf9

Please sign in to comment.