【问题标题】:Column's children must not contain any null values, but null value was found at index 0列的子项不得包含任何空值,但在索引 0 处找到空值
【发布时间】:2020-12-02 01:12:38
【问题描述】:

我正在开发一个 Flutter 应用程序,并且我正在尝试创建一个 InAppWebView。在 Android 上一切正常,但在 iOS 上出现错误:

“列的子项不得包含任何空值,但在索引 0 处找到空值”。

我已经点击了 Flutter clean、flutter build ios 和 clean xcode。但是还是出现这个错误。

感谢任何帮助

这是我的代码:

child: Scaffold(
        appBar: AppBar(title: Text("voucherweb")),
        body: Container(
            child: Column(children: <Widget>[
              progress == null ? Container() : (progress != 1.0)
              ? LinearProgressIndicator(
                  value: progress,
                  backgroundColor: Colors.grey[200],
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
              : null,
          Expanded(
            child: Container(
              child: InAppWebView(
                  initialUrl: "https://voucherweb.com",
                  initialHeaders: {},
                  initialOptions: InAppWebViewGroupOptions(
                    crossPlatform: InAppWebViewOptions(
                        debuggingEnabled: true,
                        useShouldOverrideUrlLoading: true),
                  ),
                  shouldOverrideUrlLoading: (controller, request) async {
                    var url = request.url;
                    var uri = Uri.parse(url);
                    if (request.url.startsWith("https://wa.me/")) {
                      final newString =
                          url.replaceAll("https://wa.me/", "");
                      if (await canLaunch(url)) {
                        FlutterOpenWhatsapp.sendSingleMessage(
                            newString, "Halo, gan. Mau order voucher : ");
                        return ShouldOverrideUrlLoadingAction.CANCEL;
                      }
                    }
                    return ShouldOverrideUrlLoadingAction.ALLOW;
                  },
                  onWebViewCreated: (InAppWebViewController controller) {
                    webView = controller;
                  },
                  onLoadStart:
                      (InAppWebViewController controller, String url) {},
                  onLoadStop:
                      (InAppWebViewController controller, String url) {},
                  onProgressChanged:
                      (InAppWebViewController controller, int progress) {
                    setState(() {
                      this.progress = progress / 100;
                    });
                  }),
            ),
          ),
        ]))));

【问题讨论】:

    标签: ios flutter webview


    【解决方案1】:

    您正在将Column's 子项之一设置为null,请考虑改用SizedBox()Container()

    我使用您的代码添加了一个示例:

    child: Scaffold(
            appBar: AppBar(title: Text("voucherweb")),
            body: Container(
                child: Column(children: <Widget>[
                  progress == null ? Container() : (progress != 1.0)
                  ? LinearProgressIndicator(
                      value: progress,
                      backgroundColor: Colors.grey[200],
                      valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
                  // new line
                  : SizedBox(),
              Expanded(
                child: Container(
                  child: InAppWebView(
                      initialUrl: "https://voucherweb.com",
                      initialHeaders: {},
                      initialOptions: InAppWebViewGroupOptions(
                        crossPlatform: InAppWebViewOptions(
                            debuggingEnabled: true,
                            useShouldOverrideUrlLoading: true),
                      ),
                      shouldOverrideUrlLoading: (controller, request) async {
                        var url = request.url;
                        var uri = Uri.parse(url);
                        if (request.url.startsWith("https://wa.me/")) {
                          final newString =
                              url.replaceAll("https://wa.me/", "");
                          if (await canLaunch(url)) {
                            FlutterOpenWhatsapp.sendSingleMessage(
                                newString, "Halo, gan. Mau order voucher : ");
                            return ShouldOverrideUrlLoadingAction.CANCEL;
                          }
                        }
                        return ShouldOverrideUrlLoadingAction.ALLOW;
                      },
                      onWebViewCreated: (InAppWebViewController controller) {
                        webView = controller;
                      },
                      onLoadStart:
                          (InAppWebViewController controller, String url) {},
                      onLoadStop:
                          (InAppWebViewController controller, String url) {},
                      onProgressChanged:
                          (InAppWebViewController controller, int progress) {
                        setState(() {
                          this.progress = progress / 100;
                        });
                      }),
                ),
              ),
            ]))));
    

    【讨论】:

    • 我已经添加了:SizedBox(),但是运行时出现白屏。有什么建议吗?
    • NSAppTransportSecurity 标签已添加到我的 plist 中。
    • 如果仍然出现错误"Column's children must not contain any null values, but a null value was found at index 0".,您可以尝试在android上运行吗?
    • 是的,Android 上一切正常,Webview 运行良好,加载网站没有问题。但是在我添加 SizedBox() 之后,在 iOS 上得到了白屏
    • 我的问题解决了,我只是在 plist 上添加了&lt;key&gt;io.flutter.embedded_views_preview&lt;/key&gt; &lt;true/&gt;,然后白屏就消失了。谢谢
    【解决方案2】:
    progress == null ? Container() : (progress != 1.0)
    ? LinearProgressIndicator(
    value: progress,
    backgroundColor: Colors.grey[200],
    valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
    : Container(),
    

    请使用此代码 null 不是小部件,这就是您收到此错误的原因。

    【讨论】:

      猜你喜欢
      • 2020-12-08
      • 2021-10-29
      • 2021-06-10
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-16
      相关资源
      最近更新 更多