Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 3.27.0

* Adds `WebKitWebViewWidgetCreationParams.gestureBlockingPolicy` for choosing the gesture
blocking policy of the iOS platform view. Setting it to `doNotBlockGesture` works around web
views becoming unresponsive to touches. See
https://github.com/flutter/flutter/issues/175099.
* Updates minimum supported SDK version to Flutter 3.47/Dart 3.13.

## 3.26.0

* Adds new method for accessing a native `WKWebView` from a `FlutterPluginRegistrar`.
Expand Down
20 changes: 20 additions & 0 deletions packages/webview_flutter/webview_flutter_wkwebview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ so you do not need to add it to your `pubspec.yaml`.
However, if you `import` this package to use any of its APIs directly, you
should add it to your `pubspec.yaml` as usual.

### Gesture blocking policy

By default the plugin lets the engine block the web view's gesture recognizers through Flutter's
gesture arena. If a web view stops responding to touches after the first interaction, deriving the
blocking decision from hit testing instead can work around it:

<?code-excerpt "example/lib/readme_excerpts.dart (gesture_blocking_policy_example)"?>
```dart
final params = WebKitWebViewWidgetCreationParams(
controller: controller,
gestureBlockingPolicy: UiKitViewGestureBlockingPolicy.doNotBlockGesture,
);
```

Pass those parameters to `WebViewWidget.fromPlatformCreationParams`, using the `platform` of your
`WebViewController` as the `controller`.

This is a workaround for bugs in the underlying `WKWebView`, and it may cause the web view to
recognize a gesture that should have been blocked, so only opt in when a web view is affected.

### External Native API

The plugin also provides a native API accessible by the native code of iOS applications or packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -181,9 +180,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -208,18 +206,17 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);

await pageLoads.stream.firstWhere((String url) => url == headersUrl);

final content =
await controller.runJavaScriptReturningResult('document.documentElement.innerText')
as String;
final content = await controller.runJavaScriptReturningResult(
'document.documentElement.innerText',
) as String;
expect(content.contains('flutter_test_header'), isTrue);
});

Expand All @@ -236,9 +233,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down Expand Up @@ -270,9 +266,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down Expand Up @@ -306,9 +301,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down Expand Up @@ -353,9 +347,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -372,9 +365,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down Expand Up @@ -682,9 +674,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down Expand Up @@ -1197,9 +1188,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
WebKitWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(WebKitWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down Expand Up @@ -1230,9 +1220,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
WebKitWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(WebKitWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -1250,9 +1239,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -1275,9 +1263,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -1300,9 +1287,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down Expand Up @@ -1338,9 +1324,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -1366,9 +1351,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand All @@ -1392,9 +1376,8 @@ Future<void> main() async {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: controller),
).build(context);
return PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: controller))
.build(context);
},
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ Page resource error:
JavaScriptChannelParams(
name: 'Toaster',
onMessageReceived: (JavaScriptMessage message) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message.message)));
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(message.message)));
},
),
)
Expand Down Expand Up @@ -245,9 +244,8 @@ Page resource error:
SampleMenu(webViewController: _controller, cookieManager: widget.cookieManager),
],
),
body: PlatformWebViewWidget(
PlatformWebViewWidgetCreationParams(controller: _controller),
).build(context),
body: PlatformWebViewWidget(PlatformWebViewWidgetCreationParams(controller: _controller))
.build(context),
floatingActionButton: favoriteButton(),
);
}
Expand Down Expand Up @@ -495,9 +493,8 @@ class SampleMenu extends StatelessWidget {
'caches.open("test_caches_entry"); localStorage["test_localStorage"] = "dummy_entry";',
);
if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Added a test entry to cache.')));
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Added a test entry to cache.')));
}
}

Expand Down Expand Up @@ -739,9 +736,8 @@ class NavigationControls extends StatelessWidget {
await webViewController.goBack();
} else {
if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('No back history item')));
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('No back history item')));
}
}
},
Expand All @@ -753,9 +749,8 @@ class NavigationControls extends StatelessWidget {
await webViewController.goForward();
} else {
if (context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('No forward history item')));
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('No forward history item')));
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/services.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

/// Example function for README demonstration of the gesture blocking policy.
PlatformWebViewWidgetCreationParams createParamsWithoutGestureBlocking(
PlatformWebViewController controller,
) {
// #docregion gesture_blocking_policy_example
final params = WebKitWebViewWidgetCreationParams(
controller: controller,
gestureBlockingPolicy: UiKitViewGestureBlockingPolicy.doNotBlockGesture,
);
// #enddocregion gesture_blocking_policy_example
return params;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ description: Demonstrates how to use the webview_flutter_wkwebview plugin.
publish_to: none

environment:
sdk: ^3.10.0
flutter: ">=3.38.0"
sdk: ^3.13.0
flutter: ">=3.47.0"

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';

import 'common/web_kit.g.dart';

/// An implementation of [PlatformSslAuthError] with the WebKit api.
Expand Down
Loading