简体   繁体   中英

How to disable zoom control for WebView in Flutter

@override
Widget build(BuildContext context) {
  return WillPopScope(
      child: Scaffold(
          backgroundColor: Colors.white,
          bottomNavigationBar: _bottomTab(),
          appBar: AppBar(
            title: Text('View ' + type),
          ),
          body: ProgressHUD(
            child: Padding(
              padding: EdgeInsets.all(10.0),
              child: Stack(
                children: <Widget>[
                  Container(
                    child: WebView(
                      initialUrl: weburl,
                      javascriptMode: JavascriptMode.unrestricted,
                      onPageFinished: pageFinishedLoading,
                    ),
                  )
                ],
              ),
            ),
            inAsyncCall: _isLoading,
            opacity: 0.0,
          )),
      onWillPop: backPress);
}

void pageFinishedLoading(String url) {
  setState(() {
    _isLoading = false;
  });
}

class ProgressHUD extends StatelessWidget {
  final Widget child;
  final bool inAsyncCall;
  final double opacity;
  final Color color;
  final Animation<Color> valueColor;

  ProgressHUD({
    Key key,
    @required this.child,
    @required this.inAsyncCall,
    this.opacity = 0.3,
    this.color = Colors.grey,
    this.valueColor,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> widgetList = List<Widget>();
    widgetList.add(child);
    if (inAsyncCall) {
      final modal = Stack(
        children: [
          Opacity(
            opacity: opacity,
            child: ModalBarrier(dismissible: false, color: color),
          ),
          Center(
            child: CircularProgressIndicator(
              valueColor: valueColor,
            ),
          ),
        ],
      );
      widgetList.add(modal);
    }
    return Stack(
      children: widgetList,
    );
  }
}

Webview is zoomed by default. I want to disable zoom when initially opening the page. If the user wants to zoom the page they has to do by themselves. But by default I don't want the webview to be zoomed. I have tried with webviewscaffold but I'm also having same issue. My Android webview code is working perfectly and I want to achieve the same with dart. How can I achieve this?

Note: Disable webview zoom while opening the page

For zoom controlling you should use inapp_webview

InAppWebView(        
                    initialUrlRequest: URLRequest(
                      url: Uri.parse("https://stackoverflow.com")) // updated 
                    
                    initialHeaders: {},
                    initialOptions: InAppWebViewGroupOptions(
                      crossPlatform: InAppWebViewOptions(
                          supportZoom: false, // zoom support
                          debuggingEnabled: true,
                          preferredContentMode: UserPreferredContentMode.MOBILE), // here you change the mode
                    ),
                    onWebViewCreated: (InAppWebViewController controller) {
                      webView = controller;
                    },
                    onLoadStart: (InAppWebViewController controller, String url) {

                    },
                    onLoadStop: (InAppWebViewController controller, String url) async {

                    },
                  )

You Can do this

WebView(
        zoomEnabled: false,
        initialUrl: 'https url',
        
      ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM