繁体   English   中英

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

[英]Row's children must not contain any null values, but a null value was found at index 2

我有下面的屏幕图像

我在 ui 中有一个 Apple 登录,所以我只需要在 IOS 中使用这个 Apple 登录,所以我创建了以下代码:

Platform.isIOS
                                ? IPetCustomCircleBtn(
                                    constraintWidth:
                                        constraints.maxWidth * 0.13,
                                    constraintHeight:
                                        constraints.maxHeight * 0.13,
                                    iPetShapeBorder: CircleBorder(
                                      side: BorderSide(
                                        width: 2,
                                        color: Colors.black,
                                        style: BorderStyle.solid,
                                      ),
                                    ),
                                    iPetChildCard: IPetCustomIcon(
                                      ipFontIc: FontAwesomeIcons.apple,
                                      colour: Colors.black,
                                    ),
                                    iPetIconColor: Colors.black,
                                    iPetFillColor: Colors.white,
                                  )
                                : null

我发现了这个错误:

Row's children must not contain any null values, but a null value was found at index 2

我试图通过添加一个空的小部件作为下面的代码来处理这个问题

Platform.isIOS
                                ? IPetCustomCircleBtn(
                                    constraintWidth:
                                        constraints.maxWidth * 0.13,
                                    constraintHeight:
                                        constraints.maxHeight * 0.13,
                                    iPetShapeBorder: CircleBorder(
                                      side: BorderSide(
                                        width: 2,
                                        color: Colors.black,
                                        style: BorderStyle.solid,
                                      ),
                                    ),
                                    iPetChildCard: IPetCustomIcon(
                                      ipFontIc: FontAwesomeIcons.apple,
                                      colour: Colors.black,
                                    ),
                                    iPetIconColor: Colors.black,
                                    iPetFillColor: Colors.white,
                                  )
                                : SizedBox()

但问题是外观不好,因为我需要按钮的 rest 位于行的中心,这是我的全行:

Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: [
                            IPetCustomCircleBtn(
                              constraintWidth: constraints.maxWidth * 0.13,
                              constraintHeight: constraints.maxHeight * 0.13,
                              iPetShapeBorder: CircleBorder(),
                              iPetChildCard: IPetCustomIcon(
                                ipFontIc: FontAwesomeIcons.google,
                                colour: Colors.white,
                              ),
                              iPetIconColor: Colors.white,
                              iPetFillColor: Colors.red,
                            ),
                            IPetCustomCircleBtn(
                              constraintWidth: constraints.maxWidth * 0.13,
                              constraintHeight: constraints.maxHeight * 0.13,
                              iPetShapeBorder: CircleBorder(),
                              iPetChildCard: IPetCustomIcon(
                                ipFontIc: FontAwesomeIcons.facebook,
                                colour: Colors.white,
                              ),
                              iPetIconColor: AppConst.kPrimaryWhiteBgColor,
                              iPetFillColor: AppConst.kBlueColor,
                            ),
                            Platform.isIOS
                                ? IPetCustomCircleBtn(
                                    constraintWidth:
                                        constraints.maxWidth * 0.13,
                                    constraintHeight:
                                        constraints.maxHeight * 0.13,
                                    iPetShapeBorder: CircleBorder(
                                      side: BorderSide(
                                        width: 2,
                                        color: Colors.black,
                                        style: BorderStyle.solid,
                                      ),
                                    ),
                                    iPetChildCard: IPetCustomIcon(
                                      ipFontIc: FontAwesomeIcons.apple,
                                      colour: Colors.black,
                                    ),
                                    iPetIconColor: Colors.black,
                                    iPetFillColor: Colors.white,
                                  )
                                : SizedBox()
                          ],
                        ),

所以对于这种情况有什么好办法:D..

我希望这可以足够清楚..

登录屏幕

我建议你构建两行,1 行有苹果登录,其他没有,然后调用Platform.isIOS? rowWithIos: rowWithoutIos Platform.isIOS? rowWithIos: rowWithoutIos ,如果您为所有登录类型构建小部件,您可以减少这两行中的重复代码。

我能想到的方法有两种:

  1. 尝试为您的sizedBox 添加高度和宽度

     SizedBox(height: 0, width: 0,)
  2. 尝试

     Row( mainAxisAlignment: Platform.isIOS? MainAxisAlignment.spaceAround: MainAxisAlignment.spaceBetween....

您可以根据需要替换 mainAxisAlignment

我找到了更好的解决方案,就像下面的代码:

if (Platform.isIOS)
                              IPetCustomCircleBtn(
                                constraintWidth: constraints.maxWidth * 0.13,
                                constraintHeight: constraints.maxHeight * 0.13,
                                iPetShapeBorder: CircleBorder(
                                  side: BorderSide(
                                    width: 2,
                                    color: Colors.black,
                                    style: BorderStyle.solid,
                                  ),
                                ),
                                iPetChildCard: IPetCustomIcon(
                                  ipFontIc: FontAwesomeIcons.apple,
                                  colour: Colors.black,
                                ),
                                iPetIconColor: Colors.black,
                                iPetFillColor: Colors.white,
                              ),

暂无
暂无

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

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