diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
new file mode 100644
index 00000000..fbbebaa1
--- /dev/null
+++ b/.idea/libraries/Dart_Packages.xml
@@ -0,0 +1,738 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml
index 65bb3679..31799730 100755
--- a/.idea/libraries/Flutter_Plugins.xml
+++ b/.idea/libraries/Flutter_Plugins.xml
@@ -1,8 +1,6 @@
-
-
-
+
diff --git a/example/integration_test/webview_flutter_test.dart b/example/integration_test/webview_flutter_test.dart
index ebda3bc1..5a425ce8 100644
--- a/example/integration_test/webview_flutter_test.dart
+++ b/example/integration_test/webview_flutter_test.dart
@@ -22,10 +22,7 @@ class Foo {
Foo({this.bar, this.baz});
Map toJson() {
- return {
- 'bar': this.bar,
- 'baz': this.baz
- };
+ return {'bar': this.bar, 'baz': this.baz};
}
}
@@ -33,8 +30,9 @@ class MyInAppBrowser extends InAppBrowser {
final Completer browserCreated = Completer();
final Completer firstPageLoaded = Completer();
- MyInAppBrowser({int? windowId, UnmodifiableListView? initialUserScripts}) :
- super(windowId: windowId, initialUserScripts: initialUserScripts);
+ MyInAppBrowser(
+ {int? windowId, UnmodifiableListView? initialUserScripts})
+ : super(windowId: windowId, initialUserScripts: initialUserScripts);
@override
Future onBrowserCreated() async {
@@ -52,7 +50,6 @@ class MyInAppBrowser extends InAppBrowser {
}
class MyChromeSafariBrowser extends ChromeSafariBrowser {
-
final Completer browserCreated = Completer();
final Completer firstPageLoaded = Completer();
final Completer browserClosed = Completer();
@@ -88,16 +85,16 @@ void main() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('https://flutter.dev/')
- ),
+ initialUrlRequest:
+ URLRequest(url: Uri.parse('https://flutter.dev/')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
final String? currentUrl = (await controller.getUrl())?.toString();
expect(currentUrl, 'https://flutter.dev/');
});
@@ -111,14 +108,10 @@ void main() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('https://flutter.dev/')
- ),
+ initialUrlRequest:
+ URLRequest(url: Uri.parse('https://flutter.dev/')),
initialOptions: InAppWebViewGroupOptions(
- crossPlatform: InAppWebViewOptions(
- javaScriptEnabled: false
- )
- ),
+ crossPlatform: InAppWebViewOptions(javaScriptEnabled: false)),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@@ -128,18 +121,17 @@ void main() {
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
await pageLoaded.future;
InAppWebViewGroupOptions? options = await controller.getOptions();
expect(options, isNotNull);
expect(options!.crossPlatform.javaScriptEnabled, false);
- await controller.setOptions(options: InAppWebViewGroupOptions(
- crossPlatform: InAppWebViewOptions(
- javaScriptEnabled: true
- )
- ));
+ await controller.setOptions(
+ options: InAppWebViewGroupOptions(
+ crossPlatform: InAppWebViewOptions(javaScriptEnabled: true)));
options = await controller.getOptions();
expect(options, isNotNull);
@@ -148,7 +140,8 @@ void main() {
group('javascript code evaluation', () {
testWidgets('evaluateJavascript', (WidgetTester tester) async {
- final Completer controllerCompleter = Completer();
+ final Completer controllerCompleter =
+ Completer();
final Completer pageLoaded = Completer();
await tester.pumpWidget(
@@ -156,9 +149,7 @@ void main() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('about:blank')
- ),
+ initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@@ -168,7 +159,8 @@ void main() {
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
await pageLoaded.future;
var result = await controller.evaluateJavascript(source: """
@@ -178,11 +170,14 @@ void main() {
expect(result[0], 1);
expect(result[1], true);
expect(listEquals(result[2] as List?, ["bar", 5]), true);
- expect(mapEquals(result[3]?.cast(), {"foo": "baz"}), true);
+ expect(
+ mapEquals(result[3]?.cast(), {"foo": "baz"}), true);
});
- testWidgets('evaluateJavascript with content world', (WidgetTester tester) async {
- final Completer controllerCompleter = Completer();
+ testWidgets('evaluateJavascript with content world',
+ (WidgetTester tester) async {
+ final Completer controllerCompleter =
+ Completer();
final Completer pageLoaded = Completer();
await tester.pumpWidget(
@@ -190,9 +185,7 @@ void main() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('about:blank')
- ),
+ initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@@ -202,19 +195,25 @@ void main() {
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
await pageLoaded.future;
- await controller.evaluateJavascript(source: "var foo = 49;", contentWorld: ContentWorld.world(name: "custom-world"));
+ await controller.evaluateJavascript(
+ source: "var foo = 49;",
+ contentWorld: ContentWorld.world(name: "custom-world"));
var result = await controller.evaluateJavascript(source: "foo");
expect(result, isNull);
- result = await controller.evaluateJavascript(source: "foo", contentWorld: ContentWorld.world(name: "custom-world"));
+ result = await controller.evaluateJavascript(
+ source: "foo",
+ contentWorld: ContentWorld.world(name: "custom-world"));
expect(result, 49);
});
testWidgets('callAsyncJavaScript', (WidgetTester tester) async {
- final Completer controllerCompleter = Completer();
+ final Completer controllerCompleter =
+ Completer();
final Completer pageLoaded = Completer();
await tester.pumpWidget(
@@ -222,9 +221,7 @@ void main() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('about:blank')
- ),
+ initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@@ -234,7 +231,8 @@ void main() {
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
await pageLoaded.future;
final String functionBody = """
@@ -251,19 +249,25 @@ void main() {
return p;
""";
- var result = await controller.callAsyncJavaScript(functionBody: functionBody, arguments: {'x': 49, 'y': 'error message'});
+ var result = await controller.callAsyncJavaScript(
+ functionBody: functionBody,
+ arguments: {'x': 49, 'y': 'error message'});
expect(result, isNotNull);
expect(result!.error, isNull);
expect(result.value, 49);
- result = await controller.callAsyncJavaScript(functionBody: functionBody, arguments: {'x': -49, 'y': 'error message'});
+ result = await controller.callAsyncJavaScript(
+ functionBody: functionBody,
+ arguments: {'x': -49, 'y': 'error message'});
expect(result, isNotNull);
expect(result!.value, isNull);
expect(result.error, 'error message');
});
- testWidgets('callAsyncJavaScript with content world', (WidgetTester tester) async {
- final Completer controllerCompleter = Completer();
+ testWidgets('callAsyncJavaScript with content world',
+ (WidgetTester tester) async {
+ final Completer controllerCompleter =
+ Completer();
final Completer pageLoaded = Completer();
await tester.pumpWidget(
@@ -271,9 +275,7 @@ void main() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('about:blank')
- ),
+ initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@@ -283,16 +285,22 @@ void main() {
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
await pageLoaded.future;
- await controller.callAsyncJavaScript(functionBody: "window.foo = 49;", contentWorld: ContentWorld.world(name: "custom-world"));
- var result = await controller.callAsyncJavaScript(functionBody: "return window.foo;");
+ await controller.callAsyncJavaScript(
+ functionBody: "window.foo = 49;",
+ contentWorld: ContentWorld.world(name: "custom-world"));
+ var result = await controller.callAsyncJavaScript(
+ functionBody: "return window.foo;");
expect(result, isNotNull);
expect(result!.error, isNull);
expect(result.value, isNull);
- result = await controller.callAsyncJavaScript(functionBody: "return window.foo;", contentWorld: ContentWorld.world(name: "custom-world"));
+ result = await controller.callAsyncJavaScript(
+ functionBody: "return window.foo;",
+ contentWorld: ContentWorld.world(name: "custom-world"));
expect(result, isNotNull);
expect(result!.error, isNull);
expect(result.value, 49);
@@ -301,16 +309,16 @@ void main() {
testWidgets('loadUrl', (WidgetTester tester) async {
final Completer controllerCompleter = Completer();
- final StreamController pageLoads = StreamController.broadcast();
+ final StreamController pageLoads =
+ StreamController.broadcast();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('https://flutter.dev/')
- ),
+ initialUrlRequest:
+ URLRequest(url: Uri.parse('https://flutter.dev/')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@@ -320,11 +328,13 @@ void main() {
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
var url = await pageLoads.stream.first;
expect(url, 'https://flutter.dev/');
- await controller.loadUrl(urlRequest: URLRequest(url: Uri.parse('https://www.google.com/')));
+ await controller.loadUrl(
+ urlRequest: URLRequest(url: Uri.parse('https://www.google.com/')));
url = await pageLoads.stream.first;
expect(url, 'https://www.google.com/');
@@ -332,26 +342,23 @@ void main() {
});
testWidgets('loadUrl with headers', (WidgetTester tester) async {
- final Completer controllerCompleter =
- Completer();
- final StreamController pageStarts = StreamController.broadcast();
- final StreamController pageLoads = StreamController.broadcast();
+ final Completer controllerCompleter = Completer();
+ final StreamController pageStarts =
+ StreamController.broadcast();
+ final StreamController pageLoads =
+ StreamController.broadcast();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('https://flutter.dev/')
- ),
+ initialUrlRequest:
+ URLRequest(url: Uri.parse('https://flutter.dev/')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialOptions: InAppWebViewGroupOptions(
- crossPlatform: InAppWebViewOptions(
- javaScriptEnabled: true
- )
- ),
+ crossPlatform: InAppWebViewOptions(javaScriptEnabled: true)),
onLoadStart: (controller, url) {
pageStarts.add(url!.toString());
},
@@ -361,22 +368,23 @@ void main() {
),
),
);
- final InAppWebViewController controller = await controllerCompleter.future;
+ final InAppWebViewController controller =
+ await controllerCompleter.future;
final Map headers = {
'test_header': 'flutter_test_header'
};
- await controller.loadUrl(urlRequest: URLRequest(
- url: Uri.parse('https://flutter-header-echo.herokuapp.com/'),
- headers: headers
- ));
+ await controller.loadUrl(
+ urlRequest: URLRequest(
+ url: Uri.parse('https://flutter-header-echo.herokuapp.com/'),
+ headers: headers));
final String? currentUrl = (await controller.getUrl())?.toString();
expect(currentUrl, 'https://flutter-header-echo.herokuapp.com/');
await pageStarts.stream.firstWhere((String url) => url == currentUrl);
await pageLoads.stream.firstWhere((String url) => url == currentUrl);
- final String content = await controller
- .evaluateJavascript(source: 'document.documentElement.innerText');
+ final String content = await controller.evaluateJavascript(
+ source: 'document.documentElement.innerText');
expect(content.contains('flutter_test_header'), isTrue);
pageStarts.close();
@@ -392,12 +400,12 @@ void main() {
appSupportDir = (await getApplicationSupportDirectory())!;
final Directory htmlFolder = Directory('${appSupportDir.path}/html/');
- if(!await htmlFolder.exists()){
+ if (!await htmlFolder.exists()) {
await htmlFolder.create(recursive: true);
}
final Directory jsFolder = Directory('${appSupportDir.path}/js/');
- if(!await jsFolder.exists()){
+ if (!await jsFolder.exists()) {
await jsFolder.create(recursive: true);
}
@@ -421,16 +429,17 @@ void main() {
fileJs.writeAsStringSync(js);
});
- testWidgets('initialUrl with file:// scheme and allowingReadAccessTo', (WidgetTester tester) async {
- final Completer consoleMessageShouldNotComplete = Completer();
+ testWidgets('initialUrl with file:// scheme and allowingReadAccessTo',
+ (WidgetTester tester) async {
+ final Completer consoleMessageShouldNotComplete =
+ Completer();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('file://${fileHtml.path}')
- ),
+ initialUrlRequest:
+ URLRequest(url: Uri.parse('file://${fileHtml.path}')),
onConsoleMessage: (controller, consoleMessage) {
consoleMessageShouldNotComplete.complete(consoleMessage);
},
@@ -441,42 +450,45 @@ void main() {
.timeout(const Duration(seconds: 2), onTimeout: () => null);
expect(result, null);
- final Completer consoleMessageCompleter = Completer();
+ final Completer consoleMessageCompleter =
+ Completer();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialUrlRequest: URLRequest(
- url: Uri.parse('file://${fileHtml.path}')
- ),
+ initialUrlRequest:
+ URLRequest(url: Uri.parse('file://${fileHtml.path}')),
initialOptions: InAppWebViewGroupOptions(
ios: IOSInAppWebViewOptions(
- allowingReadAccessTo: Uri.parse('file://${appSupportDir.path}/')
- )
- ),
+ allowingReadAccessTo:
+ Uri.parse('file://${appSupportDir.path}/'))),
onConsoleMessage: (controller, consoleMessage) {
consoleMessageCompleter.complete(consoleMessage);
},
),
),
);
- final ConsoleMessage consoleMessage = await consoleMessageCompleter.future;
+ final ConsoleMessage consoleMessage =
+ await consoleMessageCompleter.future;
expect(consoleMessage.messageLevel, ConsoleMessageLevel.LOG);
expect(consoleMessage.message, 'message');
}, skip: !Platform.isIOS);
- testWidgets('loadUrl with file:// scheme and iosAllowingReadAccessTo argument', (WidgetTester tester) async {
- final Completer consoleMessageShouldNotComplete = Completer();
+ testWidgets(
+ 'loadUrl with file:// scheme and iosAllowingReadAccessTo argument',
+ (WidgetTester tester) async {
+ final Completer consoleMessageShouldNotComplete =
+ Completer();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
onWebViewCreated: (controller) {
- controller.loadUrl(urlRequest: URLRequest(
- url: Uri.parse('file://${fileHtml.path}')
- ));
+ controller.loadUrl(
+ urlRequest:
+ URLRequest(url: Uri.parse('file://${fileHtml.path}')));
},
onConsoleMessage: (controller, consoleMessage) {
consoleMessageShouldNotComplete.complete(consoleMessage);
@@ -488,16 +500,19 @@ void main() {
.timeout(const Duration(seconds: 2), onTimeout: () => null);
expect(result, null);
- final Completer consoleMessageCompleter = Completer();
+ final Completer consoleMessageCompleter =
+ Completer();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
onWebViewCreated: (controller) {
- controller.loadUrl(urlRequest: URLRequest(
- url: Uri.parse('file://${fileHtml.path}')),
- iosAllowingReadAccessTo: Uri.parse('file://${appSupportDir.path}/'));
+ controller.loadUrl(
+ urlRequest:
+ URLRequest(url: Uri.parse('file://${fileHtml.path}')),
+ iosAllowingReadAccessTo:
+ Uri.parse('file://${appSupportDir.path}/'));
},
onConsoleMessage: (controller, consoleMessage) {
consoleMessageCompleter.complete(consoleMessage);
@@ -505,16 +520,15 @@ void main() {
),
),
);
- final ConsoleMessage consoleMessage = await consoleMessageCompleter.future;
+ final ConsoleMessage consoleMessage =
+ await consoleMessageCompleter.future;
expect(consoleMessage.messageLevel, ConsoleMessageLevel.LOG);
expect(consoleMessage.message, 'message');
}, skip: !Platform.isIOS);
}, skip: !Platform.isIOS);
testWidgets('JavaScript Handler', (WidgetTester tester) async {
-
- final Completer controllerCompleter =
- Completer();
+ final Completer controllerCompleter = Completer();
final Completer pageStarted = Completer();
final Completer pageLoaded = Completer();
final Completer handlerFoo = Completer();
@@ -525,29 +539,33 @@ void main() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
- initialFile: "test_assets/in_app_webview_javascript_handler_test.html",
+ initialFile:
+ "test_assets/in_app_webview_javascript_handler_test.html",
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
- controller.addJavaScriptHandler(handlerName:'handlerFoo', callback: (args) {
- handlerFoo.complete();
- return Foo(bar: 'bar_value', baz: 'baz_value');
- });
+ controller.addJavaScriptHandler(
+ handlerName: 'handlerFoo',
+ callback: (args) {
+ handlerFoo.complete();
+ return Foo(bar: 'bar_value', baz: 'baz_value');
+ });
- controller.addJavaScriptHandler(handlerName: 'handlerFooWithArgs', callback: (args) {
- messagesReceived.add(args[0] as int);
- messagesReceived.add(args[1] as bool);
- messagesReceived.add(args[2] as List?);
- messagesReceived.add(args[3]?.cast() as Map?);
- messagesReceived.add(args[4]?.cast() as Map?);
- handlerFooWithArgs.complete();
- });
+ controller.addJavaScriptHandler(
+ handlerName: 'handlerFooWithArgs',
+ callback: (args) {
+ messagesReceived.add(args[0] as int);
+ messagesReceived.add(args[1] as bool);
+ messagesReceived.add(args[2] as List?);
+ messagesReceived.add(args[3]?.cast()
+ as Map?);
+ messagesReceived.add(args[4]?.cast()
+ as Map?);
+ handlerFooWithArgs.complete();
+ });
},
initialOptions: InAppWebViewGroupOptions(
- crossPlatform: InAppWebViewOptions(
- javaScriptEnabled: true
- )
- ),
+ crossPlatform: InAppWebViewOptions(javaScriptEnabled: true)),
onLoadStart: (controller, url) {
pageStarted.complete();
},
@@ -565,9 +583,13 @@ void main() {
expect(messagesReceived[0], 1);
expect(messagesReceived[1], true);
- expect(listEquals(messagesReceived[2] as List?, ["bar", 5]), true);
+ expect(
+ listEquals(messagesReceived[2] as List?, ["bar", 5]), true);
expect(mapEquals(messagesReceived[3], {"foo": "baz"}), true);
- expect(mapEquals(messagesReceived[4], {"bar":"bar_value","baz":"baz_value"}), true);
+ expect(
+ mapEquals(
+ messagesReceived[4], {"bar": "bar_value", "baz": "baz_value"}),
+ true);
});
testWidgets('resize webview', (WidgetTester tester) async {
@@ -588,25 +610,26 @@ void main() {