From 636f1b78648724eeb30404407c63a8d857369039 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 27 Jul 2022 23:25:26 +0200 Subject: [PATCH] Make page step nullable (#62) --- lib/src/base_spin_box.dart | 12 +++++++----- lib/src/cupertino/spin_box.dart | 8 ++++---- lib/src/material/spin_box.dart | 8 ++++---- test/cupertino_spinbox_test.dart | 9 ++++++++- test/material_spinbox_test.dart | 9 +++++++-- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/src/base_spin_box.dart b/lib/src/base_spin_box.dart index e4a12c7..361d8db 100644 --- a/lib/src/base_spin_box.dart +++ b/lib/src/base_spin_box.dart @@ -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; @@ -69,8 +69,10 @@ mixin SpinBoxMixin on State { // 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, + } }; } @@ -98,8 +100,8 @@ mixin SpinBoxMixin on State { 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); diff --git a/lib/src/cupertino/spin_box.dart b/lib/src/cupertino/spin_box.dart index 143f6d4..68d9bdc 100644 --- a/lib/src/cupertino/spin_box.dart +++ b/lib/src/cupertino/spin_box.dart @@ -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, @@ -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. /// diff --git a/lib/src/material/spin_box.dart b/lib/src/material/spin_box.dart index c07999d..3a92622 100644 --- a/lib/src/material/spin_box.dart +++ b/lib/src/material/spin_box.dart @@ -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, @@ -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. /// diff --git a/test/cupertino_spinbox_test.dart b/test/cupertino_spinbox_test.dart index d96b291..68597ee 100644 --- a/test/cupertino_spinbox_test.dart +++ b/test/cupertino_spinbox_test.dart @@ -21,7 +21,13 @@ void main() { }); testInput(() { - return TestApp(widget: CupertinoSpinBox(value: 1, autofocus: true)); + return TestApp( + widget: CupertinoSpinBox( + value: 1, + autofocus: true, + pageStep: 10, + ), + ); }); testInput(() { @@ -30,6 +36,7 @@ void main() { value: 1, autofocus: true, focusNode: FocusNode(), + pageStep: 10, ), ); }); diff --git a/test/material_spinbox_test.dart b/test/material_spinbox_test.dart index 4716341..9581408 100644 --- a/test/material_spinbox_test.dart +++ b/test/material_spinbox_test.dart @@ -22,12 +22,17 @@ void main() { }); testInput(() { - return TestApp(widget: SpinBox(value: 1, autofocus: true)); + return TestApp(widget: SpinBox(value: 1, autofocus: true, pageStep: 10)); }); testInput(() { return TestApp( - widget: SpinBox(value: 1, autofocus: true, focusNode: FocusNode()), + widget: SpinBox( + value: 1, + autofocus: true, + focusNode: FocusNode(), + pageStep: 10, + ), ); });