flutter中ListView设置了Axis.horizontal,高度如何自适应

Container(
          height: 413,
          margin: EdgeInsets.only(left: 36),
          child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: goodsList.length,
            padding: EdgeInsets.zero,
            itemBuilder: (context, position) {
              return Container(
                margin: EdgeInsets.only(right: 30),
                width: 260,
                child: RowCardItem(
                  cardData: goodsList[position],
                  imgHeight: 260,
                  imgWidth: 260,
                ),
              );
            },
          ),
        )

不想给外层Container设定高度,想让高度随内容自适应

阅读 8k
3 个回答
          shrinkWrap: true,
新手上路,请多包涵

Container(

  width: double.infinity,
  margin: EdgeInsets.only(left: 36),
  child: IntrinsicHeight(
    child: SingleChildScrollView(
      child: Row(
        children: List.generate(goodsList.length, (index)=>Container(
          margin: EdgeInsets.only(right: 30),
          width: 260,
          child: RowCardItem(
            cardData: goodsList[index],
            imgHeight: 260,
            imgWidth: 260,
          ),
        )),
      ),
    ),
  ),
);
推荐问题
宣传栏