split method

List<ChatMessageText> split()

Splits this ChatMessageText equally by the maxLength characters.

Implementation

List<ChatMessageText> split() {
  if (maxLength <= 0) {
    return [];
  }

  final List<String> chunks = [];

  int start = 0;
  int end = 1;

  while (end * maxLength <= val.length) {
    chunks.add(val.substring(maxLength * start++, maxLength * end++));
  }

  final bool isRestOfLine = val.length % maxLength != 0;
  if (isRestOfLine) {
    chunks.add(
      val.substring(
        maxLength * start,
        maxLength * start + val.length % maxLength,
      ),
    );
  }

  return chunks.map((e) => ChatMessageText(e)).toList();
}