我可以在我的Flutter移动应用程序中使用JavaScript执行代码和库。我使用webview_flutter来实现这一点。但是,我不想在用户界面中显示WebView。我只想在WebView隐藏的情况下执行库。在Flutter中,我该如何做到这点?
我可以在我的Flutter移动应用程序中使用JavaScript执行代码和库。我使用webview_flutter来实现这一点。但是,我不想在用户界面中显示WebView。我只想在WebView隐藏的情况下执行库。在Flutter中,我该如何做到这点?
我已经找到了解决自己问题的方法。我使用了webview_flutter_plus: ^0.1.1+9,同时使用可见性小部件并设置相应的属性。以下是代码片段。
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Webview counter: ' + scounter),
),
body: Column(
children: <Widget>[
Visibility(
visible: false,
maintainState: true,
child: SizedBox(
height: 1,
child: WebViewPlus(
onWebViewCreated: (controller) {
this._webViewController = controller;
controller.loadUrl("files/test.html");
},
onPageFinished: (url) {
_webViewController.getHeight().then((double height) {
print("height: " + height.toString());
setState(() {
_height = height;
});
});
},
javascriptMode: JavascriptMode.unrestricted,
javascriptChannels: <JavascriptChannel>[_counterx()].toSet(),
),
),
),
Text("Webview above"),
],
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () {
_webViewController.evaluateJavascript('reset()');
},
),
);
}