Flutter 容器組件Container

容器組件Container包含一個子Widget,自身具備如下alignment、padding等基礎屬性,方便佈局過程中擺放child。Container組件常用屬性如下: 

Container組件的屬性及描述
屬性名 類型 說明
key Key container唯一標識符,用於查找更新
alignment AlignmentGeometry 控制child的對齊方式,如果Container或Container父節點尺寸大於child的尺寸,這個屬性設置會起作用,有很多對齊方式
padding EdgeInsetsGeometry Decoration內部的空白區域,如果有child的話,child位於padding內部
color Color 用來設置Container背景色,如果foregroundDecoration設置的話,可能會遮蓋color效果
decoration Decoration 繪製在child後面的裝飾,設置了decoration的話,就不能設置color屬性,否則會報錯,此時應該在Decoration中進行顏色的設置
foregroundDecoration Decoration 繪製在child前面的裝飾
width double Container的寬度,設置爲double.infinity可以強制在寬度上撐滿,不設置,則根據child和父節點兩者一起佈局
height double Container的高度,設置爲double.infiiity可以強制在高度上撐滿
constraints BoxConstraints 添加在child上額外的約束
margin EdgeInsetsGeometry 圍繞在Decoration和child之外的空白區域,不屬於內容區域
transform Matrix4 設置Container的變換矩陣,類型爲Matrix4
child Widget Container中的內容Widget

 

注意:padding與margin的不同之處在於,padding是包含在content內,而margin則是外部邊界。設置點擊事件的話,padding區域會響應,而margin區域不會響應

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章