Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[webview_flutter_web] Explain web registration (#4668)
Browse files Browse the repository at this point in the history
The README instructions currently use the standard description of using
an unendorsed implementation of a federated package, which assumes
auto-registration. Because `webview_flutter_web` doesn't use
autoregistration due to the current structural issues in
`webview_flutter`'s federation, those instructions aren't complete.

This adds an explanation of registering the implementation, including an
example of using conditional imports for multi-platform projects.
  • Loading branch information
stuartmorgan authored Jan 25, 2022
1 parent 9861088 commit c0b4032
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/webview_flutter/webview_flutter_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 0.1.0
## 0.1.0+1

* Adds an explanation of registering the implementation in the README.

* First web implementation for webview_flutter
## 0.1.0

* First web implementation for webview_flutter
64 changes: 61 additions & 3 deletions packages/webview_flutter/webview_flutter_web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,65 @@ Nothing else is currently supported.

## Usage

### Depend on the package
This package is not an endorsed implementation of the `webview_flutter` plugin
yet, so it currently requires extra setup to use:

This package is not an endorsed implementation of the `webview_flutter` plugin yet, so you'll need to
[add it explicitly](https://pub.dev/packages/webview_flutter_web/install).
* [Add this package](https://pub.dev/packages/webview_flutter_web/install)
as an explicit dependency of your project, in addition to depending on
`webview_flutter`.
* Register `WebWebViewPlatform` as the `WebView.platform` before creating a
`WebView`. See below for examples.

Once those steps below are complete, the APIs from `webview_flutter` listed
above can be used as normal on web.

### Registering the implementation

Before creating a `WebView` (for instance, at the start of `main`), you will
need to register the web implementation.

#### Web-only project example

```dart
...
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_web/webview_flutter_web.dart';
main() {
WebView.platform = WebWebViewPlatform();
...
```

#### Multi-platform project example

If your project supports platforms other than web, you will need to use a
conditional import to avoid directly including `webview_flutter_web.dart` on
non-web platforms. For example:

`register_web_webview.dart`:
```dart
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_web/webview_flutter_web.dart';
void registerWebViewWebImplementation() {
WebView.platform = WebWebViewPlatform();
}
```

`register_web_webview_stub.dart`:
```dart
void registerWebViewWebImplementation() {
// No-op.
}
```

`main.dart`:
```dart
...
import 'register_web_webview_stub.dart'
if (dart.library.html) 'register_web.dart';
main() {
registerWebViewWebImplementation();
...
```
2 changes: 1 addition & 1 deletion packages/webview_flutter/webview_flutter_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: webview_flutter_web
description: A Flutter plugin that provides a WebView widget on web.
repository: https://github.com/flutter/plugins/tree/master/packages/webview_flutter/webview_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
version: 0.1.0
version: 0.1.0+1

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down

0 comments on commit c0b4032

Please sign in to comment.