javascript - 如何在移动应用程序中隐藏颤动的 webview
问题描述
我可以在我的移动应用程序中使用 javascript 执行代码和库。我使用 webview_flutter 来做到这一点。但我不想在我的 UI 中显示 webview。我只想在隐藏 webview 的情况下执行库。我怎么能在颤动中做到这一点?
解决方案
我找到了解决我自己问题的方法。我改用 webview_flutter_plus: ^0.1.1+9 和具有适当属性的 Visibility 小部件。可以在下面的代码片段中看到。
@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()');
},
),
);
}
推荐阅读
- angular - Mat-Select 显示对象属性,即来自先前选择/保存的值的 customer.name
- firebase - 使用 Firebase 和 React Native 删除密钥中的多个子项
- oauth - 外部/来宾/B2B 协作用户能否访问 Dynamics Operations OData?
- redux - 当有效负载为真时,Redux Reducer 不会更新状态
- visual-studio-code - 如何在 Visual Studio 代码中使用 Autohotkey 热字串?
- javascript - 我如何执行 btoa(string); 使用 HTML 和 JS
- ruby-on-rails - 在 API 模式下使用 Rails 5 进行电子邮件样式的引导
- java - Android Studio:添加自定义 jar 作为依赖项
- javascript - 如何使用 Javascript 从 2D json 对象获取数据
- javascript - 使用JS获取SVG内部元素的绝对坐标