ReactiveSwitch constructor

ReactiveSwitch({
  1. Key? key,
  2. String? formControlName,
  3. FormControl<bool>? formControl,
  4. FocusNode? focusNode,
  5. Color? activeColor,
  6. Color? activeTrackColor,
  7. Color? inactiveThumbColor,
  8. Color? inactiveTrackColor,
  9. ImageProvider<Object>? activeThumbImage,
  10. ImageErrorListener? onActiveThumbImageError,
  11. ImageProvider<Object>? inactiveThumbImage,
  12. ImageErrorListener? onInactiveThumbImageError,
  13. MaterialTapTargetSize? materialTapTargetSize,
  14. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  15. Color? focusColor,
  16. Color? hoverColor,
  17. bool autofocus = false,
  18. MaterialStateProperty<Color?>? thumbColor,
  19. MaterialStateProperty<Color?>? trackColor,
  20. MouseCursor? mouseCursor,
  21. MaterialStateProperty<Color?>? overlayColor,
  22. double? splashRadius,
  23. ReactiveFormFieldCallback<bool>? onChanged,
  24. MaterialStateProperty<Color?>? trackOutlineColor,
  25. MaterialStateProperty<Icon?>? thumbIcon,
  26. ValueChanged<bool>? onFocusChange,
})

Creates a ReactiveSwitch that wraps a material design switch.

Can optionally provide a formControl to bind this widget to a control.

Can optionally provide a formControlName to bind this ReactiveFormField to a FormControl.

Must provide one of the arguments formControl or a formControlName, but not both at the same time.

For documentation about the various parameters, see the Switch class and Switch, the constructor.

Implementation

ReactiveSwitch({
  super.key,
  super.formControlName,
  super.formControl,
  super.focusNode,
  Color? activeColor,
  Color? activeTrackColor,
  Color? inactiveThumbColor,
  Color? inactiveTrackColor,
  ImageProvider? activeThumbImage,
  ImageErrorListener? onActiveThumbImageError,
  ImageProvider? inactiveThumbImage,
  ImageErrorListener? onInactiveThumbImageError,
  MaterialTapTargetSize? materialTapTargetSize,
  DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  Color? focusColor,
  Color? hoverColor,
  bool autofocus = false,
  MaterialStateProperty<Color?>? thumbColor,
  MaterialStateProperty<Color?>? trackColor,
  MouseCursor? mouseCursor,
  MaterialStateProperty<Color?>? overlayColor,
  double? splashRadius,
  ReactiveFormFieldCallback<bool>? onChanged,
  MaterialStateProperty<Color?>? trackOutlineColor,
  MaterialStateProperty<Icon?>? thumbIcon,
  ValueChanged<bool>? onFocusChange,
}) : super(
        builder: (field) {
          return Switch(
            value: field.value ?? false,
            activeColor: activeColor,
            trackOutlineColor: trackOutlineColor,
            thumbIcon: thumbIcon,
            onFocusChange: onFocusChange,
            activeTrackColor: activeTrackColor,
            inactiveThumbColor: inactiveThumbColor,
            inactiveTrackColor: inactiveTrackColor,
            activeThumbImage: activeThumbImage,
            onActiveThumbImageError: onActiveThumbImageError,
            inactiveThumbImage: inactiveThumbImage,
            onInactiveThumbImageError: onInactiveThumbImageError,
            materialTapTargetSize: materialTapTargetSize,
            dragStartBehavior: dragStartBehavior,
            focusColor: focusColor,
            hoverColor: hoverColor,
            autofocus: autofocus,
            thumbColor: thumbColor,
            trackColor: trackColor,
            mouseCursor: mouseCursor,
            overlayColor: overlayColor,
            splashRadius: splashRadius,
            focusNode: field.focusNode,
            onChanged: field.control.enabled
                ? (value) {
                    field.didChange(value);
                    onChanged?.call(field.control);
                  }
                : null,
          );
        },
      );