满怀信心使用Column进行布局,总会遇到各种各样异常,有的直接报错,有的表现形式和预想的不同。下面直接分场景归纳并解决Column中的问题(大多数布局问题都有Column这货参与):
1.Column中嵌套Column,外层Column直接撑满屏幕,而内层Column只是刚好为子元素高度(子元素没有Flexible类型组件)
2.Column中嵌套Column,内层Column有Expanded,直接抛出异常
3.Scroll类型组件中嵌套Column,Column只是刚好为子元素高度(子元素没有Flexible类型组件),和场景一表现一致
4.Scroll类型组件中嵌套Column,内层Column有Expanded,直接抛出异常,报错和场景二一致
1、3,2、4场景极为相似,阅读源码后发现原因都是
场景2,4报错信息总结为一句话:
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
什么时unbounded的constraints?,源码告诉我们:“An axis whose maximum constraint is infinite is _unbounded_.”,也就是maxHight为无限大,这会引发什么现象?源码中又有透露:
“it gives them unbounded constraints so that they can determine their own dimensions (passing unbounded constraints usually s