【问题标题】:Error hasSize even though there is expanded and there is container height and width错误 hasSize 即使有扩展并且有容器高度和宽度
【发布时间】:2023-01-16 17:11:06
【问题描述】:

我对下面的代码有疑问

Align(
 alignment: Alignment.center,
 child:Expanded(
 child: Container(
 decoration: AppDecoration.fillGray100.copyWith(
 borderRadius: BorderRadiusStyle.roundedBorder16,
 ),
 child: Expanded(
 child: Column(
 children: [
 Expanded(
 child: Row(
 children: [
 Container(
 padding: getPadding(
 all: 12,
 ),
 decoration: AppDecoration.fillGray100,
 child: Expanded(
 child: Row(
 children: [
 Expanded(
 child: Column(
 mainAxisAlignment:
 MainAxisAlignment.start,
 children: [
 CustomImageView(
 svgPath:
 ImageConstant.imgSearch,
 height: getSize(
 24.00,
 ),
 width: getSize(
 24.00,
 ),
 margin: getMargin(
 all: 12,
 ),
 ),
 ],
 ),
 ),
 ],
 ),
 ),
 ),
 AppbarTitle(
 text: "lbl_search_doctor".tr,
 margin: getMargin(
 left: 16,
 top: 14,
 right: 125,
 bottom: 14,
 ),
 ),
 ],
 ),
 ),
 ],
 ),
 ),
 ),
 ),
 ),

错误信息: 'package:flutter/src/rendering/shifted_box.dart':断言失败:第 361 行 pos 12:'child!.hasSize':不正确。

RenderBox 未布局:RenderDecoratedBox#79ea0 relayoutBoundary=up2 '包:flutter/src/rendering/box.dart': 断言失败:第 2001 行第 12 行:'hasSize'

这是错误消息,此代码之前没有单个滚动视图

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您在两个地方错误地使用了 Expanded 。第一个在容器上方,第二个在列上方。这导致它们具有无限的宽度和高度。我修改了代码:-

    Align(
    alignment: Alignment.center,
    child: Container(
    decoration: AppDecoration.fillGray100.copyWith(
      borderRadius: BorderRadiusStyle.roundedBorder16,
    ),
    child: Column(
      children: [
        Row(
          children: [
            Container(
              padding: getPadding(
                all: 12,
              ),
              decoration: AppDecoration.fillGray100,
              child: Expanded(
                child: Row(
                  children: [
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          CustomImageView(
                            svgPath: ImageConstant.imgSearch,
                            height: getSize(
                              24.00,
                            ),
                            width: getSize(
                              24.00,
                            ),
                            margin: getMargin(
                              all: 12,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            AppbarTitle(
              text: "lbl_search_doctor".tr,
              margin: getMargin(
                left: 16,
                top: 14,
                right: 125,
                bottom: 14,
              ),
            ),
          ],
        ),
      ],
    ),
    ),
    ),
    

    【讨论】:

      猜你喜欢
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多