解决华为 webview Chrome 78 内核版本渲染白屏问题

This commit is contained in:
2026-07-17 15:22:57 +08:00
parent e08a8ed26b
commit a4333d3bd1
+17 -2
View File
@@ -64,7 +64,7 @@ class WebviewPageState extends State<WebviewPage> {
late final WebViewController controller;
controller = WebViewController.fromPlatformCreationParams(params)
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(Colors.transparent)
..setBackgroundColor(Colors.white)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {
@@ -231,6 +231,21 @@ class WebviewPageState extends State<WebviewPage> {
return const PlatformWebViewControllerCreationParams();
}
Widget _buildWebView(WebViewController controller) {
PlatformWebViewWidgetCreationParams params =
PlatformWebViewWidgetCreationParams(controller: controller.platform);
if (WebViewPlatform.instance is AndroidWebViewPlatform) {
params =
AndroidWebViewWidgetCreationParams.fromPlatformWebViewWidgetCreationParams(
params,
displayWithHybridComposition: true,
);
}
return WebViewWidget.fromPlatformCreationParams(params: params);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -294,7 +309,7 @@ class WebviewPageState extends State<WebviewPage> {
Expanded(
child: Stack(
children: [
Positioned.fill(child: WebViewWidget(controller: controller)),
Positioned.fill(child: _buildWebView(controller)),
if (_isLoading)
const Center(child: CircularProgressIndicator()),
],