@@ -119,7 +119,6 @@ class NumberPicker extends StatelessWidget {
119
119
}
120
120
121
121
animateDecimalAndInteger (double valueToSelect) {
122
- print (valueToSelect);
123
122
animateInt (valueToSelect.floor ());
124
123
animateDecimal (((valueToSelect - valueToSelect.floorToDouble ()) *
125
124
math.pow (10 , decimalPlaces))
@@ -163,6 +162,7 @@ class NumberPicker extends StatelessWidget {
163
162
controller: intScrollController,
164
163
itemExtent: itemExtent,
165
164
itemCount: itemCount,
165
+ cacheExtent: _calculateCacheExtent (itemCount),
166
166
itemBuilder: (BuildContext context, int index) {
167
167
final int value = minValue + index - 1 ;
168
168
@@ -175,8 +175,8 @@ class NumberPicker extends StatelessWidget {
175
175
return isExtra
176
176
? new Container () //empty first and last element
177
177
: new Center (
178
- child: new Text (value.toString (), style: itemStyle),
179
- );
178
+ child: new Text (value.toString (), style: itemStyle),
179
+ );
180
180
},
181
181
),
182
182
),
@@ -212,10 +212,10 @@ class NumberPicker extends StatelessWidget {
212
212
return isExtra
213
213
? new Container () //empty first and last element
214
214
: 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
+ );
219
219
},
220
220
),
221
221
),
@@ -287,6 +287,17 @@ class NumberPicker extends StatelessWidget {
287
287
return true ;
288
288
}
289
289
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
+
290
301
///When overscroll occurs on iOS,
291
302
///we can end up with value not in the range between [minValue] and [maxValue]
292
303
///To avoid going out of range, we change values out of range to border values.
@@ -410,9 +421,10 @@ class _NumberPickerDialogControllerState extends State<NumberPickerDialog> {
410
421
child: widget.cancelWidget,
411
422
),
412
423
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),
416
428
child: widget.confirmWidget),
417
429
],
418
430
);
0 commit comments