Skip to content

Commit f49cb36

Browse files
committed
Get rid of SpinCallback
1 parent c9c5f44 commit f49cb36

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

lib/src/base_spin_box.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,15 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
117117
widget.onChanged?.call(v);
118118
}
119119

120-
bool setValue(double v) {
120+
void setValue(double v) {
121121
final newValue = v.clamp(widget.min, widget.max);
122-
if (newValue == value) return false;
122+
if (newValue == value) return;
123123

124-
if (widget.canChange?.call(newValue) == false) return false;
124+
if (widget.canChange?.call(newValue) == false) return;
125125

126126
widget.beforeChange?.call();
127127
setState(() => _updateController(value, newValue));
128128
widget.afterChange?.call();
129-
130-
return true;
131129
}
132130

133131
void _updateController(double oldValue, double newValue) {

lib/src/cupertino/spin_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CupertinoSpinButton extends StatelessWidget {
4646
final double step;
4747
final double? acceleration;
4848
final Duration interval;
49-
final SpinCallback onStep;
49+
final ValueChanged<double> onStep;
5050

5151
@override
5252
Widget build(BuildContext context) {

lib/src/material/spin_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SpinButton extends StatelessWidget {
4444
final double step;
4545
final double? acceleration;
4646
final Duration interval;
47-
final SpinCallback onStep;
47+
final ValueChanged<double> onStep;
4848

4949
@override
5050
Widget build(BuildContext context) {

lib/src/spin_gesture.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import 'package:flutter/material.dart';
2626

2727
// ignore_for_file: public_member_api_docs
2828

29-
typedef SpinCallback = bool Function(double value);
30-
3129
class SpinGesture extends StatefulWidget {
3230
const SpinGesture({
3331
Key? key,
@@ -44,7 +42,7 @@ class SpinGesture extends StatefulWidget {
4442
final double step;
4543
final double? acceleration;
4644
final Duration interval;
47-
final SpinCallback onStep;
45+
final ValueChanged<double> onStep;
4846

4947
@override
5048
State<SpinGesture> createState() => _SpinGestureState();
@@ -60,6 +58,14 @@ class _SpinGestureState extends State<SpinGesture> {
6058
step = widget.step;
6159
}
6260

61+
@override
62+
void didUpdateWidget(covariant SpinGesture oldWidget) {
63+
super.didUpdateWidget(oldWidget);
64+
if (oldWidget.enabled && !widget.enabled) {
65+
stopTimer();
66+
}
67+
}
68+
6369
@override
6470
void dispose() {
6571
stopTimer();
@@ -75,18 +81,19 @@ class _SpinGestureState extends State<SpinGesture> {
7581
);
7682
}
7783

78-
bool onStep() {
79-
if (!widget.enabled) return false;
84+
void onStep() {
85+
if (!widget.enabled) return;
8086
if (widget.acceleration != null) {
8187
step += widget.acceleration!;
8288
}
83-
return widget.onStep(step);
89+
widget.onStep(step);
8490
}
8591

8692
void startTimer() {
8793
if (timer != null) return;
8894
timer = Timer.periodic(widget.interval, (timer) {
89-
if (!onStep()) {
95+
onStep();
96+
if (!widget.enabled) {
9097
stopTimer();
9198
}
9299
});

0 commit comments

Comments
 (0)