Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/reactive_cupertino_switch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [4.0.0]
Mark control as touchable on switch press

## [3.0.1]

* Support `reactive_forms: 18.x`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,27 +104,36 @@ class ReactiveCupertinoSwitch<T> extends ReactiveFocusableFormField<T, bool> {
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,
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/reactive_cupertino_switch/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down