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: [
///
]
))
相关推荐
星释6 小时前
鸿蒙Flutter三方库适配指南:08.联合插件开发
flutter·华为·harmonyos
星释6 小时前
鸿蒙Flutter三方库适配指南:06.插件适配原理
flutter·华为·harmonyos
小蜜蜂嗡嗡6 小时前
【flutter报错:Build failed due to use of deprecated Android v1 embedding.】
android·flutter·embedding
安卓开发者7 小时前
第3讲:创建并运行你的第一个Flutter应用
flutter
GBVFtou8 小时前
flutter写后感 构建您的第一个 Flutter 应用
flutter
2501_9389639610 小时前
Flutter 3.19 桌面应用开发:适配 Windows/macOS 端窗口大小与菜单栏自定义
windows·flutter·macos
星释11 小时前
鸿蒙Flutter三方库适配指南:07.插件开发
flutter·华为·harmonyos
SoaringHeart1 天前
Flutter疑难解决:单独让某个页面的电池栏标签颜色改变
前端·flutter
西西学代码1 天前
Flutter---个人信息(3)---实现修改性别
flutter
西西学代码1 天前
Flutter---ListTile列表项组件
flutter