flutter richtext separated align

Viewed 19694

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

3 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))
                    ])),
              ],
            ),

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

WidgetSpan(
  child: Text(
    'your text',
    textAlign: TextAlign.left,
    textDirection: TextDirection.ltr,
  ),
),

I think this will can help you:

RichText(
  text: TextSpan(
    children: [
      WidgetSpan(
        child: Padding(
          padding: const EdgeInsets.fromLTRB(1, 10, 10, 0),
          child: Icon(
            Icons.developer_mode_sharp,
          ),
        ),
      ),
      TextSpan(
        text: '  Tinkle is Powered By:',
        style: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.bold,
            color: Colors.black),
      ),
    ],
  ),
),
Text(
  'Together Marketing Agency',
  textAlign: TextAlign.right,
  style: TextStyle(
      fontSize: 16, color: Colors.black, fontWeight: FontWeight.w500),
),
Related