flutter文字漸變

直接上代碼:

   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屬性來指定文本顏色以及前景色的混合模式
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章