Skip to content

Commit

Permalink
Merge pull request #14 from MarcinusX/issue_13
Browse files Browse the repository at this point in the history
Issue 13
  • Loading branch information
MarcinusX authored May 22, 2018
2 parents 57dd6fa + 10391a5 commit e4cabc2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.1.3]

* Fixed issue with small integer ranges

## [0.1.2]

* Added environment restrictions
Expand Down
32 changes: 22 additions & 10 deletions lib/numberpicker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class NumberPicker extends StatelessWidget {
}

animateDecimalAndInteger(double valueToSelect) {
print(valueToSelect);
animateInt(valueToSelect.floor());
animateDecimal(((valueToSelect - valueToSelect.floorToDouble()) *
math.pow(10, decimalPlaces))
Expand Down Expand Up @@ -163,6 +162,7 @@ class NumberPicker extends StatelessWidget {
controller: intScrollController,
itemExtent: itemExtent,
itemCount: itemCount,
cacheExtent: _calculateCacheExtent(itemCount),
itemBuilder: (BuildContext context, int index) {
final int value = minValue + index - 1;

Expand All @@ -175,8 +175,8 @@ class NumberPicker extends StatelessWidget {
return isExtra
? new Container() //empty first and last element
: new Center(
child: new Text(value.toString(), style: itemStyle),
);
child: new Text(value.toString(), style: itemStyle),
);
},
),
),
Expand Down Expand Up @@ -212,10 +212,10 @@ class NumberPicker extends StatelessWidget {
return isExtra
? new Container() //empty first and last element
: new Center(
child: new Text(
value.toString().padLeft(decimalPlaces, '0'),
style: itemStyle),
);
child: new Text(
value.toString().padLeft(decimalPlaces, '0'),
style: itemStyle),
);
},
),
),
Expand Down Expand Up @@ -287,6 +287,17 @@ class NumberPicker extends StatelessWidget {
return true;
}

///There was a bug, when if there was small integer range, e.g. from 1 to 5,
///When user scrolled to the top, whole listview got displayed.
///To prevent this we are calculating cacheExtent by our own so it gets smaller if number of items is smaller
double _calculateCacheExtent(int itemCount) {
double cacheExtent = 250.0; //default cache extent
if ((itemCount - 2) * DEFAULT_ITEM_EXTENT <= cacheExtent) {
cacheExtent = ((itemCount - 3) * DEFAULT_ITEM_EXTENT);
}
return cacheExtent;
}

///When overscroll occurs on iOS,
///we can end up with value not in the range between [minValue] and [maxValue]
///To avoid going out of range, we change values out of range to border values.
Expand Down Expand Up @@ -410,9 +421,10 @@ class _NumberPickerDialogControllerState extends State<NumberPickerDialog> {
child: widget.cancelWidget,
),
new FlatButton(
onPressed: () => Navigator.of(context).pop(widget.decimalPlaces > 0
? selectedDoubleValue
: selectedIntValue),
onPressed: () =>
Navigator.of(context).pop(widget.decimalPlaces > 0
? selectedDoubleValue
: selectedIntValue),
child: widget.confirmWidget),
],
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: numberpicker
version: 0.1.2
version: 0.1.3
description: NumberPicker is a widget allowing user to choose numbers by scrolling spinners.
author: Marcin Szalek <[email protected]>
homepage: https://github.com/MarcinusX/NumberPicker
Expand Down

0 comments on commit e4cabc2

Please sign in to comment.