5

I can't get this to layout properly.

I'm trying to achieve

Attached an image to explain what I'm trying to achieve

This is what I tried so far that gets me the closest to it but isn't exactly right.

  Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
    Flexible(
      child: Row(children: [
        PrefixIcon(),
        Flexible(
          child: DefaultTextStyle(
            overflow: TextOverflow.ellipsis,
            child: TextGoesHere(),
          ),
        ),
        SuffixIcon(),
      ]),
    ),
    TrailingIcon(),
  ]),

But Flexible with FlexFit.loose acts like Expanded so the SuffixIcon gets pushed to the end even though TextGoesHere is a short text.

I got so far

I got so far

Please help.

1 Answer 1

5

If you consider ..from TextOverflow.ellipsis, this I've got so far with row.

color container just for visual

enter image description here

Widget

 Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text("Prefix"),
            Expanded(
              child: Container(
                color: Colors.deepOrange,
                child: Row(
                  children: [
                    Flexible(
                      child: Text(
                        "Very LongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggText",
                        maxLines: 1,
                      ),
                    ),
                    Icon(
                      Icons.tag_sharp,
                    )
                  ],
                ),
              ),
            ),
            Text("TrailingIcon"),
          ],
        ),

Else, we can use LayoutBuilder if we know the prefix and Icons size.

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

2 Comments

Hey thanks, I tried your answer but it looked exactly like what I got so far. So I tried it in dartpad and it seems like it works great there. I'll accept the answer but I'm still lost as to why it won't work in my codebase.
Got it. It was because of Alignment I had. Thanks for your help!

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.