flutter 当为堆栈中嵌套的位置设置top和right时,获取size.isFinite错误

42fyovps  于 2023-01-02  发布在  Flutter
关注(0)|答案(1)|浏览(68)

我有3个定位为ListView内部堆栈的子项。运行时,builder还为所有3个定位设置了顶部和右侧,得到了此错误
size.isFinite
我也有错误
底部溢出102像素
如果我从第一个位置正确地移除顶部和右侧***仅和仅***,我的错误是什么

ListView.builder(
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            itemCount: HomeProvider().homeItems.length,
            itemBuilder: (context, index) => SizedBox(
              
                  child: Stack(
                    children: [
                          Positioned(
                          top: 35,
                          right: 20,
                          child: Material(
                            child: Container(
                              height: 75.0,
                               width: width * 0.9,
                             
                              decoration: BoxDecoration(
                                color: ColorManager.white,
                                borderRadius: BorderRadius.circular(0.0),
                                boxShadow: [
                                  BoxShadow(
                                      color: ColorManager.grey,
                                      offset: const Offset(-10.0, 10.0),
                                      blurRadius: 20.0,
                                      spreadRadius: 4.0),
                                ],
                              ),
                            ),
                          ),),
                          positioned(
                             top:30,
                             right:45,
                             ...
                             ),
                           positioned(
                             top:30,
                             right:45,
                             ...
                             ),
]
izj3ouym

izj3ouym1#

如果你想定位Positioned,需要知道Stack的约束条件(使用上/右/下/左),所以你需要给包裹StackSizedBox分配一些高度。

ListView.builder(
  scrollDirection: Axis.vertical,
  shrinkWrap: true,
  itemCount: HomeProvider().homeItems.length,
  itemBuilder: (context, index) => SizedBox(
    height: 100, // give some height here
    child: Stack(
    children: [
    Positioned(
    top: 35,
    right: 20,
    child: Material(
    child: Container(
      height: 75.0,
        width: width * 0.9,
      
      decoration: BoxDecoration(
        color: ColorManager.white,
        borderRadius: BorderRadius.circular(0.0),
        boxShadow: [
          BoxShadow(
              color: ColorManager.grey,
              offset: const Offset(-10.0, 10.0),
              blurRadius: 20.0,
              spreadRadius: 4.0),
        ],
      ),
    ),
    ),),
    Positioned(
      top:30,
      right:45,
      ...
      ),
    Positioned(
      top:30,
      right:45,
      ...
      ),
])));

相关问题