Home > Net >  Flutter: How do I create a line of text where one String goes to the end of the line while the other
Flutter: How do I create a line of text where one String goes to the end of the line while the other

Time:02-28

I'm working on a flutter app, where I have some text in a Text widget. The text has two components, one word, and one number. I want to format it such that the word appears at the beginning of the line, but the number goes to the end of the line. For instance, assuming the box below spans the whole screen:

Word 1 Num

I want this to be dynamic, so that no matter what your screen size, the word and the number go to opposite ends of the line. The only solution I could find was using padRight, but I'm not sure how to make it dynamic since the I'm not sure how to set the width parameter. Is there a way for me to map the screen width to the number of characters in a line? Or any other tool I'm missing?

My current solution is something like this:

Text(
" "   name   ":".padRight(32)   number,
)

This clearly doesn't work because I chose 32 arbitrarily and it won't dynamically change.

Appreciate any help, thanks!!

CodePudding user response:

Try below code, you use enter image description here

CodePudding user response:

    Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween
      children: [
           Text("Word 1"),
           Text("Num"),
      ]
    )

CodePudding user response:

**Try like this **

Container(
    margin: const EdgeInsets.all(10.0),
   decoration: BoxDecoration(
     borderRadius: BorderRadius.circular(8.0),
     color: Colors.black26,
   ),
    child: const ListTile(
      title: Text("Word 1"),
      trailing: Text("Num"),
    ),
  )

it will work perfectly all devices

  • Related