Skip to content

Commit

Permalink
Make page step nullable (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi authored Jul 27, 2022
1 parent f49cb36 commit 636f1b7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
12 changes: 7 additions & 5 deletions lib/src/base_spin_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class BaseSpinBox extends StatefulWidget {
double get min;
double get max;
double get step;
double get pageStep;
double? get pageStep;
double get value;
int get decimals;
int get digits;
Expand Down Expand Up @@ -69,8 +69,10 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
// https://github.com/flutter/flutter/issues/92717
LogicalKeySet(LogicalKeyboardKey.arrowUp): _stepUp,
LogicalKeySet(LogicalKeyboardKey.arrowDown): _stepDown,
LogicalKeySet(LogicalKeyboardKey.pageUp): _pageStepUp,
LogicalKeySet(LogicalKeyboardKey.pageDown): _pageStepDown,
if (widget.pageStep != null) ...{
LogicalKeySet(LogicalKeyboardKey.pageUp): _pageStepUp,
LogicalKeySet(LogicalKeyboardKey.pageDown): _pageStepDown,
}
};
}

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

void _pageStepUp() => setValue(value + widget.pageStep);
void _pageStepDown() => setValue(value - widget.pageStep);
void _pageStepUp() => setValue(value + widget.pageStep!);
void _pageStepDown() => setValue(value - widget.pageStep!);

void _updateValue() {
final v = _parseValue(_controller.text);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/cupertino/spin_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CupertinoSpinBox extends BaseSpinBox {
this.min = 0,
this.max = 100,
this.step = 1,
this.pageStep = 10,
this.pageStep,
this.value = 0,
this.interval = const Duration(milliseconds: 100),
this.acceleration,
Expand Down Expand Up @@ -120,11 +120,11 @@ class CupertinoSpinBox extends BaseSpinBox {
@override
final double step;

/// The page step size for incrementing and decrementing the value.
/// An optional page step size for incrementing and decrementing the value.
///
/// Defaults to `10.0`.
/// Defaults to `null`.
@override
final double pageStep;
final double? pageStep;

/// The current value.
///
Expand Down
8 changes: 4 additions & 4 deletions lib/src/material/spin_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SpinBox extends BaseSpinBox {
this.min = 0,
this.max = 100,
this.step = 1,
this.pageStep = 10,
this.pageStep,
this.value = 0,
this.interval = const Duration(milliseconds: 100),
this.acceleration,
Expand Down Expand Up @@ -118,11 +118,11 @@ class SpinBox extends BaseSpinBox {
@override
final double step;

/// The page step size for incrementing and decrementing the value.
/// An optional page step size for incrementing and decrementing the value.
///
/// Defaults to `10.0`.
/// Defaults to `null`.
@override
final double pageStep;
final double? pageStep;

/// The current value.
///
Expand Down
9 changes: 8 additions & 1 deletion test/cupertino_spinbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ void main() {
});

testInput<CupertinoSpinBox>(() {
return TestApp(widget: CupertinoSpinBox(value: 1, autofocus: true));
return TestApp(
widget: CupertinoSpinBox(
value: 1,
autofocus: true,
pageStep: 10,
),
);
});

testInput<CupertinoSpinBox>(() {
Expand All @@ -30,6 +36,7 @@ void main() {
value: 1,
autofocus: true,
focusNode: FocusNode(),
pageStep: 10,
),
);
});
Expand Down
9 changes: 7 additions & 2 deletions test/material_spinbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ void main() {
});

testInput<SpinBox>(() {
return TestApp(widget: SpinBox(value: 1, autofocus: true));
return TestApp(widget: SpinBox(value: 1, autofocus: true, pageStep: 10));
});

testInput<SpinBox>(() {
return TestApp(
widget: SpinBox(value: 1, autofocus: true, focusNode: FocusNode()),
widget: SpinBox(
value: 1,
autofocus: true,
focusNode: FocusNode(),
pageStep: 10,
),
);
});

Expand Down

0 comments on commit 636f1b7

Please sign in to comment.