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

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

dart 复制代码
//当布局外不需要包裹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时高度自适应包裹

dart 复制代码
ConstrainedBox(constraints: BoxConstraints(minHeight: 50,
child: Column(
mainAxisSize: MainAxisSize.min,//设置布局内容尽可能小
children: [
///
]
))
相关推荐
神经蛙39714 小时前
settings.gradle' line: 22 * What went wrong: Plugin [id: 'org.jetbrains.kotlin.a
flutter
stringwu5 小时前
一个bug 引发的Dart 与 Java WeakReference 对比探讨
flutter
火柴就是我1 天前
从头写一个自己的app
android·前端·flutter
●VON1 天前
Flutter 项目成功运行后,如何正确迁移到 OpenHarmony?常见疑问与跳转失效问题解析
flutter·华为·openharmony·开源鸿蒙
●VON1 天前
Flutter 编译开发 OpenHarmony 全流程实战教程(基于 GitCode 社区项目)
flutter·openharmony·gitcode
消失的旧时光-19432 天前
Flutter 组件:Row / Column
flutter
程序员老刘2 天前
Flutter版本选择指南:3.35稳定,3.38发布 | 2025年11月
flutter·客户端
kirk_wang2 天前
Flutter 3.38和Dart 3.10中最大的更新
flutter
前端小伙计2 天前
Flutter 配置国内镜像,加速项目加载!
flutter
zonda的地盘2 天前
开发 Flutter Plugin 之 初始配置
flutter