今天遇到一个布局报错BoxConstraints forces an infinite width.

布局如图所示:Flutter报错:BoxConstraints forces an infinite width.

我把报错信息也贴一下:

Flutter报错:BoxConstraints forces an infinite width.

在这里我们要注意,当Stack中使用Positioned的时候,要注意限制Positioned宽度为具体宽度,不能设置double.infinity之类的,

解决方法:1.如果能用Align替代 使用Align  我这里解决办法就是使用Align替代,

Flutter报错:BoxConstraints forces an infinite width.

2.给如果要宽度充满父Widget,可以给Postioned限制left:0,right:0,这样就充满父Widget 而且不会报错

Flutter报错:BoxConstraints forces an infinite width.

相关文章: