File tree Expand file tree Collapse file tree 4 files changed +5
-43
lines changed Expand file tree Collapse file tree 4 files changed +5
-43
lines changed Original file line number Diff line number Diff line change @@ -39,9 +39,6 @@ abstract class BaseSpinBox extends StatefulWidget {
3939 int get decimals;
4040 int get digits;
4141 ValueChanged <double >? get onChanged;
42- bool Function (double value)? get canChange;
43- VoidCallback ? get beforeChange;
44- VoidCallback ? get afterChange;
4542 bool get readOnly;
4643 FocusNode ? get focusNode;
4744 SpinController ? get controller;
@@ -80,9 +77,6 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
8077 value: widget.value,
8178 decimals: widget.decimals,
8279 digits: widget.digits,
83- canChange: widget.canChange,
84- beforeChange: widget.beforeChange,
85- afterChange: widget.afterChange,
8680 );
8781 _controller.addListener (_handleValueChange);
8882 _editor = TextEditingController (text: _controller.format (widget.value));
Original file line number Diff line number Diff line change @@ -81,9 +81,6 @@ class CupertinoSpinBox extends BaseSpinBox {
8181 this .enableInteractiveSelection = true ,
8282 this .spacing = 8 ,
8383 this .onChanged,
84- this .canChange,
85- this .beforeChange,
86- this .afterChange,
8784 this .focusNode,
8885 this .controller,
8986 }) : assert (min <= max),
@@ -209,15 +206,6 @@ class CupertinoSpinBox extends BaseSpinBox {
209206 @override
210207 final ValueChanged <double >? onChanged;
211208
212- @override
213- final bool Function (double value)? canChange;
214-
215- @override
216- final VoidCallback ? beforeChange;
217-
218- @override
219- final VoidCallback ? afterChange;
220-
221209 /// See [CupertinoTextField.enabled] .
222210 final bool enabled;
223211
Original file line number Diff line number Diff line change @@ -82,9 +82,6 @@ class SpinBox extends BaseSpinBox {
8282 this .enableInteractiveSelection = true ,
8383 this .spacing = 8 ,
8484 this .onChanged,
85- this .canChange,
86- this .beforeChange,
87- this .afterChange,
8885 this .focusNode,
8986 this .controller,
9087 }) : assert (min <= max),
@@ -207,15 +204,6 @@ class SpinBox extends BaseSpinBox {
207204 @override
208205 final ValueChanged <double >? onChanged;
209206
210- @override
211- final bool Function (double value)? canChange;
212-
213- @override
214- final VoidCallback ? beforeChange;
215-
216- @override
217- final VoidCallback ? afterChange;
218-
219207 /// See [TextField.enabled] .
220208 final bool enabled;
221209
Original file line number Diff line number Diff line change @@ -31,9 +31,6 @@ class SpinController extends ValueNotifier<double> {
3131 this .pageStep,
3232 this .decimals = 0 ,
3333 this .digits = 0 ,
34- this .canChange,
35- this .beforeChange,
36- this .afterChange,
3734 }) : _min = min,
3835 _max = max,
3936 super (value);
@@ -45,9 +42,6 @@ class SpinController extends ValueNotifier<double> {
4542 final double ? pageStep;
4643 final int decimals;
4744 final int digits;
48- final bool Function (double value)? canChange;
49- final VoidCallback ? beforeChange;
50- final VoidCallback ? afterChange;
5145
5246 double get min => _min;
5347 set min (double min) {
@@ -84,16 +78,14 @@ class SpinController extends ValueNotifier<double> {
8478 void pageStepDown () => _doStep (- (pageStep ?? 0 ));
8579 void _doStep (double step) => value += step;
8680
81+ bool canChange (double value) => true ;
82+
8783 @override
8884 set value (double v) {
8985 final newValue = v.clamp (min, max);
90- if (newValue == value) return ;
91-
92- if (canChange? .call (newValue) == false ) return ;
93-
94- beforeChange? .call ();
95- super .value = newValue;
96- afterChange? .call ();
86+ if (newValue != value && canChange (newValue)) {
87+ super .value = newValue;
88+ }
9789 }
9890
9991 bool validate (String text) {
You can’t perform that action at this time.
0 commit comments