Flutter的Builder生成彩虹Text

Builder(
              builder: (context) {
                RenderBox box = context.findRenderObject();
                final Shader radialGradient =
                    RadialGradient(colors: [Colors.orangeAccent, Colors.cyan],tileMode: TileMode.repeated)
                        .createShader(Rect.fromLTWH(
                            0.0, 0.0, box?.size?.width, box?.size?.height));
                final Shader linearGradient =
                LinearGradient(colors: [Colors.orangeAccent, Colors.cyan])
                    .createShader(Rect.fromLTWH(
                    0.0, 0.0, box?.size?.width, box?.size?.height));
                return Text(
                  "我是一名Flutter初学者,请多多关照!",
                  style: TextStyle(
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                      foreground: Paint()..shader = radialGradient),//linearGradient
                );
              },
            ),
image.png

你可能感兴趣的:(Flutter的Builder生成彩虹Text)