splitTextAtNearestDot method

List<String> splitTextAtNearestDot(
  1. String text, {
  2. int? chunkSize = 10,
})

Implementation

List<String> splitTextAtNearestDot(String text, {int? chunkSize = 10}) {
  List<String> result = [];
  var currentChunk = [];
  var listChar = ['.', ',', ':', ';', '!', '?'];

  var words = text.split(' ');
  for (String word in words) {
    currentChunk.add(word);
    if (currentChunk.length >= chunkSize!) {
      if (containEndWith(word, listChar)) {
        result.add(currentChunk.join(' '));
        currentChunk = [];
      }
    }
  }
  if (currentChunk.isNotEmpty) {
    result.add(currentChunk.join(' '));
  }

  return result;
}