fixed README.md HeadlessInAppWebView example

This commit is contained in:
Lorenzo Pichilli 2020-05-26 00:44:14 +02:00
parent 682c6e2243
commit 6c97be3604
1 changed files with 37 additions and 37 deletions

View File

@ -779,6 +779,7 @@ Example:
```dart ```dart
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async { Future main() async {
@ -845,44 +846,43 @@ class _MyAppState extends State<MyApp> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
"HeadlessInAppWebView", "HeadlessInAppWebView",
)), )),
drawer: myDrawer(context: context),
body: SafeArea( body: SafeArea(
child: Column(children: <Widget>[ child: Column(children: <Widget>[
Container( Container(
padding: EdgeInsets.all(20.0), padding: EdgeInsets.all(20.0),
child: Text( child: Text(
"CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"), "CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"),
), ),
Center( Center(
child: RaisedButton( child: RaisedButton(
onPressed: () async { onPressed: () async {
await headlessWebView.dispose(); await headlessWebView.dispose();
await headlessWebView.run(); await headlessWebView.run();
}, },
child: Text("Run HeadlessInAppWebView")), child: Text("Run HeadlessInAppWebView")),
), ),
Center( Center(
child: RaisedButton( child: RaisedButton(
onPressed: () async { onPressed: () async {
try { try {
await headlessWebView.webViewController.evaluateJavascript(source: """console.log('Here is the message!');"""); await headlessWebView.webViewController.evaluateJavascript(source: """console.log('Here is the message!');""");
} on MissingPluginException catch(e) { } on MissingPluginException catch(e) {
print("HeadlessInAppWebView is not running. Click on \"Run HeadlessInAppWebView\"!"); print("HeadlessInAppWebView is not running. Click on \"Run HeadlessInAppWebView\"!");
} }
}, },
child: Text("Send console.log message")), child: Text("Send console.log message")),
), ),
Center( Center(
child: RaisedButton( child: RaisedButton(
onPressed: () { onPressed: () {
headlessWebView.dispose(); headlessWebView.dispose();
}, },
child: Text("Dispose HeadlessInAppWebView")), child: Text("Dispose HeadlessInAppWebView")),
) )
]) ])
) )
); );
} }
} }