loopIndex static method
Loop an index to an range of a specif length (index: 3 ,length: 5) => 3 (index: 5 ,length: 5) => 0 (index: 7 ,length: 5) => 2 (index should be negative)
Implementation
static int loopIndex(int index, int length) {
assert(index >= 0, 'index should not be less than 0');
assert(length > 0, 'length should be greater than 0');
final division = index / length;
return (division.decimalPart() * length).round();
}