Skip to content

Commit e4cabc2

Browse files
authored
Merge pull request #14 from MarcinusX/issue_13
Issue 13
2 parents 57dd6fa + 10391a5 commit e4cabc2

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.1.3]
2+
3+
* Fixed issue with small integer ranges
4+
15
## [0.1.2]
26

37
* Added environment restrictions

lib/numberpicker.dart

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class NumberPicker extends StatelessWidget {
119119
}
120120

121121
animateDecimalAndInteger(double valueToSelect) {
122-
print(valueToSelect);
123122
animateInt(valueToSelect.floor());
124123
animateDecimal(((valueToSelect - valueToSelect.floorToDouble()) *
125124
math.pow(10, decimalPlaces))
@@ -163,6 +162,7 @@ class NumberPicker extends StatelessWidget {
163162
controller: intScrollController,
164163
itemExtent: itemExtent,
165164
itemCount: itemCount,
165+
cacheExtent: _calculateCacheExtent(itemCount),
166166
itemBuilder: (BuildContext context, int index) {
167167
final int value = minValue + index - 1;
168168

@@ -175,8 +175,8 @@ class NumberPicker extends StatelessWidget {
175175
return isExtra
176176
? new Container() //empty first and last element
177177
: new Center(
178-
child: new Text(value.toString(), style: itemStyle),
179-
);
178+
child: new Text(value.toString(), style: itemStyle),
179+
);
180180
},
181181
),
182182
),
@@ -212,10 +212,10 @@ class NumberPicker extends StatelessWidget {
212212
return isExtra
213213
? new Container() //empty first and last element
214214
: new Center(
215-
child: new Text(
216-
value.toString().padLeft(decimalPlaces, '0'),
217-
style: itemStyle),
218-
);
215+
child: new Text(
216+
value.toString().padLeft(decimalPlaces, '0'),
217+
style: itemStyle),
218+
);
219219
},
220220
),
221221
),
@@ -287,6 +287,17 @@ class NumberPicker extends StatelessWidget {
287287
return true;
288288
}
289289

290+
///There was a bug, when if there was small integer range, e.g. from 1 to 5,
291+
///When user scrolled to the top, whole listview got displayed.
292+
///To prevent this we are calculating cacheExtent by our own so it gets smaller if number of items is smaller
293+
double _calculateCacheExtent(int itemCount) {
294+
double cacheExtent = 250.0; //default cache extent
295+
if ((itemCount - 2) * DEFAULT_ITEM_EXTENT <= cacheExtent) {
296+
cacheExtent = ((itemCount - 3) * DEFAULT_ITEM_EXTENT);
297+
}
298+
return cacheExtent;
299+
}
300+
290301
///When overscroll occurs on iOS,
291302
///we can end up with value not in the range between [minValue] and [maxValue]
292303
///To avoid going out of range, we change values out of range to border values.
@@ -410,9 +421,10 @@ class _NumberPickerDialogControllerState extends State<NumberPickerDialog> {
410421
child: widget.cancelWidget,
411422
),
412423
new FlatButton(
413-
onPressed: () => Navigator.of(context).pop(widget.decimalPlaces > 0
414-
? selectedDoubleValue
415-
: selectedIntValue),
424+
onPressed: () =>
425+
Navigator.of(context).pop(widget.decimalPlaces > 0
426+
? selectedDoubleValue
427+
: selectedIntValue),
416428
child: widget.confirmWidget),
417429
],
418430
);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: numberpicker
2-
version: 0.1.2
2+
version: 0.1.3
33
description: NumberPicker is a widget allowing user to choose numbers by scrolling spinners.
44
author: Marcin Szalek <[email protected]>
55
homepage: https://github.com/MarcinusX/NumberPicker

0 commit comments

Comments
 (0)