这些天我正在练习飘动的容器,而我想出的这个例子简直令人惊讶
我把尺寸为50×50的容器放在200×200的容器内.奇怪的是内部容器扩展到200×200,即使它有50×50的严格约束.
这是代码
Container( width: 200.0,height: 200.0,color: Colors.orange,child: Container( width: 50.0,height: 50.0,color: Colors.blue,),)
我希望在一个更大的橙色盒子里面放一个小蓝盒子.
有人能解释为什么吗?
解决方法
您需要指定橙色框中您希望显示蓝色框的位置,否则蓝色框将增长到其父级的大小.
Container( width: 200.0,alignment: Alignment.center,// where to position the child child: Container( width: 50.0,