Skip to content

Commit f61a1cb

Browse files
authored
Merge pull request #202 from vovaklhdella/feat/touchable-cupertino-switch
feat: Mark control touchable on cupertino switch touch
2 parents e8e4abd + 5934ba3 commit f61a1cb

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

packages/reactive_cupertino_switch/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [4.0.0]
2+
Mark control as touchable on switch press
3+
14
## [3.0.1]
25

36
* Support `reactive_forms: 18.x`

packages/reactive_cupertino_switch/lib/reactive_cupertino_switch.dart

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import 'package:flutter/cupertino.dart';
44
import 'package:flutter/gestures.dart';
55
import 'package:reactive_forms/reactive_forms.dart';
66

7+
enum MarkAsTouched {
8+
none,
9+
pointerUp,
10+
pointerDown;
11+
}
12+
713
/// A [ReactiveCupertinoSwitch] that contains a [CupertinoSwitch].
814
///
915
/// This is a convenience widget that wraps a [CupertinoSwitch] widget in a
@@ -98,27 +104,36 @@ class ReactiveCupertinoSwitch<T> extends ReactiveFocusableFormField<T, bool> {
98104
bool? applyTheme,
99105
bool autofocus = false,
100106
double disabledOpacity = 0.5,
107+
MarkAsTouched markAsTouched = MarkAsTouched.pointerDown,
101108
}) : super(
102109
builder: (field) {
103110
return IgnorePointer(
104111
ignoring: !field.control.enabled,
105-
child: Opacity(
106-
opacity: field.control.enabled ? 1 : disabledOpacity,
107-
child: CupertinoSwitch(
108-
key: widgetKey,
109-
value: field.value ?? false,
110-
onChanged: field.didChange,
111-
activeTrackColor: activeTrackColor,
112-
inactiveTrackColor: inactiveTrackColor,
113-
dragStartBehavior: dragStartBehavior,
114-
thumbColor: thumbColor,
115-
applyTheme: applyTheme,
116-
focusColor: focusColor,
117-
onLabelColor: onLabelColor,
118-
offLabelColor: offLabelColor,
119-
focusNode: field.focusNode,
120-
onFocusChange: onFocusChange,
121-
autofocus: autofocus,
112+
child: Listener(
113+
onPointerDown: markAsTouched == MarkAsTouched.pointerDown
114+
? (_) => field.control.markAsTouched()
115+
: null,
116+
onPointerUp: markAsTouched == MarkAsTouched.pointerUp
117+
? (_) => field.control.markAsTouched()
118+
: null,
119+
child: Opacity(
120+
opacity: field.control.enabled ? 1 : disabledOpacity,
121+
child: CupertinoSwitch(
122+
key: widgetKey,
123+
value: field.value ?? false,
124+
onChanged: field.didChange,
125+
activeTrackColor: activeTrackColor,
126+
inactiveTrackColor: inactiveTrackColor,
127+
dragStartBehavior: dragStartBehavior,
128+
thumbColor: thumbColor,
129+
applyTheme: applyTheme,
130+
focusColor: focusColor,
131+
onLabelColor: onLabelColor,
132+
offLabelColor: offLabelColor,
133+
focusNode: field.focusNode,
134+
onFocusChange: onFocusChange,
135+
autofocus: autofocus,
136+
),
122137
),
123138
),
124139
);

packages/reactive_cupertino_switch/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: reactive_cupertino_switch
22
description: Wrapper around CupertinoSwitch to use with reactive_forms.
3-
version: 3.0.1
3+
version: 4.0.0
44
repository: https://github.com/artflutter/reactive_forms_widgets/tree/master/packages/reactive_cupertino_switch
55
issue_tracker: https://github.com/artflutter/reactive_forms_widgets/issues
66

0 commit comments

Comments
 (0)