Explorar el Código

Merge pull request #431 from muffinjello/master

Update README.md with injection example
Rafal Wachol hace 6 años
padre
commit
bda93062c9
Se han modificado 1 ficheros con 20 adiciones y 1 borrados
  1. 20 1
      README.md

+ 20 - 1
README.md

@@ -10,7 +10,7 @@ Plugin that allows Flutter to communicate with a native WebView.
 
 
 **_Warning:_**
 **_Warning:_**
 The webview is not integrated in the widget tree, it is a native view on top of the flutter view.
 The webview is not integrated in the widget tree, it is a native view on top of the flutter view.
-you won't be able to use snackbars, dialogs ...
+You won't be able see snackbars, dialogs, or other flutter widgets that would overlap with the region of the screen taken up by the webview.
 
 
 ## Getting Started
 ## Getting Started
 
 
@@ -142,6 +142,25 @@ flutterWebviewPlugin.launch(url,
 );
 );
 ```
 ```
 
 
+#### Injecting custom code into the webview
+Use `flutterWebviewPlugin.evalJavaScript(String code)`. This function must be run after the page has finished loading (i.e. listen to `onStateChanged` for events where state is `finishLoad`).
+
+If you have a large amount of JavaScript to embed, use an asset file. Add the asset file to `pubspec.yaml`, then call the function like:
+
+```dart
+Future<String> loadJS(String name) async {
+  var givenJS = rootBundle.loadString('assets/$name.js');
+  return givenJS.then((String js) {
+    flutterWebViewPlugin.onStateChanged.listen((viewState) async {
+      if (viewState.type == WebViewState.finishLoad) {
+        flutterWebViewPlugin.evalJavascript(js);
+      }
+    });
+  });
+}
+```
+
+
 ### Webview Events
 ### Webview Events
 
 
 - `Stream<Null>` onDestroy
 - `Stream<Null>` onDestroy