首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使webview适应屏幕大小

如何使webview适应屏幕大小
EN

Stack Overflow用户
提问于 2021-09-02 12:06:25
回答 1查看 29关注 0票数 0
代码语言:javascript
复制
 @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      bottomNavigationBar: _bottomTab(),
      appBar: AppBar(
        title: Text('View ' + type),
        actions: [
          IconButton(
              icon: Icon(Icons.print),
              onPressed: () {
                // getPermission('print');
                printPdfFile();
              }),
          IconButton(
              icon: Icon(Icons.edit),
              onPressed: () {
                navigateTo();
              }),
        ],
      ),
      body: Stack(
        children: <Widget>[
          Align(
            alignment: Alignment.center,
            child:
                Visibility(visible: true, child: CircularProgressIndicator()),
          ),

          Align(
            alignment: Alignment.center,
            child: Container(
              color: Colors.white,
              height: MediaQuery.of(context).size.height / 1.5,
              child: WebviewScaffold(
                url: weburl,
                displayZoomControls: true,
                withJavascript: true,
                // scrollBar: true,
                withZoom: true,

                hidden: true,
                // bottomNavigationBar: _bottomTab(),
              ),
            ),
          ),

          // WebviewScaffold(
          //   url: weburl,
          //   withZoom: true,
          //   hidden: true,
          //   appBar: AppBar(
          //     title: Text('View ' + type),
          //     actions: [
          //       IconButton(
          //           icon: Icon(Icons.print),
          //           onPressed: () {
          //             getPermission('print');
          //           }),
          //     ],
          //   ),
          //   bottomNavigationBar: _bottomTab(),
          // )
        ],
      ),
    );
  }

我在flutter application.The中实现webview的问题是,当我最初打开小工具时,默认情况下我的webview是缩放的。我不想要它,假设用户想要缩放屏幕,他们可以,但在默认情况下,我不希望网页视图在打开页面时处于缩放状态。

EN

回答 1

Stack Overflow用户

发布于 2021-09-02 12:28:48

请记住,我用dartPad编写了一段很脏的代码,所以可能会遗漏了一些结束标记

  1. 如何使web视图适合屏幕大小您可以使用

,然后展开子列

代码语言:javascript
复制
return Scaffold(
      backgroundColor: Colors.white,
      bottomNavigationBar: _bottomTab(),
      appBar: AppBar(
        title: Text('View ' + type),
        actions: [
          IconButton(
              icon: Icon(Icons.print),
              onPressed: () {
                // getPermission('print');
                printPdfFile();
              }),
          IconButton(
              icon: Icon(Icons.edit),
              onPressed: () {
                navigateTo();
              }),
        ],
      ),
      body: _isLoading   
        ? CircularProgressIndicator() 
        : Column(children: [
            Expanded(
                child: WebviewScaffold(
                  url: weburl,
                  displayZoomControls: _enableZoom,
                  withJavascript: true,
                  withZoom: _enableZoom,
                  hidden: true,
                ),
            ),
          ],
        ),
      );

2禁止从webView进行默认缩放

注意这里有一个变量_enableZoom,在渲染之后你可以启用缩放。或者使用另一个用于缩放InteractiveViewer的小部件。

代码语言:javascript
复制
InteractiveViewer(
   panEnabled: _zoomEnable,
   child: WebviewScaffold(
                  url: weburl,
                  displayZoomControls: false,
                  withJavascript: true,
                  withZoom: false,
                  hidden: true,
                  ....
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69029965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档