Search code examples
flutterflutter-layout

How to make color part of a text for UI in Flutter?


How can I change the color of part of a text? I'm trying to make it so the text says "Don't have an account? Register now!" but I want to add color to the Register now! part. How can I do this if possible?

image


Solution

  • Use RichText:

    RichText(
            text: TextSpan(
              text: "Don't have an account? ",
              style: TextStyle(color: Colors.black, fontSize: 40),
              children: <TextSpan>[
                TextSpan(text: ' Register now!', style: TextStyle(color: Colors.red)),
              ],
            ),
          );
    

    Result