6

I am trying to ellipsis the text in Flutter app but I am not able to set it.

I design the view as below

Positioned(
            bottom: 20,
            left: 10,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  snapshot.data.results[index].title,
                  overflow: TextOverflow.ellipsis,
                  textAlign: TextAlign.start,
                  style: TextStyle(
                    fontSize: 20.0,
                    fontWeight: FontWeight.w600,
                    color: Colors.white,
                  ),
                ),
                Text(
                  snapshot.data.results[index].release_date,
                  style: TextStyle(
                      fontSize: 18.0,
                      fontWeight: FontWeight.w400,
                      color: Colors.white,
                      letterSpacing: 1.2),
                ),
              ],
            ))

Screen Shot Ellipsis

3
  • I have the same widget, but the accepted answer doesn't work. How did you do it ? Commented Sep 29, 2021 at 11:52
  • Use Expanded Widgets if flexible is not working and set text overflow. If you want to every letter go with multiline. I would suggest Commented Sep 30, 2021 at 19:23
  • 1
    I ended up using Column with mainAxisAlignment.end instead of Positioned. Thanks for replying Commented Oct 1, 2021 at 9:05

3 Answers 3

12

You should wrap your text with Flexible or Expanded widgets like below:

    Flexible(child:Text("Text goes here"),

for more info try out this link

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

1 Comment

This doesn't solve the problem at hand. It just shrinks the text and that's not what's needed. The text should be the same size and truncate the text in the manner chosen in TextOverflow. If someone asks how to get overflow to work, the answer isn't to ignore the idea of overflow and just shrink the text to make it fit.
4

I recently encountered something similar. If you inspect the constraints on the renderObject of your Text Widget using the DartDevTools, you are quite probably going to find the maxWidth constraint to be infinity. Therefore the Text Widget is not aware it is supposed to be wrapping (default behaviour) or appling ellipsis (in your case) to the text you provide.

The solution in my case was to wrap the Text Widget in an Expanded.

1 Comment

you could try to wrap the Text in a container with a fixed small width, to test whether ellipsis works in principle if the Text widget knows its maxWidth. This is no permanent solution however.
1

You shuld wrap your widget with Expanded

              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text(
                      ("Mortal Kombat"),
                      style: TextStyle(
                          color: Colors.black,
                          fontWeight: FontWeight.bold,
                          fontSize: 20),
                      overflow: TextOverflow.ellipsis,
                    ),
                    const SizedBox(
                      height: 10,
                    ),
                    Text(
                      ("12/10/2022"),
                      style:
                          TextStyle(color: Colors.black.withOpacity(0.4)),
                    ),
                    const SizedBox(
                      height: 10,
                    ),
                    const Text(
                      ("Express yourself with a custom text design created just fo`r you by a professional designer. Need ideas? We’ve collected some amazing examples of text images from our global community of designers. Get inspired and start planning the perfect text design today."),
                      // style: TextStyle(overflow: TextOverflow.ellipsis),

                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ),
              ),
            ],
          

1 Comment

It's important to not just post code, but to also include a description of what the code does and why you are suggesting it. This helps others understand the context and purpose of the code, and makes it more useful for others who may be reading the question or answer.

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.