reorder method
Reorders the collection according to order, which has to be a complete
permutation of the current indices.
order[i] is the current index of the page that comes to occupy
position i.
Implementation
void reorder(List<int> order) {
if (order.length != _pages.length) {
throw PdfPageEditException(
'A nova ordem tem ${order.length} posições, e o documento tem '
'${_pages.length} páginas. reorder() exige uma permutação completa.',
);
}
final seen = <int>{};
for (final index in order) {
if (index < 0 || index >= _pages.length) {
throw RangeError.index(index, _pages, 'order', null, _pages.length);
}
if (!seen.add(index)) {
throw PdfPageEditException(
'O índice $index aparece mais de uma vez na nova ordem.',
);
}
}
final before = List<PdfPage>.of(_pages);
final reordered = <PdfPage>[for (final index in order) before[index]];
_pages
..clear()
..addAll(reordered);
_afterMutation(before);
}