Flutter different color for different letters in a Text widget
6,756
You can do this using a RichText
widget and different TextSpan
s. You can read the documentation to familiarize yourself with it more.
https://api.flutter.dev/flutter/widgets/RichText-class.html
Comments
-
Rohan Taneja over 1 year
I have a use-case where I want to change the colour of a letter in a String inside a
Text
widget. Let's say that my String is "Flutter". On pressing theFloatingActionButton
, I want the letter 'F' to change its colour, then on the next press of theFloatingActionButton
, change the colour of letter 'l', then 'u', then 't', then 't', then 'e' and then finally 'r' with everyFloatingActionButton
press.Please don't suggest having a different
Text
widget for every letter.