Skip to content

Commit 636f1b7

Browse files
authored
Make page step nullable (#62)
1 parent f49cb36 commit 636f1b7

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

lib/src/base_spin_box.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class BaseSpinBox extends StatefulWidget {
3333
double get min;
3434
double get max;
3535
double get step;
36-
double get pageStep;
36+
double? get pageStep;
3737
double get value;
3838
int get decimals;
3939
int get digits;
@@ -69,8 +69,10 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
6969
// https://github.com/flutter/flutter/issues/92717
7070
LogicalKeySet(LogicalKeyboardKey.arrowUp): _stepUp,
7171
LogicalKeySet(LogicalKeyboardKey.arrowDown): _stepDown,
72-
LogicalKeySet(LogicalKeyboardKey.pageUp): _pageStepUp,
73-
LogicalKeySet(LogicalKeyboardKey.pageDown): _pageStepDown,
72+
if (widget.pageStep != null) ...{
73+
LogicalKeySet(LogicalKeyboardKey.pageUp): _pageStepUp,
74+
LogicalKeySet(LogicalKeyboardKey.pageDown): _pageStepDown,
75+
}
7476
};
7577
}
7678

@@ -98,8 +100,8 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
98100
void _stepUp() => setValue(value + widget.step);
99101
void _stepDown() => setValue(value - widget.step);
100102

101-
void _pageStepUp() => setValue(value + widget.pageStep);
102-
void _pageStepDown() => setValue(value - widget.pageStep);
103+
void _pageStepUp() => setValue(value + widget.pageStep!);
104+
void _pageStepDown() => setValue(value - widget.pageStep!);
103105

104106
void _updateValue() {
105107
final v = _parseValue(_controller.text);

lib/src/cupertino/spin_box.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CupertinoSpinBox extends BaseSpinBox {
5252
this.min = 0,
5353
this.max = 100,
5454
this.step = 1,
55-
this.pageStep = 10,
55+
this.pageStep,
5656
this.value = 0,
5757
this.interval = const Duration(milliseconds: 100),
5858
this.acceleration,
@@ -120,11 +120,11 @@ class CupertinoSpinBox extends BaseSpinBox {
120120
@override
121121
final double step;
122122

123-
/// The page step size for incrementing and decrementing the value.
123+
/// An optional page step size for incrementing and decrementing the value.
124124
///
125-
/// Defaults to `10.0`.
125+
/// Defaults to `null`.
126126
@override
127-
final double pageStep;
127+
final double? pageStep;
128128

129129
/// The current value.
130130
///

lib/src/material/spin_box.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SpinBox extends BaseSpinBox {
5353
this.min = 0,
5454
this.max = 100,
5555
this.step = 1,
56-
this.pageStep = 10,
56+
this.pageStep,
5757
this.value = 0,
5858
this.interval = const Duration(milliseconds: 100),
5959
this.acceleration,
@@ -118,11 +118,11 @@ class SpinBox extends BaseSpinBox {
118118
@override
119119
final double step;
120120

121-
/// The page step size for incrementing and decrementing the value.
121+
/// An optional page step size for incrementing and decrementing the value.
122122
///
123-
/// Defaults to `10.0`.
123+
/// Defaults to `null`.
124124
@override
125-
final double pageStep;
125+
final double? pageStep;
126126

127127
/// The current value.
128128
///

test/cupertino_spinbox_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ void main() {
2121
});
2222

2323
testInput<CupertinoSpinBox>(() {
24-
return TestApp(widget: CupertinoSpinBox(value: 1, autofocus: true));
24+
return TestApp(
25+
widget: CupertinoSpinBox(
26+
value: 1,
27+
autofocus: true,
28+
pageStep: 10,
29+
),
30+
);
2531
});
2632

2733
testInput<CupertinoSpinBox>(() {
@@ -30,6 +36,7 @@ void main() {
3036
value: 1,
3137
autofocus: true,
3238
focusNode: FocusNode(),
39+
pageStep: 10,
3340
),
3441
);
3542
});

test/material_spinbox_test.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ void main() {
2222
});
2323

2424
testInput<SpinBox>(() {
25-
return TestApp(widget: SpinBox(value: 1, autofocus: true));
25+
return TestApp(widget: SpinBox(value: 1, autofocus: true, pageStep: 10));
2626
});
2727

2828
testInput<SpinBox>(() {
2929
return TestApp(
30-
widget: SpinBox(value: 1, autofocus: true, focusNode: FocusNode()),
30+
widget: SpinBox(
31+
value: 1,
32+
autofocus: true,
33+
focusNode: FocusNode(),
34+
pageStep: 10,
35+
),
3136
);
3237
});
3338

0 commit comments

Comments
 (0)