Flutter WebView 在 iOS 上显示白屏

问题描述 投票:0回答:1

我想使用Flutter中的WebView加载苹果的代码兑换页面,以便我的用户可以使用订阅折扣。例如,像 Google、Flutter.dev 这样的页面...它工作正常,但遗憾的是使用苹果的 url 则不行。我的身体只是出现一个空白的白屏 - 应用栏工作正常。可能出了什么问题?

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../configuration/theme.dart';


class FumiProPromoPage extends StatefulWidget {
  String code;
  //Variable Code übergeben
  FumiProPromoPage({
    Key? key,
    required this.code,
  }) : super(key: key);

  @override
  State<FumiProPromoPage> createState() => _FumiProPromoPageState();
}

class _FumiProPromoPageState extends State<FumiProPromoPage> {
  var loadingPercentage = 0;
  late WebViewController controller;
  final GlobalKey webViewKey = GlobalKey();

  String promourl = "https://google.de";
  String url = "";
  double progress = 0;
  final urlController = TextEditingController();


  @override
  void initState() {
    super.initState();
    promourl = 'https://apps.apple.com/redeem?ctx=offercodes&id=xxxxxxxx&code=${widget.code}';
    print(promourl);

    controller = WebViewController()
    ..setJavaScriptMode(JavaScriptMode.unrestricted)
    ..setBackgroundColor(const Color(0x00000000))
    ..setNavigationDelegate(
      NavigationDelegate(
        onProgress: (int progress) {
          // Update loading bar.
        },
        onPageStarted: (String url) {},
        onPageFinished: (String url) {},
        onWebResourceError: (WebResourceError error) {},
        onNavigationRequest: (NavigationRequest request) {
          if (request.url.startsWith('https://www.youtube.com/')) {
            return NavigationDecision.prevent;
          }
          return NavigationDecision.navigate;
        },
      ),
    )
    ..loadRequest(Uri.parse(promourl));
  }
  Widget build(BuildContext context) {
    
    return Scaffold(
      appBar: AppBar(
            elevation: 0,
            backgroundColor: fumigruenAccent,
            title: const Text(
              "Promocode einlösen",
              style: TextStyle(
                color: Colors.black,
              ),
            ),
            leading: CloseButton(
              color: Colors.black,
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),),
        
        
      body: 
      
      Stack(
        children: [
          WebViewWidget(
            controller: controller,
          ), 
          
          loadingPercentage < 100
              ? LinearProgressIndicator(
                  color: Colors.red,
                  value: loadingPercentage / 100.0,
                )
              : Container()
        ],
      ), 
    );
  }
}

我还停用了 http 请求的 Apple 传输安全 (ATS) 功能,以查明是否存在问题。可惜没成功。

为此,我将以下行添加到我的 Info.plist 中

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key><true/>
</dict>

有什么想法吗?非常感谢!

ios flutter webview
1个回答
0
投票

我也面临着同样的问题。您找到解决方案了吗?我使用的是 webview_flutter 4.8.0,在 IOS 17 及以下版本上出现黑屏。

© www.soinside.com 2019 - 2024. All rights reserved.