data_table_2
data_table_2 copied to clipboard
Off-by-one error in goToPageWithRow()
Specifically, in _alignRowIndex():
https://github.com/maxim-saplin/data_table_2/blob/879f9baa25751dd928d2cc8511d95d519cd551bb/lib/src/paginated_data_table_2.dart#L596-L598
We'd expect that _alignRowIndex(9, 10) would return 0, but instead we get 10:
((rowIndex + 1) ~/ rowsPerPage) * rowsPerPage
= ((9 + 1) ~/ 10) * 10
= (10 ~/ 10) * 10
= 1 * 10
= 10
So attempting to go to the page containing the last row for that page actually puts us on the page after the one we'd expect.
My workaround — to preserve some sort of forward-compatibility once this is fixed — is to subtract 1 from rowIndex before passing it into goToPageWithRow(), but only if (rowIndex - 1) % rowsPerPage == 0. Basically: if (and only if) we're on the index that would cause the error, then we pretend we're on the index before it.