Flutter設置Container的最大最小寬高


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設置最大寬高'),
)

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM