|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'package:flutter/foundation.dart'; |
| 6 | +import 'package:flutter/g
8000
estures.dart'; |
5 | 7 | import 'package:flutter/widgets.dart';
|
6 | 8 | import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
| 9 | +import 'package:webview_flutter_platform_interface/v4/src/platform_webview_controller.dart'; |
7 | 10 |
|
8 | 11 | import 'webview_platform.dart';
|
9 | 12 |
|
@@ -33,5 +36,75 @@ abstract class PlatformWebViewWidget extends PlatformInterface {
|
33 | 36 | /// Builds a new WebView.
|
34 | 37 | ///
|
35 | 38 | /// Returns a Widget tree that embeds the created web view.
|
36 |
| - Widget build(BuildContext context); |
| 39 | + Widget build(BuildParams params); |
| 40 | +} |
| 41 | + |
| 42 | +/// Describes the parameters necessary for displaying the platform WebView. |
| 43 | +/// |
| 44 | +/// Platform specific implementations can add additional fields by extending |
| 45 | +/// this class. |
| 46 | +/// |
| 47 | +/// {@tool sample} |
| 48 | +/// This example demonstrates how to extend the [BuildParams] to provide |
| 49 | +/// additional platform specific parameters. |
| 50 | +/// |
| 51 | +/// When extending [BuildParams], additional parameters should always accept |
| 52 | +/// `null` or have a default value to prevent breaking changes. |
| 53 | +/// |
| 54 | +/// ```dart |
| 55 | +/// @immutable |
| 56 | +/// class WebKitBuildParams extends BuildParams { |
| 57 | +/// WebKitBuildParams( |
| 58 | +/// super.context, { |
| 59 | +/// required super.controller, |
| 60 | +/// super.layoutDirection, |
| 61 | +/// super.gestureRecognizers, |
| 62 | +/// this.platformSpecificFieldExample, |
| 63 | +/// }); |
| 64 | +/// |
| 65 | +/// WebKitBuildParams.fromBuildParams( |
| 66 | +/// BuildParams params, { |
| 67 | +/// Object? platformSpecificFieldExample, |
| 68 | +/// }) : this( |
| 69 | +/// params.context, |
| 70 | +/// controller: params.controller, |
| 71 | +/// layoutDirection: params.layoutDirection, |
| 72 | +/// gestu
8000
reRecognizers: params.gestureRecognizers, |
| 73 | +/// platformSpecificFieldExample: platformSpecificFieldExample, |
| 74 | +/// ); |
| 75 | +/// |
| 76 | +/// final Object? platformSpecificFieldExample; |
| 77 | +/// } |
| 78 | +/// ``` |
| 79 | +/// {@end-tool} |
| 80 | +@immutable |
| 81 | +class BuildParams { |
| 82 | + /// Constructs a [BuildParams]. |
| 83 | + const BuildParams( |
| 84 | + this.context, { |
| 85 | + required this.controller, |
| 86 | + this.layoutDirection = TextDirection.ltr, |
| 87 | + this.gestureRecognizers = const <Factory<OneSequenceGestureRecognizer>>{}, |
| 88 | + }); |
| 89 | + |
| 90 | + /// Describes the part of the user interface represented by the returned |
| 91 | + /// widget. |
| 92 | + final BuildContext context; |
| 93 | + |
| 94 | + /// Controls the embedded WebView for the current platform. |
| 95 | + final PlatformWebViewController controller; |
| 96 | + |
| 97 | + /// The layout direction to use for the embedded WebView. |
| 98 | + final TextDirection layoutDirection; |
| 99 | + |
| 100 | + /// Specifies which gestures should be consumed by the web view. |
| 101 | + /// |
| 102 | + /// It is possible for other gesture recognizers to be competing with the web |
| 103 | + /// view on pointer events, e.g if the web view is inside a [ListView] the |
| 104 | + /// [ListView] will want to handle vertical drags. The web view will claim |
| 105 | + /// gestures that are recognized by any of the recognizers on this list. |
| 106 | + /// |
| 107 | + /// When this is empty, the web view will only handle pointer events for |
| 108 | + /// gestures that were not claimed by any other gesture recognizer. |
| 109 | + final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers; |
37 | 110 | }
|
0 commit comments