-1

添加堆栈小部件之前

添加堆栈小部件后om/cFMse.png

为什么当我在 StaggeredGridView 中使用堆栈小部件时图像尺寸会变得奇怪。当我从网格视图中删除堆栈时,布局看起来非常好。我是否以错误的方式使用布局?

new StaggeredGridView.countBuilder(
                crossAxisCount: 2,
                crossAxisSpacing: 10,
                mainAxisSpacing: 10,
                itemCount:model.hit.length,
                itemBuilder: (context, index) {
                  return
                    Stack(
                     children: [
                       Container(
                         decoration: BoxDecoration(
                             color: Colors.transparent,
                             borderRadius: BorderRadius.all(Radius.circular(35))),
                         child:
                         ClipRRect(
                             borderRadius: BorderRadius.all(Radius.circular(35)),
                             child:FadeInImage.memoryNetwork(
                               placeholder: kTransparentImage, image: model.hit[index]['largeImageURL'],fit: BoxFit.cover,)

                         ),


                       )
                     ],
                    );

                },
                staggeredTileBuilder: (index) {
                  return new StaggeredTile.count(1, index.isEven ? 1.2 : 1.8);
                })
4

1 回答 1

1

尝试将 StackFit.expand 参数传递给 Stack

return
    Stack(
       fit: StackFit.expand, /// <-- expand to the size of the parent constraint
       children: [
          Container(
            decoration: BoxDecoration(
              color: Colors.transparent,
              borderRadius: BorderRadius.all(Radius.circular(35))),
              child: ClipRRect(
                 borderRadius: BorderRadius.all(Radius.circular(35)),
                 child:FadeInImage.memoryNetwork(
                   placeholder: kTransparentImage, image: model.hit[index]['largeImageURL'],fit: BoxFit.cover,)
                 ),
             )
        ],
);
于 2020-11-09T16:01:20.647 回答