Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 561
overdeveloping Avatar asked Apr 20 '19 22:04

overdeveloping


People also ask

How do you color specific text in Flutter?

Step 1: Locate the file where you have placed the Text widget. Step 2: Inside the Text widget, add the Style parameter and assign the TextStyle widget. Step 3: Inside the TextStyle widget, add the color parameter and set the color of your choice. For example, color: Colors.

How do you change the text color in theme Flutter?

Steps to change theme text color in Flutter You can change theme text color in Flutter, by defining the TextTheme (inside MaterialApp) and then adding headings type. For example, headline1 , headline2 , BodyText1 , and so on. After that, you can assign the TextStyle widget with the color of your choice.

How do I make part of text bold Flutter?

Flutter – Text Widget – Bold To display bold text in Text widget in Flutter, set font weight to bold in style property for the Text widget.

How do you change the color of the underline in text flutters?

To change TextField underline color in Flutter, add styling to the TextField widget. Basically, you provide the styling instructions by using the InputDecoration widget with the required parameters.


1 Answers

Use RichText https://docs.flutter.io/flutter/widgets/RichText-class.html

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

like image 99
Doc Avatar answered Oct 22 '22 17:10

Doc