Flutter中设置Container宽高可直接通过width和height属性来设置:如下

Container(
  width: 100,
  height: 100,
  color: Colors.red,
  child: Text('Container固定宽高'),
)

  

有时在不确定宽高的情况下需要设置Container的最大或最小宽高,可以通过Container的constraints属性来设置,如下:

设置container最小宽高

Container(
  constraints: BoxConstraints(
    minWidth: 180,
    minHeight: 50,
  ),
  color: Colors.red,
  child: Text('Container设置最小宽高'),
)

  

设置Container最大宽高,此时超出部分溢出

Container(
  constraints: BoxConstraints(
    maxWidth: 50,
    maxHeight: 50,
  ),
  color: Colors.red,
  child: Text('Container设置最大宽高'),
)

  

 

转载于:https://www.cnblogs.com/gxsyj/p/11218362.html

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐