File tree Expand file tree Collapse file tree 4 files changed +19
-14
lines changed Expand file tree Collapse file tree 4 files changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -117,17 +117,15 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
117
117
widget.onChanged? .call (v);
118
118
}
119
119
120
- bool setValue (double v) {
120
+ void setValue (double v) {
121
121
final newValue = v.clamp (widget.min, widget.max);
122
- if (newValue == value) return false ;
122
+ if (newValue == value) return ;
123
123
124
- if (widget.canChange? .call (newValue) == false ) return false ;
124
+ if (widget.canChange? .call (newValue) == false ) return ;
125
125
126
126
widget.beforeChange? .call ();
127
127
setState (() => _updateController (value, newValue));
128
128
widget.afterChange? .call ();
129
-
130
- return true ;
131
129
}
132
130
133
131
void _updateController (double oldValue, double newValue) {
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class CupertinoSpinButton extends StatelessWidget {
46
46
final double step;
47
47
final double ? acceleration;
48
48
final Duration interval;
49
- final SpinCallback onStep;
49
+ final ValueChanged < double > onStep;
50
50
51
51
@override
52
52
Widget build (BuildContext context) {
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ class SpinButton extends StatelessWidget {
44
44
final double step;
45
45
final double ? acceleration;
46
46
final Duration interval;
47
- final SpinCallback onStep;
47
+ final ValueChanged < double > onStep;
48
48
49
49
@override
50
50
Widget build (BuildContext context) {
Original file line number Diff line number Diff line change @@ -26,8 +26,6 @@ import 'package:flutter/material.dart';
26
26
27
27
// ignore_for_file: public_member_api_docs
28
28
29
- typedef SpinCallback = bool Function (double value);
30
-
31
29
class SpinGesture extends StatefulWidget {
32
30
const SpinGesture ({
33
31
Key ? key,
@@ -44,7 +42,7 @@ class SpinGesture extends StatefulWidget {
44
42
final double step;
45
43
final double ? acceleration;
46
44
final Duration interval;
47
- final SpinCallback onStep;
45
+ final ValueChanged < double > onStep;
48
46
49
47
@override
50
48
State <SpinGesture > createState () => _SpinGestureState ();
@@ -60,6 +58,14 @@ class _SpinGestureState extends State<SpinGesture> {
60
58
step = widget.step;
61
59
}
62
60
61
+ @override
62
+ void didUpdateWidget (covariant SpinGesture oldWidget) {
63
+ super .didUpdateWidget (oldWidget);
64
+ if (oldWidget.enabled && ! widget.enabled) {
65
+ stopTimer ();
66
+ }
67
+ }
68
+
63
69
@override
64
70
void dispose () {
65
71
stopTimer ();
@@ -75,18 +81,19 @@ class _SpinGestureState extends State<SpinGesture> {
75
81
);
76
82
}
77
83
78
- bool onStep () {
79
- if (! widget.enabled) return false ;
84
+ void onStep () {
85
+ if (! widget.enabled) return ;
80
86
if (widget.acceleration != null ) {
81
87
step += widget.acceleration! ;
82
88
}
83
- return widget.onStep (step);
89
+ widget.onStep (step);
84
90
}
85
91
86
92
void startTimer () {
87
93
if (timer != null ) return ;
88
94
timer = Timer .periodic (widget.interval, (timer) {
89
- if (! onStep ()) {
95
+ onStep ();
96
+ if (! widget.enabled) {
90
97
stopTimer ();
91
98
}
92
99
});
You can’t perform that action at this time.
0 commit comments