当前位置: 首页 > news >正文

flutter Column嵌套ListView高度自适应问题

1.限制最大高度500,当布局高度小于500时高度自适应包裹

//当布局外不需要包裹Container时,使用ConstrainedBox(constraints: BoxConstraints(maxHeight: 500,minHeight: 0),child: Column())
_body(){
    return Container(
        constraints: BoxConstraints(maxHeight: 500,minHeight: 0),
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(10)
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(height: 40.w),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Container(width: 10),
                Expanded(
                    child: Text(
                      '选择二维码',
                      style: TextStyle(
                        fontSize: 30.sp,
                        color: JadeColors.grey_2,
                        fontWeight: FontWeight.w600,
                      ),
                      textAlign: TextAlign.center,
                    )),
                GestureDetector(
                  child: Container(
                    color: Colors.transparent,
                    padding: EdgeInsets.all(4),
                    margin: EdgeInsets.only(right: 20.w),
                    child: Image.asset(PathConfig.iconCloseWhite, width: 36.w, height: 36.w),
                  ),
                  onTap: () {
                    NavigatorUtil.pop();
                  },
                )
              ],
            ),
            Padding(padding: EdgeInsets.only(top: 20.w),
                child: Text('因阿推秀格口较多,请分批生成下载。',style: TextStyle(color: JadeColors.grey,fontSize: 24.sp))),
            Flexible(child: _listView())//Flexible灵活分配空间,未设置flex时默认尽可能小地包裹其内容
          ],
        )
        ,
      );
  }

  _listView(){
    return Padding(padding: EdgeInsets.only(left: 50.w,right: 50.w,top: 30.w),
    child: ScrollConfiguration(
    behavior: CusBehavior(),
    child: ListView.builder(
        shrinkWrap: true,
        itemBuilder: (_,index){
          return _itemButton(index);
        },itemCount: _testList.length))
    );
  }

  _itemButton(index){
    return Container(
      height: 170.w, width: double.infinity,
      padding: EdgeInsets.symmetric(horizontal: 40.w),
      margin: EdgeInsets.only(top: 20.w,bottom: index == _testList.length -1 ? 120.w : 0),
      decoration: BoxDecoration(color: JadeColors.grey_14, borderRadius: BorderRadius.circular(10)),
      child: Row(
        children: [
          Expanded(child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('标题',style: TextStyle(fontSize: 32.sp,fontWeight: FontWeight.w600)),
              Text('描述',style: TextStyle(fontSize: 22.sp,fontWeight: FontWeight.w300,color: JadeColors.grey_3))
            ],)),
          GestureDetector(
            onTap: (){},
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 40.w,vertical: 15.w),
              decoration: BoxDecoration(
                  color: JadeColors.blue_30,
                  borderRadius: BorderRadius.circular(30),
                border: Border.all(color: JadeColors.blue_29)
              ),
              child: Text('查看',style: TextStyle(color: JadeColors.blue_2,fontSize: 24.sp),),
            ),
          )
        ],
      ),
    );
  }

2.限制布局最小高度50,当布局高度大于50时高度自适应包裹

ConstrainedBox(constraints: BoxConstraints(minHeight: 50,
child: Column(
mainAxisSize: MainAxisSize.min,//设置布局内容尽可能小
children: [
///
]
))

相关文章:

  • stm32-电源控制
  • 第N1周:one-hot编码案例
  • Mysql 主从集群同步延迟问题怎么解决
  • 启动Redis报错记录
  • Spring和MyBatis原理和核心
  • 插入排序:一种简单而直观的排序算法
  • MySQL入门
  • 费曼学习法6 - 你好,NumPy!数据分析的 “瑞士军刀” (入门篇)
  • LD_PRELOAD 绕过 disable_function 学习
  • Parameter 与 Param 有什么区别
  • hot100---day3
  • [青基解读二] 2025年国家自然科学基金---时间安排
  • C语言堆学习笔记
  • 将Ubuntu操作系统的安装源设置为阿里云
  • 八大排序算法(C语言实现)
  • JWT令牌
  • 关于单调栈问题的本质的思考
  • vue js-web-screen-shot浏览器截取其他非全屏窗口界面
  • 点击修改按钮图片显示有问题
  • 爬虫解析库:pyquery的详细使用
  • 营销型网站 财务咨询公司/网络营销乐云seo
  • 云信网站建设/世界互联网峰会
  • 做一个网站的基本步骤/网页设计模板
  • vue 做pc网站可以吗/外链收录网站
  • 黄骗免费网站/买链接网站
  • php动态网站开发期末考试/百度一下百度搜索百度一下