今天我来看一下在Flutter 中实现渐变的代码片段
return new Container(
...
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [
const Color(0xFF3366FF),
const Color(0xFF00CCFF),
]
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp
),
),
),
它提出了两个问题:
1)这0xFF3366FF
个是什么 colored颜色 系统?它看起来有点像祸不单行,但它不是.
2)为什么我们用const
代替const Color()
,而不是new Color()
,我理解两者之间的不同,但是const对我来说感觉不直观,我希望它创建一个new Color()
类实例,类似于我们使用new Text("Some text")
的方式.如果需要是const,为什么TileMode.clamp
不也是const呢?