autoWrap method

List<String> autoWrap(
  1. int maxLength
)

Implementation

List<String> autoWrap(int maxLength) {
  final result = <String>[];
  final words = split(' ');
  final buffer = StringBuffer();
  for (final w in words) {
    if (buffer.isNotEmpty && buffer.length + 1 + w.length >= maxLength) {
      result.add(buffer.toString());
      buffer.clear();
    }
    if (buffer.isNotEmpty) buffer.write(' ');
    buffer.write(w);
    if (identical(w, words.last) && buffer.isNotEmpty) {
      result.add(buffer.toString());
      buffer.clear();
    }
  }
  return result;
}