wrapText static method

  1. @Deprecated('will return List<String> in next major version')
String wrapText(
  1. String text,
  2. int maxWidth,
  3. int charSpacing
)

Implementation

@Deprecated('will return List<String> in next major version')
static String wrapText(String text, int maxWidth, int charSpacing) {
  List<String> lines = text.split("\n");
  String output = "";

  for (String line in lines) {
    if (getTextWidth(line, charSpacing) <= maxWidth) {
      output += "$line\n";
    } else {
      String thisLine = "";
      List<String> words = line.split(" ");
      for (String word in words) {
        if (getTextWidth("$thisLine $word", charSpacing) > maxWidth) {
          output += "$thisLine\n";
          thisLine = word;
        } else if (thisLine.isEmpty) {
          thisLine = word;
        } else {
          thisLine += " $word";
        }
      }
      if (thisLine.isNotEmpty) {
        output += "$thisLine\n";
      }
    }
  }
  return output.trimRight();
}