我正在创建一个 html 文件并将其文件路径提供给webview_flutter
插件以显示社交嵌入,例如 twitter、youtube 等。
我已经在更多的项目中使用了这个逻辑,但是我无法在一些旧的 Android 版本上加载资产错误。例如,它在 Android 10、11 上完美运行,但在 Android 8 上出现错误。
这是一个遗留项目,我不确定为什么两个操作系统之间的逻辑不同是不同的
@override
Widget build(BuildContext context) {
var wv;
if (Platform.isIOS) {
wv = WebView(
initialUrl: htmlToURI(_buildCode(context)),
javascriptChannels:
<JavascriptChannel>[_getHeightJavascriptChannel()].toSet(),
javascriptMode: JavascriptMode.unrestricted);
} else if (Platform.isAndroid) {
File aux =
File(Config.filePath.path + '/' + name.toString() + '.html');
aux.writeAsString(_buildCode(context));
wv = WebView(
initialUrl: 'file:///' + aux.path,
javascriptChannels:
<JavascriptChannel>[_getHeightJavascriptChannel()].toSet(),
javascriptMode: JavascriptMode.unrestricted,
navigationDelegate: (navigation) {
return NavigationDecision.prevent;
},
onPageFinished: (url) => aux.delete(),
onWebResourceError: (err) {
print(err.description);
},
);
}