简体   繁体   English

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

[英]Column's children must not contain any null values, but null value was found at index 0

I'm developing a Flutter app, and I am trying to create a InAppWebView.我正在开发一个 Flutter 应用程序,并且我正在尝试创建一个 InAppWebView。 Everything is working well on Android, but on iOS i got an error:在 Android 上一切正常,但在 iOS 上出现错误:

"Column's children must not contain any null values, but a null value was found at index 0". “列的子项不得包含任何 null 值,但在索引 0 处找到 null 值”。

I already hit flutter clean, flutter build ios, and clean xcode.我已经打了 flutter 清洁,flutter 构建 ios,清洁 xcode。 But still got this error.但仍然得到这个错误。

Any help is appreciated任何帮助表示赞赏

Here is my code:这是我的代码:

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;
                    });
                  }),
            ),
          ),
        ]))));

You are setting one of the Column's child to null , consider using a SizedBox() or a Container() instead:您正在将Column's其中一个子级设置为null ,请考虑使用SizedBox()Container()代替:

I added an example using your code:我使用您的代码添加了一个示例:

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;
                    });
                  }),
            ),
          ),
        ]))));
progress == null ? Container() : (progress != 1.0)
? LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
: Container(),

Please use this code null is not widget that's why you are getting this error.请使用此代码 null 不是小部件,这就是您收到此错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM