Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter richtext separated align

Tags:

i see this code for rich text in flutter:

  return Row(
        children: <Widget>[
          ?
          Container(
            child: RichText(
              text: TextSpan(
                text: "Hello",
                style: TextStyle(fontSize: 20.0,color: Colors.black),
                children: <TextSpan>[
                  TextSpan(text:"Bold"),
                    style: TextStyle( fontSize: 10.0, color: Colors.grey),

                  ),

                ],
              ),
            ),
          )

this print

Hellobold 

but i need to separe both text one aling to left other to right, like this

Hello                               bold

how i do this?

thanks

like image 716
ALEXANDER LOZANO Avatar asked Nov 03 '18 17:11

ALEXANDER LOZANO


2 Answers

I don't know your exact Use Case - But One way of getting what you require:

Row(
      children: <Widget>[
                Expanded(
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(text: 'Singh', style: TextStyle(fontSize: 22.0,color: Colors.grey))
                  ])),
                ),
                RichText(
                    text: TextSpan(children: [
                      TextSpan(text: 'Kaur', style: TextStyle(fontSize: 28.0,color: Colors.redAccent))
                    ])),
              ],
            ),
like image 126
anmol.majhail Avatar answered Nov 15 '22 06:11

anmol.majhail


if you want to use textalign in RichText use WidgetSpan and Text widget

WidgetSpan(
  child: Text(
    'your text',
    textAlign: TextAlign.left,
    textDirection: TextDirection.ltr,
  ),
),
like image 32
karzan kamal Avatar answered Nov 15 '22 06:11

karzan kamal