Last active
November 24, 2020 16:08
-
-
Save talamaska/6690485898c552989e227e192715131f to your computer and use it in GitHub Desktop.
text with gradient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final colors = [ | |
Color(0xffff0000), Color(0xffffff00), Color(0xff00ff00), | |
Color(0xff00ffff), Color(0xff0000ff), Color(0xffff00ff), Color(0xffff0000), | |
]; | |
final colorStops = [0 / 6, 1 / 6, 2 / 6, 3 / 6, 4 / 6, 5 / 6, 6 / 6]; | |
final gradient = new ui.Gradient.linear( | |
Offset(0.0, 0.0), | |
Offset(0.0, size.height), | |
colors, | |
colorStops, | |
); | |
final gradientPaint = new Paint()..shader = gradient; | |
final paragraphStyle = new ui.ParagraphStyle( | |
fontSize: 60.0, | |
textAlign: TextAlign.center, | |
); | |
final paragraphBuilder = new ui.ParagraphBuilder(paragraphStyle) | |
..pushStyle(new ui.TextStyle(foreground: gradientPaint)) | |
..addText('TEST'); | |
final paragraph = paragraphBuilder.build(); | |
paragraph.layout(new ui.ParagraphConstraints(width: size.width / 2)); | |
final offset1 = new Offset(size.width * 0.5, size.height * 0.33); | |
canvas.drawParagraph(paragraph, offset1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment