使用flutter 的deoration時報錯, 提醒:deoration和 color: 背景顏色不能共存,二者同時只能有一個
decoration可以設置邊框、背景色、背景圖片、圓角等屬性,非常實用。對於transform這個屬性,一般有過其他平臺開發經驗的,都大致瞭解,這種變換,一般不是變換的實際位置,而是變換的繪製效果,也就是說它的點擊以及尺寸、間距等都是按照未變換前的。
demo
new Container(
constraints: new BoxConstraints.expand(
height:Theme.of(context).textTheme.display1.fontSize * 1.1 + 200.0,
),
decoration: new BoxDecoration(
border: new Border.all(width: 2.0, color: Colors.red),
color: Colors.grey,
borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
image: new DecorationImage(
image: new NetworkImage('http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg'),
centerSlice: new Rect.fromLTRB(270.0, 180.0, 1360.0, 730.0),
),
),
padding: const EdgeInsets.all(8.0),
alignment: Alignment.center,
child: new Text('Hello World',
style: Theme.of(context).textTheme.display1.copyWith(color: Colors.black)),
transform: new Matrix4.rotationZ(0.3),
)
tips
color:用來設置container背景色,如果foregroundDecoration設置的話,可能會遮蓋color效果。
decoration:繪製在child後面的裝飾,設置了decoration的話,就不能設置color屬性,否則會報錯,此時應該在decoration中進行顏色的設置。
foregroundDecoration:繪製在child前面的裝飾。