skip to Main Content

I’m using TextOverflow.ellipsis and have the following issue:

Text(
    'This is an example of a string that needs an ellipses',
    overflow: TextOverflow.ellipsis,
  )

Obviously it depends on the size of the Text widget and the font, etc, but when given the correct parameters the result will look like:

'This is an example of a string ...'

where I want it to look like this, ignoring the final blank space:

'This is an example of a string...'

Would appreciate any ideas how this might be achieved.

2

Answers


  1. By using inputText.trim(), you ensure that any leading or trailing whitespace is removed from the string before it is displayed in the Text widget with TextOverflow.ellipsis. This will result in the desired output where the ellipsis follows the last non-whitespace character without any extra spaces.

    String inputText = 'This is an example of a string that needs an ellipses';
    
    inputText = inputText.trim(); // Remove leading and trailing whitespace
    
    Text(
      inputText,
      overflow: TextOverflow.ellipsis,
    )
    
    Login or Signup to reply.
  2. Text(
      title,
      style: TextStyle(
        color: color ?? Colors.black,
        fontSize: 18,
        fontWeight: fontWeight,
      ),
      maxLines: maxLines,
      softWrap: false,
      overflow: TextOverflow.ellipsis,
      textAlign: TextAlign.left,
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search