Ravi Parmar
Ravi Parmar

Reputation: 1018

How to align text center in Text.rich()

I am using a text span widget in which I like to center all the text, instead of default alignment at the start.

 Text.rich(
                          TextSpan(
                            text: "Go to your e-mail inbox and ",
                            style: TextStyle(
                                color: appBackground_color,
                                fontSize: 14,
                                fontWeight: FontWeight.w500),
                            children: <InlineSpan>[
                              TextSpan(
                                text: "activate your account",
                                style: TextStyle(
                                  fontSize: 14,
                                  fontWeight: FontWeight.w700,
                                  color: appBackground_color,
                                ),
                              ),
                              TextSpan(
                                text: " to proceed.",
                                style: TextStyle(
                                    fontSize: 14,
                                    fontWeight: FontWeight.w500,
                                    color: appBackground_color),
                              ),
                            ],
                          ),
                        ),

How can i center the text in this widget?

Upvotes: 1

Views: 1134

Answers (1)

zeed
zeed

Reputation: 305

Use RichText() instead of Text.rich(). Text.rich() has no textAlign parameter. Use like this:

RichText(
          textAlign: TextAlign.center,
          text: TextSpan(
            text: "Go to your e-mail inbox and ",
            children: <InlineSpan>[
              TextSpan(),
              TextSpan(),
            ],
          ),
        ),

But remember, RichText() must have a width for the textAlign to work. Like this:

 Container(
              width: double.infinity,
              child: RichText(
               //**
              ),
            ),

Upvotes: 4

Related Questions