Flutter Container 尺寸变化问题

官网提到

Containers with no children try to be as big as possible unless the incoming constraints are unbounded, in which case they try to be as small as possible.

意思是如果没有子元素, 并且给的constraintsunbounded的, 那么Container就会尽可能的小.

但是测试下来似乎不是这样的, 不知道是不是理解有误

body: Container(
    color: Colors.blueAccent,
    constraints: BoxConstraints(maxHeight: double.infinity, maxWidth: double.infinity),
    child: Container(
        color: Colors.redAccent,
    ),
),

上面是代码, 蓝色Container里面套了一层红色Container. 外层Container给了unbounded的constraints, 但是内层的Container任然是铺满了外层的Container.

这个是为什么? 或者说, BoxConstraints(maxHeight: double.infinity, maxWidth: double.infinity),并不是unbounded的?

阅读 3.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题