為您解碼網(wǎng)站建設(shè)的點(diǎn)點(diǎn)滴滴
發(fā)表日期:2018-12 文章編輯:小燈 瀏覽次數(shù):2551
在 Flutter 中的組件樣式,都是通過(guò)組件上的 style 屬性進(jìn)行設(shè)置的,這與 React Native 很類似。
例如,在 Text 組件里設(shè)置樣式。
new Text('Hello', style: new TextStyle( fontSize: 24.0, fontWeight: FontWeight.w900, fontFamily: "Georgia", ) );
與 React Native 不同的是,有一些樣式不不能在 style 里面設(shè)置的。例如 width,height,color 等屬性。因?yàn)?Flutter 認(rèn)為這樣應(yīng)該是組件的屬性而不是樣式。
new Text( 'Hello', style: new TextStyle( fontSize: 24.0, fontWeight: FontWeight.w900, fontFamily: "Georgia", ), textAlign: TextAlign.center, )
var container = new Container( width: 320.0, height: 240.0, );
邊距只要是 padding(內(nèi)邊距) 和 margin(外邊距)兩個(gè)設(shè)置。邊距只適用于 Container。
new Container( padding: new EdgeInsets.all(20.0), // padding: 20px;padding: new EdgeInsets.only(left: 30.0, right: 0.0, top: 20.0, bottom: 20.0), // padding-left: 30px; // padding-right: 0; // padding-top: 20px; // padding-bottom: 20px;padding: new EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0), // padding: 10px 20px;// 同理,對(duì)于 margin 也是一樣 margin: new EdgeInsets.all(20.0), )
如果要使用絕對(duì)定位,那么需要把內(nèi)容包裹在 Positioned 容器里,而 Positioned 又需要包裹在 Stack 容器里。
var container = new Container( child: new Stack( children: [ new Positioned( child:new Container( child: new Text("Lorem ipsum"), ), left: 24.0, top: 24.0, ), ], ), width: 320.0, height: 240.0, );
容器的邊框設(shè)置,使用 Border 對(duì)象。邊框只適用于 Container。
decoration: new BoxDecoration( color: Colors.red[400], // 這里設(shè)置 border: new Border.all(width: 2.0, style: BorderStyle.solid), ),
要設(shè)置容器的圓角,使用 BorderRadius 對(duì)象,它只能使用于 Container。
new Container( decoration: new BoxDecoration( color: Colors.red[400], // 這里設(shè)置 borderRadius: new BorderRadius.all( const Radius.circular(8.0), ), ), padding: new EdgeInsets.all(16.0), ),
BorderRadius
有以下的屬性與方法。
在 Flutter 里設(shè)置陰影效果,需要使用 BoxShadow 對(duì)象。陰影效果只適用于 Container。
decoration: new BoxDecoration( color: Colors.red, boxShadow: <BoxShadow>[ new BoxShadow ( offset: new Offset(0.0, 2.0), // (x, y) blurRadius: 4.0, color: const Color(0xcc000000), ), new BoxShadow ( offset: new Offset(0.0, 6.0), blurRadius: 20.0, color: const Color(0x80000000), ), ], ),
等效于 css 上的陰影效果設(shè)置。
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 6px 20px rgba(0, 0, 0, 0.5);