Flutter Column 子组件高度充满(BoxConstraints forces an infinite height)

本文探讨了Flutter应用中遇到的BoxConstraints forces infinite height错误,重点在于如何在Column布局中适当地使用Expanded填充剩余空间,同时给出了自定义LoadStateLayout充满底部的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写布局遇到了一个bug,BoxConstraints forces an infinite height

2021-12-31 14:53:54.959 23302-23398/com.example.my_fllutter_test I/flutter: 错误信息1:BoxConstraints forces an infinite height.
    These invalid constraints were provided to RenderConstrainedBox's layout() function by the following function, which probably computed the invalid constraints in question:
      RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:277:14)
    The offending constraints were:
      BoxConstraints(w=360.0, h=Infinity)
2021-12-31 14:53:54.960 23302-23398/com.example.my_fllutter_test I/flutter: 错误信息2:#0      BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError (package:flutter/src/rendering/box.dart:517:9)
    #1      BoxConstraints.debugAssertIsValid.<anonymous closure> (package:flutter/src/rendering/box.dart:561:11)
    #2      BoxConstraints.debugAssertIsValid (package:flutter/src/rendering/box.dart:565:6)
    #3      RenderObject.layout (package:flutter/src/rendering/object.dart:1758:24)
    #4      RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:277:14)
    #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
    #6      ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:56:11)
    #7      RenderFlex._computeSizes (package:flutter/src/rendering/flex.dart:829:43)
    #8      RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:931:32)
    #9      RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
    #10     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart

在column中某个的组件的高度想充满整个剩余的位置,但是如果你不设置高度的话就会报以上这个错误,类似下面这种,就被报错

LoadStateLayout是我自己定义的一个加载页面,这个页面需要充满底部的高度,如何实现呢,用Expanded即可。

 

使用Expanded 包围整个的子组件,就可以撑满剩下的屏幕区域了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值