Skip to content

Commit 7817142

Browse files
authored
Add onSubmitted (ubuntu-flutter-community#74)
1 parent 7cab63c commit 7817142

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/src/base_spin_box.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ abstract class BaseSpinBox extends StatefulWidget {
3838
int get decimals;
3939
int get digits;
4040
ValueChanged<double>? get onChanged;
41+
void Function(double value)? get onSubmitted;
4142
bool Function(double value)? get canChange;
4243
VoidCallback? get beforeChange;
4344
VoidCallback? get afterChange;
@@ -154,6 +155,7 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
154155
} else {
155156
_cachedValue = _value;
156157
}
158+
widget.onSubmitted?.call(_cachedValue);
157159
}
158160

159161
void _handleFocusChanged() {

lib/src/cupertino/spin_box.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CupertinoSpinBox extends BaseSpinBox {
8080
this.enableInteractiveSelection = true,
8181
this.spacing = 8,
8282
this.onChanged,
83+
this.onSubmitted,
8384
this.canChange,
8485
this.beforeChange,
8586
this.afterChange,
@@ -255,6 +256,10 @@ class CupertinoSpinBox extends BaseSpinBox {
255256
/// See [CupertinoTextField.toolbarOptions].
256257
final ToolbarOptions? toolbarOptions;
257258

259+
/// See [CupertinoTextField.onSubmitted]. Is called with a formatted value.
260+
@override
261+
final void Function(double)? onSubmitted;
262+
258263
@override
259264
State<CupertinoSpinBox> createState() => _CupertinoSpinBoxState();
260265
}

lib/src/material/spin_box.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class SpinBox extends BaseSpinBox {
8282
this.enableInteractiveSelection = true,
8383
this.spacing = 8,
8484
this.onChanged,
85+
this.onSubmitted,
8586
this.canChange,
8687
this.beforeChange,
8788
this.afterChange,
@@ -263,6 +264,10 @@ class SpinBox extends BaseSpinBox {
263264
/// See [TextField.toolbarOptions].
264265
final ToolbarOptions? toolbarOptions;
265266

267+
/// See [TextField.onSubmitted]. Is called with a formatted value.
268+
@override
269+
final void Function(double)? onSubmitted;
270+
266271
@override
267272
State<SpinBox> createState() => _SpinBoxState();
268273
}

0 commit comments

Comments
 (0)