body:Center(
child: Container(
color: Colors.blue,
width: 400,
height: 200,
decoration:new BoxDecoration(
gradient: const LinearGradient(
colors: [
Colors.amber,
Colors.cyanAccent
])
)
),
)
如上面寫法,在調試的時候會出現下面的報錯。
Cannot provide both a color and a decoration
The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".
'package:flutter/src/widgets/container.dart':
Failed assertion: line 319 pos 15: 'color == null || decoration == null'
報錯中告訴我們color屬性和decoration 是不能同時存在的,一次我們需要把color移除即可。