本文主要介紹Flutter中非常常見的Container,列舉了一些實際例子介紹如何使用。
?1.0 組成
Container的組成如下:
- width?和?height:寬和高。
- color:背景色,值為一個 Color 對象,不能與 decoration 屬性同時設(shè)置。
-?margin:外邊距,值為一個 EdgeInsets 對象。EdgeInsets 對象即可調(diào)用EdgeInsets.all() 方法統(tǒng)一設(shè)置左上右下四條邊的邊距,也可以調(diào)用 EdgeInsets.fromLTRB() 分別設(shè)置左上右下四條邊的邊距。
-?padding:內(nèi)間距,值同 margin。
-?alignment:元素對齊方式
-?decoration:裝飾、背景顏色、邊框、背景圖片、等,不能與 color 屬性同時設(shè)置
-?child:子組件
-參數(shù) alignment:
topCenter:頂部居中對齊????topLeft:頂部左對齊?????topRight:頂部右對齊 ????center:水平垂直居中對齊 ????centerLeft:垂直居中水平居左對齊 ????centerRight:垂直居中水平居右對齊 ????bottomCenter 底部居中對齊???? bottomLeft:底部居左對齊???? bottomRight:底部居右對齊
-參數(shù)?decoration:
decoration: BoxDecoration(
????color: Colors.blue,
????border: Border.all( color: Colors.red, width: 2.0, ),
????borderRadius: BorderRadius.all( Radius.circular(8.0) )
)
?
2.0 使用
?Container參數(shù)的使用如下:
Container(?
width:?300.0,??
height:?300.0,
??padding:?EdgeInsets.all(20),
??margin:?EdgeInsets.all(20),?
? alignment:?Alignment.center,?
? decoration:BoxDecoration(?
???color:Colors.green,?
???border:Border.all(??????color:?Colors.red,??????width:?2.0????),?
???borderRadius:?BorderRadius.all(??????Radius.circular(8)????),??),?
? ?transform:?Matrix4.rotationZ(0.3),?
?),)