直接上代碼:
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屬性來指定文本顏色以及前景色的混合模式