容器組件(Container)

容器組件(Container)是一個組合Widget,內部有繪製Widget、定位Widget和尺寸Widget,包含一個子Widget,自身具備如alignment、pading等基礎屬性,方便佈局過程中擺放child。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.infinity可以強制在高度上撐滿

constraints

BoxConstraints

    添加到child上額外的約束條件

margin

EdgeInsetsGeometry

    圍繞在Decoration和child之外的空白區域,不屬於內容區域

transform

Matrix4

    設置Container的變換矩陣,類型爲Matrix4

child

Widget

    Container中的內容Widget

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