flutter RichText, TextSpan align

2.2k views Asked by At

this is my code

RichText(
          text: TextSpan(children: [
            TextSpan(
                text: 'flutterABC',
                style: TextStyle(
                    fontSize: isDesktop(context) ? 64 : 32,
                    fontWeight: FontWeight.w800)),
            TextSpan(
                text: 'flutterABC',
                style: TextStyle(
                    fontSize: isDesktop(context) ? 64 : 32,
                    fontWeight: FontWeight.w800,
                    color: Colors.indigo))
          ]),
        ),

like this. i use RichText and TextSpan. when i run in chrome, i can't control align if 'flutterABCflutterABC' is one line > align is center. but if two line > align is start..

i want to always align center how can i do? enter image description here

enter image description here

2

There are 2 answers

1
Ananda Pramono On

Try this please

             RichText(
                text: TextSpan(
                    children:[
                  TextSpan(
                      text: 'flutterABC\n',
                      style: TextStyle(
                          fontWeight: FontWeight.w800)),
                  TextSpan(
                      text: 'flutterABC',
                      style: TextStyle(
                          fontWeight: FontWeight.w800,
                          color: Colors.indigo))
                ]),
              ),
0
Abd Alazeez On

you can use Column to this effect but if you went to use RichText you can use \n for newline