@@ -15,7 +15,7 @@ class NumberPicker extends StatefulWidget {
15
15
final int value;
16
16
17
17
/// Called when selected value changes
18
- final ValueChanged <int > onChanged;
18
+ final ValueChanged <int >? onChanged;
19
19
20
20
/// Specifies how many items should be shown - defaults to 3
21
21
final int itemCount;
@@ -61,7 +61,7 @@ class NumberPicker extends StatefulWidget {
61
61
required this .minValue,
62
62
required this .maxValue,
63
63
required this .value,
64
- required this .onChanged,
64
+ this .onChanged,
65
65
this .itemCount = 3 ,
66
66
this .step = 1 ,
67
67
this .itemHeight = 50 ,
@@ -110,9 +110,11 @@ class _NumberPickerState extends State<NumberPicker> {
110
110
_intValueFromIndex (indexOfMiddleElement + additionalItemsOnEachSide);
111
111
112
112
if (widget.value != intValueInTheMiddle) {
113
- widget.onChanged (intValueInTheMiddle);
114
- if (widget.haptics) {
115
- HapticFeedback .selectionClick ();
113
+ if (widget.onChanged != null ) {
114
+ widget.onChanged !(intValueInTheMiddle);
115
+ if (widget.haptics) {
116
+ HapticFeedback .selectionClick ();
117
+ }
116
118
}
117
119
}
118
120
Future .delayed (
@@ -166,6 +168,7 @@ class _NumberPickerState extends State<NumberPicker> {
166
168
children: [
167
169
if (widget.infiniteLoop)
168
170
InfiniteListView .builder (
171
+ physics: widget.onChanged == null ? NeverScrollableScrollPhysics () : BouncingScrollPhysics (),
169
172
scrollDirection: widget.axis,
170
173
controller: _scrollController as InfiniteScrollController ,
171
174
itemExtent: itemExtent,
@@ -174,6 +177,7 @@ class _NumberPickerState extends State<NumberPicker> {
174
177
)
175
178
else
176
179
ListView .builder (
180
+ physics: widget.onChanged == null ? NeverScrollableScrollPhysics () : BouncingScrollPhysics (),
177
181
itemCount: listItemsCount,
178
182
scrollDirection: widget.axis,
179
183
controller: _scrollController,
@@ -215,11 +219,13 @@ class _NumberPickerState extends State<NumberPicker> {
215
219
return InkWell (
216
220
onTap: () {
217
221
if (! isExtra) {
218
- widget.onChanged (value);
219
- Future .delayed (
220
- const Duration (milliseconds: 100 ),
221
- () => _maybeCenterValue (),
222
- );
222
+ if (widget.onChanged != null ) {
223
+ widget.onChanged !(value);
224
+ Future .delayed (
225
+ const Duration (milliseconds: 100 ),
226
+ () => _maybeCenterValue (),
227
+ );
228
+ }
223
229
}
224
230
},
225
231
child: Container (
0 commit comments