Skip to content

Commit

Permalink
Clamp index if not infinite loop picker
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieupost committed Jan 14, 2019
1 parent 099eddd commit d6f09ae
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/numberpicker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ class NumberPicker extends StatelessWidget {
//calculate
int intIndexOfMiddleElement = (notification.metrics.pixels / itemExtent)
.round();
if (!infiniteLoop) {
intIndexOfMiddleElement =
intIndexOfMiddleElement.clamp(0, integerItemCount - 1);
}
int intValueInTheMiddle = _intValueFromIndex(intIndexOfMiddleElement + 1);
intValueInTheMiddle = _normalizeIntegerMiddleValue(intValueInTheMiddle);

Expand Down

0 comments on commit d6f09ae

Please sign in to comment.