直接上代码:
Container(
foregroundDecoration: BoxDecoration(
backgroundBlendMode: BlendMode.srcIn,
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: <Color>[Colors.yellow, Color(0xfffd8403), Colors.red]
),
),
child: Text(item1['title'],style: TextStyle(color:Color(0xff000000)),),
),
注:
- foregroundDecoration为Text添加一个前景修饰
- BoxDecoration的gradient属性为Text组件添加一个渐变的前景
- 通过BoxDecoration的backgroundBlendMode属性来指定文本颜色以及前景色的混合模式