splitByLength method

List<String> splitByLength(
  1. int length, {
  2. bool ignoreEmpty = false,
})

Implementation

List<String> splitByLength(int length, {bool ignoreEmpty = false}) {
  List<String> pieces = [];

  for (int i = 0; i < this.length; i += length) {
    int offset = i + length;
    String piece = substring(i, offset >= this.length ? this.length : offset);

    if (ignoreEmpty) {
      piece = piece.replaceAll(RegExp(r'\s+'), '');
    }

    pieces.add(piece);
  }
  return pieces;
}