splitBlocks method
Split entries
into blocks.
Implementation
List<List<MapEntry<String, String>>> splitBlocks(
List<MapEntry<String, String>> entries) {
var cursor = 0;
var blocks = entries.splitBeforeIndexed((i, e) {
var lng = (i - cursor) + 1;
if (lng == 0) return false;
var prevLength = entries
.sublist(cursor, i + 1)
.map((e) => e.key.length + e.value.length + 2)
.sum;
if (prevLength > maxBlockLength) {
cursor = i;
return true;
} else {
return false;
}
}).toList();
return blocks;
}