[英]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.