Gradient Text in Flutter

后端 未结 2 1493
南旧
南旧 2021-02-03 10:58

I was wondering if it is possible to create a gradient over text Flutter. There is a gist of text gradient using Dart\'s ui, but it is kinda long and I was hoping to be simpler.

2条回答
  •  自闭症患者
    2021-02-03 11:45

    Taken from here, you can use Text's style painter.

    Create the shader,

    final Shader linearGradient = LinearGradient(
      colors: [Color(0xffDA44bb), Color(0xff8921aa)],
    ).createShader(Rect.fromLTWH(0.0, 0.0, 200.0, 70.0));
    

    then use it in the TextStyle's foreground

      Text(
            'Hello Gradients!',
            style: new TextStyle(
                fontSize: 60.0,
                fontWeight: FontWeight.bold,
                foreground: Paint()..shader = linearGradient),
          )
    

    Source code

提交回复
热议问题