[英]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 默认是缩放的。 我想在最初打开页面时禁用缩放。 如果用户想要缩放页面,他们必须自己做。 但默认情况下,我不希望 webview 被缩放。 我尝试过使用 webviewscaffold,但我也遇到了同样的问题。 我的 Android webview 代码运行良好,我想用 dart 实现同样的效果。 我怎样才能做到这一点?
注意:打开页面时禁用 webview 缩放
对于缩放控制,您应该使用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 {
},
)
你可以这样做
WebView(
zoomEnabled: false,
initialUrl: 'https url',
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.