Skip to content

Commit 777966d

Browse files
seungsoo47JSUYA
andauthored
[webview_flutter_tizen] Update webview_flutter to 4.10.0 (#809)
Co-authored-by: JunsuChoi <[email protected]>
1 parent 582c2d3 commit 777966d

File tree

11 files changed

+571
-46
lines changed

11 files changed

+571
-46
lines changed

packages/webview_flutter/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
## NEXT
1+
## 0.9.4
22

33
* Disable unnecessary web-engine initialization.
4+
* Update minimum Flutter and Dart version to 3.24 and 3.5.
5+
* Update the example main app.
6+
* Update webview_flutter to 4.10.0.
7+
* Update webview_flutter_platform_interface to 2.10.0.
8+
* Add enableZoom, setOnJavaScriptAlertDialog, setOnJavaScriptConfirmDialog, setOnJavaScriptTextInputDialog APIs.
49

510
## 0.9.3
611

packages/webview_flutter/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ This package is not an _endorsed_ implementation of `webview_flutter`. Therefore
2222

2323
```yaml
2424
dependencies:
25-
webview_flutter: ^4.4.2
26-
webview_flutter_tizen: ^0.9.3
25+
webview_flutter: ^4.10.0
26+
webview_flutter_tizen: ^0.9.4
2727
```
2828
2929
## Example

packages/webview_flutter/example/lib/main.dart

Lines changed: 242 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import 'dart:async';
88
import 'dart:convert';
99
import 'dart:io';
10-
import 'dart:typed_data';
1110

11+
import 'package:flutter/foundation.dart';
1212
import 'package:flutter/material.dart';
1313
import 'package:path_provider/path_provider.dart';
1414
import 'package:webview_flutter/webview_flutter.dart';
@@ -104,6 +104,39 @@ const String kLogExamplePage = '''
104104
</html>
105105
''';
106106

107+
const String kAlertTestPage = '''
108+
<!DOCTYPE html>
109+
<html>
110+
<head>
111+
<script type = "text/javascript">
112+
function showAlert(text) {
113+
console.log('showAlert(' + text + ')' )
114+
alert(text);
115+
}
116+
117+
function showConfirm(text) {
118+
var result = confirm(text);
119+
alert(result);
120+
}
121+
122+
function showPrompt(text, defaultText) {
123+
var inputString = prompt('Enter input', 'Default text');
124+
alert(inputString);
125+
}
126+
</script>
127+
</head>
128+
129+
<body>
130+
<p> Click the following button to see the effect </p>
131+
<form>
132+
<input type = "button" value = "Alert" onclick = "showAlert('Test Alert');" />
133+
<input type = "button" value = "Confirm" onclick = "showConfirm('Test Confirm');" />
134+
<input type = "button" value = "Prompt" onclick = "showPrompt('Test Prompt', 'Default Value');" />
135+
</form>
136+
</body>
137+
</html>
138+
''';
139+
107140
class WebViewExample extends StatefulWidget {
108141
const WebViewExample({super.key});
109142

@@ -112,13 +145,21 @@ class WebViewExample extends StatefulWidget {
112145
}
113146

114147
class _WebViewExampleState extends State<WebViewExample> {
115-
final WebViewController _controller = WebViewController();
148+
late final WebViewController _controller;
116149

117150
@override
118151
void initState() {
119152
super.initState();
120153

121-
_controller
154+
// #docregion platform_features
155+
late final PlatformWebViewControllerCreationParams params;
156+
params = const PlatformWebViewControllerCreationParams();
157+
158+
final WebViewController controller =
159+
WebViewController.fromPlatformCreationParams(params);
160+
// #enddocregion platform_features
161+
162+
controller
122163
..setJavaScriptMode(JavaScriptMode.unrestricted)
123164
..setBackgroundColor(const Color(0x00000000))
124165
..setNavigationDelegate(
@@ -149,9 +190,17 @@ Page resource error:
149190
debugPrint('allowing navigation to ${request.url}');
150191
return NavigationDecision.navigate;
151192
},
193+
// Note: onHttpError is not implemented by TizenWebview.
194+
// onHttpError: (HttpResponseError error) {
195+
// debugPrint('Error occurred on page: ${error.response?.statusCode}');
196+
// },
152197
onUrlChange: (UrlChange change) {
153198
debugPrint('url change to ${change.url}');
154199
},
200+
// Note: onHttpAuthRequest is not implemented by TizenWebview.
201+
// onHttpAuthRequest: (HttpAuthRequest request) {
202+
// openDialog(request);
203+
// },
155204
),
156205
)
157206
..addJavaScriptChannel(
@@ -163,6 +212,13 @@ Page resource error:
163212
},
164213
)
165214
..loadRequest(Uri.parse('https://flutter.dev'));
215+
216+
// setBackgroundColor is not currently supported on macOS.
217+
if (kIsWeb || !Platform.isMacOS) {
218+
controller.setBackgroundColor(const Color(0x80000000));
219+
}
220+
221+
_controller = controller;
166222
}
167223

168224
@override
@@ -195,6 +251,62 @@ Page resource error:
195251
child: const Icon(Icons.favorite),
196252
);
197253
}
254+
255+
Future<void> openDialog(HttpAuthRequest httpRequest) async {
256+
final TextEditingController usernameTextController =
257+
TextEditingController();
258+
final TextEditingController passwordTextController =
259+
TextEditingController();
260+
261+
return showDialog(
262+
context: context,
263+
barrierDismissible: false,
264+
builder: (BuildContext context) {
265+
return AlertDialog(
266+
title: Text('${httpRequest.host}: ${httpRequest.realm ?? '-'}'),
267+
content: SingleChildScrollView(
268+
child: Column(
269+
mainAxisSize: MainAxisSize.min,
270+
children: <Widget>[
271+
TextField(
272+
decoration: const InputDecoration(labelText: 'Username'),
273+
autofocus: true,
274+
controller: usernameTextController,
275+
),
276+
TextField(
277+
decoration: const InputDecoration(labelText: 'Password'),
278+
controller: passwordTextController,
279+
),
280+
],
281+
),
282+
),
283+
actions: <Widget>[
284+
// Explicitly cancel the request on iOS as the OS does not emit new
285+
// requests when a previous request is pending.
286+
TextButton(
287+
onPressed: () {
288+
httpRequest.onCancel();
289+
Navigator.of(context).pop();
290+
},
291+
child: const Text('Cancel'),
292+
),
293+
TextButton(
294+
onPressed: () {
295+
httpRequest.onProceed(
296+
WebViewCredential(
297+
user: usernameTextController.text,
298+
password: passwordTextController.text,
299+
),
300+
);
301+
Navigator.of(context).pop();
302+
},
303+
child: const Text('Authenticate'),
304+
),
305+
],
306+
);
307+
},
308+
);
309+
}
198310
}
199311

200312
enum MenuOptions {
@@ -212,6 +324,8 @@ enum MenuOptions {
212324
transparentBackground,
213325
setCookie,
214326
logExample,
327+
basicAuthentication,
328+
javaScriptAlert,
215329
}
216330

217331
class SampleMenu extends StatelessWidget {
@@ -257,6 +371,10 @@ class SampleMenu extends StatelessWidget {
257371
_onSetCookie();
258372
case MenuOptions.logExample:
259373
_onLogExample();
374+
case MenuOptions.basicAuthentication:
375+
_promptForUrl(context);
376+
case MenuOptions.javaScriptAlert:
377+
_onJavaScriptAlertExample(context);
260378
}
261379
},
262380
itemBuilder: (BuildContext context) => <PopupMenuItem<MenuOptions>>[
@@ -317,6 +435,14 @@ class SampleMenu extends StatelessWidget {
317435
value: MenuOptions.logExample,
318436
child: Text('Log example'),
319437
),
438+
const PopupMenuItem<MenuOptions>(
439+
value: MenuOptions.basicAuthentication,
440+
child: Text('Basic Authentication Example'),
441+
),
442+
const PopupMenuItem<MenuOptions>(
443+
value: MenuOptions.javaScriptAlert,
444+
child: Text('JavaScript Alert Example'),
445+
),
320446
],
321447
);
322448
}
@@ -437,6 +563,28 @@ class SampleMenu extends StatelessWidget {
437563
return webViewController.loadHtmlString(kTransparentBackgroundPage);
438564
}
439565

566+
Future<void> _onJavaScriptAlertExample(BuildContext context) {
567+
webViewController.setOnJavaScriptAlertDialog(
568+
(JavaScriptAlertDialogRequest request) async {
569+
await _showAlert(context, request.message);
570+
});
571+
572+
webViewController.setOnJavaScriptConfirmDialog(
573+
(JavaScriptConfirmDialogRequest request) async {
574+
final bool result = await _showConfirm(context, request.message);
575+
return result;
576+
});
577+
578+
webViewController.setOnJavaScriptTextInputDialog(
579+
(JavaScriptTextInputDialogRequest request) async {
580+
final String result =
581+
await _showTextInput(context, request.message, request.defaultText);
582+
return result;
583+
});
584+
585+
return webViewController.loadHtmlString(kAlertTestPage);
586+
}
587+
440588
Widget _getCookieList(String cookies) {
441589
if (cookies == '""') {
442590
return Container();
@@ -471,6 +619,97 @@ class SampleMenu extends StatelessWidget {
471619

472620
return webViewController.loadHtmlString(kLogExamplePage);
473621
}
622+
623+
Future<void> _promptForUrl(BuildContext context) {
624+
final TextEditingController urlTextController = TextEditingController();
625+
626+
return showDialog<String>(
627+
context: context,
628+
builder: (BuildContext context) {
629+
return AlertDialog(
630+
title: const Text('Input URL to visit'),
631+
content: TextField(
632+
decoration: const InputDecoration(labelText: 'URL'),
633+
autofocus: true,
634+
controller: urlTextController,
635+
),
636+
actions: <Widget>[
637+
TextButton(
638+
onPressed: () {
639+
if (urlTextController.text.isNotEmpty) {
640+
final Uri? uri = Uri.tryParse(urlTextController.text);
641+
if (uri != null && uri.scheme.isNotEmpty) {
642+
webViewController.loadRequest(uri);
643+
Navigator.pop(context);
644+
}
645+
}
646+
},
647+
child: const Text('Visit'),
648+
),
649+
],
650+
);
651+
},
652+
);
653+
}
654+
655+
Future<void> _showAlert(BuildContext context, String message) async {
656+
return showDialog<void>(
657+
context: context,
658+
builder: (BuildContext ctx) {
659+
return AlertDialog(
660+
content: Text(message),
661+
actions: <Widget>[
662+
TextButton(
663+
onPressed: () {
664+
Navigator.of(ctx).pop();
665+
},
666+
child: const Text('OK'))
667+
],
668+
);
669+
});
670+
}
671+
672+
Future<bool> _showConfirm(BuildContext context, String message) async {
673+
return await showDialog<bool>(
674+
context: context,
675+
builder: (BuildContext ctx) {
676+
return AlertDialog(
677+
content: Text(message),
678+
actions: <Widget>[
679+
TextButton(
680+
onPressed: () {
681+
Navigator.of(ctx).pop(false);
682+
},
683+
child: const Text('Cancel')),
684+
TextButton(
685+
onPressed: () {
686+
Navigator.of(ctx).pop(true);
687+
},
688+
child: const Text('OK')),
689+
],
690+
);
691+
}) ??
692+
false;
693+
}
694+
695+
Future<String> _showTextInput(
696+
BuildContext context, String message, String? defaultText) async {
697+
return await showDialog<String>(
698+
context: context,
699+
builder: (BuildContext ctx) {
700+
return AlertDialog(
701+
content: Text(message),
702+
actions: <Widget>[
703+
TextButton(
704+
onPressed: () {
705+
Navigator.of(ctx).pop('Text test');
706+
},
707+
child: const Text('Enter')),
708+
],
709+
);
710+
}) ??
711+
'';
712+
}
474713
}
475714

476715
class NavigationControls extends StatelessWidget {

packages/webview_flutter/example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ description: Demonstrates how to use the webview_flutter_tizen plugin.
33
publish_to: "none"
44

55
environment:
6-
sdk: ">=3.1.0 <4.0.0"
7-
flutter: ">=3.13.0"
6+
sdk: ^3.5.0
7+
flutter: ">=3.24.0"
88

99
dependencies:
1010
flutter:
1111
sdk: flutter
1212
path_provider: ^2.0.7
1313
path_provider_tizen:
1414
path: ../../path_provider/
15-
webview_flutter: ^4.4.2
15+
webview_flutter: ^4.10.0
1616
webview_flutter_tizen:
1717
path: ../
1818

0 commit comments

Comments
 (0)