javascript - 如何在移动应用程序中隐藏 flutter 的 webview

标签 javascript android ios flutter

我可以在我的移动应用程序中使用 javascript 执行代码和库。我使用 webview_flutter 来做到这一点。但我不想在我的 UI 中显示 webview。我只想在隐藏 webview 的情况下执行库。我怎么能在 flutter 中做到这一点?

最佳答案

我找到了解决我自己问题的方法。我改用 webview_flutter_plus: ^0.1.1+9 和具有适当属性的 Visibility 小部件。可以在下面的代码 fragment 中看到。

  @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()');
        },
      ),
    );
  }

关于javascript - 如何在移动应用程序中隐藏 flutter 的 webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62858028/

相关文章:

android - 为什么在 android 开发人员指南中 android :authorities is defined like this?

android - 将位图缩放到 80%

ios - 迪尔德 : Symbol not found: __TMPdCSs12AnyGenerator

javascript - 将数据属性从“like”按钮复制到父列表项

javascript - 子组件中的事件返回未定义的 ' Uncaught TypeError: Cannot read property ' 值

android - 杀死线程中的 Activity

ios - layoutifneeded 不会触发layoutSubviews

android - Flutter:如何将 RefreshIndicator 与 SliverAppBar 一起使用

javascript - 我需要用 javascript 为我的计算器创建一个退格函数

javascript - 如何在UIWebView中使用Javascript?