1

I am trying to use space between to separate two Text widgets but none of mainAxisAlignment options works. Screenshot of code below.

enter image description here

In the picture, you can see Text2 and Text3 are glued together I want them separated. First child in main Row needs to be expanded 1. Second (the problematic one) needs to be like expanded 0.

Container(
  color: Colors.blue,
  child: Row(
    children: [
      Expanded(
        child: Container(
          color: Colors.orange,
          child: Text('Text1'),
        ),
        flex: 1,
      ),
      Column(
        children: [
          Row(
            children: [Text('Text2'), Text('Text3')],
          ),
          Text('Long text Long text Long text'),
        ],
      )
    ],
  ),
)

3 Answers 3

2

so I realized you used Expanded widget for the first child but not for the second. Also, you need to add mainAxisAlignment: MainAxisAlignment.spaceBetween to the Row widget. Below is a complete code for what you want to achieve.

Container(
    color: Colors.blue,
    child: Row(
        children: [
            Expanded(
                child: Container(
                    color: Colors.orange,
                    child: Text('Text1'),
                ),
                flex: 1,
            ),
            Expanded(
                child: Column(
                    children: [
                        Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                                Text('Text2'),
                                Text('Text3')
                            ],
                        ),
                        Text('Long text Long text Long text'),
                    ],
                ),
            )
        ],
    ),
)

Desired outcome!

Sign up to request clarification or add additional context in comments.

Comments

0

Use mainAxisAlignment to spaceBetween

 Row(
      mainAxisAlignment:MainAxisAlignment.spaceBetween,
      children: [Text('Text2'), Text('Text3')],
     ),

1 Comment

It doesn't work. None of the mainAxisAlignment options works. Maby is the way flutter calculate Text widgets?
0

Use Spacer() between two Text.

Text("Text2"), 
Spacer(), 
Text("Text3")

3 Comments

This throws some layout error. I ended up using IntrinsicWidth on Column widget.
Try to avoid IntrinsicWidth as much as possible.
Read that in doc :) but really have no idea what use instead to get desired design.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.