【发布时间】:2023-02-23 18:25:39
【问题描述】:
我写了一个使用InAppWebView显示网页的应用程序,网页缩放必须禁用,根据规范我设置了supportzoom如下
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
supportZoom: false,
clearCache: true,
preferredContentMode: UserPreferredContentMode.DESKTOP))
一切正常,直到最新的 android 更新(ANDROID 11 版本 T725XXU2DVG3/T250XM2DVB2/T725XXU2DVB2)
更新后,我可以缩放显示的页面,尽管之前的设置有效。
我目前使用的版本是“flutter_inappwebview: ^5.7.1”
我还尝试使用 beta 6.0.0(显然更改了已弃用的方法)但没有任何改变。 我写了一个测试应用程序,它给了我同样的问题
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter/services.dart';
import 'package:wakelock/wakelock.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey webViewKey = GlobalKey();
InAppWebViewController? webViewController;
InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
supportZoom: false,
clearCache: true,
mediaPlaybackRequiresUserGesture: false,
),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
),
ios: IOSInAppWebViewOptions(
allowsInlineMediaPlayback: true,
));
late PullToRefreshController pullToRefreshController;
String url = "";
@override
void initState() {
super.initState();
Wakelock.enable();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
pullToRefreshController = PullToRefreshController(
options: PullToRefreshOptions(
color: Colors.blue,
),
onRefresh: () async {
if (Platform.isAndroid) {
webViewController?.reload();
} else if (Platform.isIOS) {
webViewController?.loadUrl(
urlRequest: URLRequest(url: await webViewController?.getUrl()));
}
},
);
}
void _incrementCounter() {
setState(() {
webViewController?.reload();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: InAppWebView(
key: webViewKey,
initialUrlRequest: URLRequest(
url: Uri.parse("https://someURL")),
onWebViewCreated: (controller) {
webViewController = controller;
},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
supportZoom: false,
clearCache: true,
preferredContentMode: UserPreferredContentMode.DESKTOP)),
onLoadStart: (controller, url) {
setState(() {
this.url = url.toString();
//urlController.text = this.url;
});
},
androidOnPermissionRequest: (controller, origin, resources) async {
return PermissionRequestResponse(
resources: resources,
action: PermissionRequestResponseAction.GRANT);
},
shouldOverrideUrlLoading: (controller, navigationAction) async {
var uri = navigationAction.request.url!;
if (![
"http",
"https",
"file",
"chrome",
"data",
"javascript",
"about"
].contains(uri.scheme)) {
if (await canLaunchUrl(Uri.parse(url))) {
// Launch the App
await launchUrl(
Uri.parse(url),
);
// and cancel the request
return NavigationActionPolicy.CANCEL;
}
}
return NavigationActionPolicy.ALLOW;
},
onLoadStop: (controller, url) async {
pullToRefreshController.endRefreshing();
setState(() {
this.url = url.toString();
//urlController.text = this.url;
});
},
onProgressChanged: (controller, progress) {
if (progress == 100) {
pullToRefreshController.endRefreshing();
}
setState(() {
});
},
onUpdateVisitedHistory: (controller, url, androidIsReload) {
setState(() {
this.url = url.toString();
});
},
onReceivedServerTrustAuthRequest: (controller, challenge) async {
return ServerTrustAuthResponse(
action: ServerTrustAuthResponseAction.PROCEED);
},
onConsoleMessage: (controller, consoleMessage) {
print(consoleMessage);
},
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
pubspec.yaml
环境: SDK: '>=2.18.2 <3.0.0'
依赖项: 扑: SDK: 颤动
cupertino_icons: ^1.0.2 flutter_inappwebview: ^5.7.1 唤醒锁:^0.6.2 url_launcher: ^6.1.6
dev_dependencies: 颤动测试: SDK: 颤动
flutter_lints:^2.0.0
扑:
使用材料设计:正确
compileSdk版本33 minSdkVersion 17 targetSdk版本 17
还有其他人有同样的问题吗?
【问题讨论】:
-
请修剪您的代码,以便更容易找到您的问题。按照这些指南创建一个minimal reproducible example。
标签: flutter webview zooming flutter-web flutter-inappwebview