shorten function Null safety

String shorten(
  1. String text,
  2. int width,
  3. {int maxLines = 1,
  4. String initialIndent = '',
  5. String subsequentIndent = '',
  6. bool expandTabs = true,
  7. bool replaceWhitespace = true,
  8. bool fixSentenceEndings = false,
  9. bool breakLongWords = true,
  10. bool dropWhitespace = true,
  11. bool breakOnHyphens = true,
  12. int tabSize = 8,
  13. String placeholder = ' ...'}
)

Collapse and truncate the given text to fit in the given width.

Implementation

String shorten(String text, int width,
    {int maxLines = 1,
    String initialIndent = '',
    String subsequentIndent = '',
    bool expandTabs = true,
    bool replaceWhitespace = true,
    bool fixSentenceEndings = false,
    bool breakLongWords = true,
    bool dropWhitespace = true,
    bool breakOnHyphens = true,
    int tabSize = 8,
    String placeholder = ' ...'}) {
  var wrapper = TextWrapper(
      width: width,
      initialIndent: initialIndent,
      subsequentIndent: subsequentIndent,
      expandTabs: expandTabs,
      replaceWhitespace: replaceWhitespace,
      fixSentenceEndings: fixSentenceEndings,
      breakLongWords: breakLongWords,
      dropWhitespace: dropWhitespace,
      breakOnHyphens: breakOnHyphens,
      tabSize: tabSize,
      maxLines: maxLines,
      placeholder: placeholder);
  return wrapper.fill(text.split(RegExp('\\s+')).join(' '));
}