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,
          ),
        )),
      ),
    ),
  ),
);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏