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

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: [
///
]
))

http://www.kler.cn/a/560570.html

相关文章:

  • MySQL的InnoDB引擎中的聚簇索引和非聚簇索引有什么区别?
  • 如何用HBase轻松管理海量数据?
  • 蓝桥杯备赛-迷宫-BFS
  • leetcode_二叉树 543.二叉树的直径
  • GreatSQL修改配置文件参数无法生效
  • jvm调试和查看工具
  • 与go比肩的FastAPI,如何快速入门
  • Java 大视界 -- 深入剖析 Java 大数据实时 ETL 中的数据质量保障策略(97)
  • go实现敏感词过滤
  • 我与Linux的爱恋:了解信号量+共享内存+消息队列的应用
  • 【quicker】调节PPT指定字号字体大小/快速调节WPS的PPT字体大小
  • 专用奶泡棒芯片SOC,WD8001
  • 计算机毕业设计SpringBoot+Vue.js足球青训俱乐部管理系统(源码+文档+PPT+讲解)
  • Origin 2024绘图与数据分析下载|附安装包+学习教程
  • 模版语法vscode
  • git从本地其他设备上fetch分支
  • Spring Cloud Gateway 网关的使用
  • AWS IoT Core与AWS服务协同:构建强大的物联网解决方案
  • langchain系列(四)- LangChain 的RAG原理与代码实现
  • 005:Cesium.viewer 知识详解、示例代码