From 5934ba3808188f651f1a104157a63859f4f65efd Mon Sep 17 00:00:00 2001 From: vovaklh Date: Thu, 17 Jul 2025 19:29:41 +0200 Subject: [PATCH] feat: Mark control touchable on cupertino switch touch --- .../reactive_cupertino_switch/CHANGELOG.md | 3 ++ .../lib/reactive_cupertino_switch.dart | 49 ++++++++++++------- .../reactive_cupertino_switch/pubspec.yaml | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/packages/reactive_cupertino_switch/CHANGELOG.md b/packages/reactive_cupertino_switch/CHANGELOG.md index 2a431a84..f04ec70b 100644 --- a/packages/reactive_cupertino_switch/CHANGELOG.md +++ b/packages/reactive_cupertino_switch/CHANGELOG.md @@ -1,3 +1,6 @@ +## [4.0.0] +Mark control as touchable on switch press + ## [3.0.1] * Support `reactive_forms: 18.x` diff --git a/packages/reactive_cupertino_switch/lib/reactive_cupertino_switch.dart b/packages/reactive_cupertino_switch/lib/reactive_cupertino_switch.dart index 863d24f0..0ea03d0a 100644 --- a/packages/reactive_cupertino_switch/lib/reactive_cupertino_switch.dart +++ b/packages/reactive_cupertino_switch/lib/reactive_cupertino_switch.dart @@ -4,6 +4,12 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:reactive_forms/reactive_forms.dart'; +enum MarkAsTouched { + none, + pointerUp, + pointerDown; +} + /// A [ReactiveCupertinoSwitch] that contains a [CupertinoSwitch]. /// /// This is a convenience widget that wraps a [CupertinoSwitch] widget in a @@ -98,27 +104,36 @@ class ReactiveCupertinoSwitch extends ReactiveFocusableFormField { bool? applyTheme, bool autofocus = false, double disabledOpacity = 0.5, + MarkAsTouched markAsTouched = MarkAsTouched.pointerDown, }) : super( builder: (field) { return IgnorePointer( ignoring: !field.control.enabled, - child: Opacity( - opacity: field.control.enabled ? 1 : disabledOpacity, - child: CupertinoSwitch( - key: widgetKey, - value: field.value ?? false, - onChanged: field.didChange, - activeTrackColor: activeTrackColor, - inactiveTrackColor: inactiveTrackColor, - dragStartBehavior: dragStartBehavior, - thumbColor: thumbColor, - applyTheme: applyTheme, - focusColor: focusColor, - onLabelColor: onLabelColor, - offLabelColor: offLabelColor, - focusNode: field.focusNode, - onFocusChange: onFocusChange, - autofocus: autofocus, + child: Listener( + onPointerDown: markAsTouched == MarkAsTouched.pointerDown + ? (_) => field.control.markAsTouched() + : null, + onPointerUp: markAsTouched == MarkAsTouched.pointerUp + ? (_) => field.control.markAsTouched() + : null, + child: Opacity( + opacity: field.control.enabled ? 1 : disabledOpacity, + child: CupertinoSwitch( + key: widgetKey, + value: field.value ?? false, + onChanged: field.didChange, + activeTrackColor: activeTrackColor, + inactiveTrackColor: inactiveTrackColor, + dragStartBehavior: dragStartBehavior, + thumbColor: thumbColor, + applyTheme: applyTheme, + focusColor: focusColor, + onLabelColor: onLabelColor, + offLabelColor: offLabelColor, + focusNode: field.focusNode, + onFocusChange: onFocusChange, + autofocus: autofocus, + ), ), ), ); diff --git a/packages/reactive_cupertino_switch/pubspec.yaml b/packages/reactive_cupertino_switch/pubspec.yaml index f524417e..857ebb69 100644 --- a/packages/reactive_cupertino_switch/pubspec.yaml +++ b/packages/reactive_cupertino_switch/pubspec.yaml @@ -1,6 +1,6 @@ name: reactive_cupertino_switch description: Wrapper around CupertinoSwitch to use with reactive_forms. -version: 3.0.1 +version: 4.0.0 repository: https://github.com/artflutter/reactive_forms_widgets/tree/master/packages/reactive_cupertino_switch issue_tracker: https://github.com/artflutter/reactive_forms_widgets/issues