truncateToFixedWordLength method

String truncateToFixedWordLength(
  1. int length, {
  2. String truncationIndicator = '…',
  3. TruncateAt truncateAt = TruncateAt.end,
  4. String? locale,
})

Truncates this String as necessary to ensure it contains at most length words.

// 'Some text that is…'
'Some text that is too long'.truncateToFixedWordLength(4);

See also:

Implementation

String truncateToFixedWordLength(
  int length, {
  String truncationIndicator = '…',
  TruncateAt truncateAt = TruncateAt.end,
  String? locale,
}) =>
    TruncateToFixedWordLengthTransformation(
      length: length,
      truncationIndicator: truncationIndicator,
      truncateAt: truncateAt,
    ).transform(this, locale ?? Intl.getCurrentLocale());