MorphSwitch constructor

MorphSwitch({
  1. Key? key,
  2. required bool stateValue,
  3. void onSwitch(
    1. bool
    )?,
  4. void onSwipeLeft(
    1. bool
    )?,
  5. void onSwipeRight(
    1. bool
    )?,
  6. double borderWidth = 1.3,
  7. bool hasHover = true,
  8. String? offBgImage,
  9. String offLabel = "",
  10. String onLabel = "",
  11. TextStyle? onLabelStyle,
  12. TextStyle? offLabelStyle,
  13. String? onBgImage,
  14. IconData? thumbOnIcon,
  15. IconData? thumbOffIcon,
  16. Color borderColor = const Color(0xFF4B2B30),
  17. Color? onBgColor,
  18. Color? offBgColor,
  19. Color thumbBorderColor = const Color(0x00000000),
  20. Color thumbOnBgColor = const Color(0xFF2196F3),
  21. Color thumbOffBgColor = const Color(0xFF9E9E9E),
  22. double thumbRadius = 18.0,
  23. bool isVertical = false,
  24. Curve switchCurve = Curves.bounceOut,
  25. IconData? onBgIcon,
  26. IconData? offBgIcon,
  27. double? width,
  28. double? height,
  29. bool applyThumbRotationAnimation = true,
  30. EdgeInsetsGeometry margin = EdgeInsets.zero,
  31. double squareThumbRadius = 7.0,
  32. double thumbBorderWidth = 1.0,
  33. Color? thumbIconColor,
  34. int durationInMs = 1000,
  35. double offOpacity = 1.0,
  36. double textPadding = 12.0,
  37. TextDirection direction = TextDirection.ltr,
  38. List<BoxShadow>? boxShadow,
  39. ImageTransitionAnimationStyle imageTransitionStyle = ImageTransitionAnimationStyle.fade,
  40. SwitcherRadius switcherRadius = const SwitcherRadius.all(radius: 5.0),
  41. IconTransitionStyle iconTransitionStyle = IconTransitionStyle.scale,
  42. GlassProperties glassProperties = const GlassProperties.init(),
  43. ThumbType thumbType = ThumbType.circle,
  44. SwitcherSize size = SwitcherSize.xSmall,
  45. bool disabled = false,
  46. LinearGradient? onGradient,
  47. LinearGradient? offGradient,
})

Implementation

MorphSwitch({
  super.key,
  required this.stateValue,
  this.onSwitch,
  this.onSwipeLeft,
  this.onSwipeRight,
  this.borderWidth = 1.3,
  this.hasHover = true,
  this.offBgImage,
  this.offLabel = "",
  this.onLabel = "",
  this.onLabelStyle,
  this.offLabelStyle,
  this.onBgImage,
  this.thumbOnIcon,
  this.thumbOffIcon,
  this.borderColor = const Color(0xFF4B2B30),
  this.onBgColor,
  this.offBgColor,
  this.thumbBorderColor = const Color(0x00000000),
  this.thumbOnBgColor = const Color(0xFF2196F3),
  this.thumbOffBgColor = const Color(0xFF9E9E9E),
  this.thumbRadius = 18.0,
  this.isVertical = false,
  this.switchCurve = Curves.bounceOut,
  this.onBgIcon,
  this.offBgIcon,
  this.width,
  this.height,
  this.applyThumbRotationAnimation = true,
  this.margin = EdgeInsets.zero,
  this.squareThumbRadius = 7.0,
  this.thumbBorderWidth = 1.0,
  this.thumbIconColor,
  this.durationInMs = 1000,
  this.offOpacity = 1.0,
  this.textPadding = 12.0,
  this.direction = TextDirection.ltr,
  this.boxShadow,
  this.imageTransitionStyle = ImageTransitionAnimationStyle.fade,
  this.switcherRadius = const SwitcherRadius.all(radius: 5.0),
  this.iconTransitionStyle = IconTransitionStyle.scale,
  this.glassProperties = const GlassProperties.init(),
  this.thumbType = ThumbType.circle,
  this.size = SwitcherSize.xSmall,
  this.disabled = false,
  this.onGradient,
  this.offGradient,
})  : assert(durationInMs > 0),
      assert(thumbRadius > 0.0, THUMB_RADIUS),
      assert(offOpacity >= 0.0 || offOpacity <= 1.0),
      assert(
        width == null && height == null || width != null && height != null,
        DIMENSIONS_ERROR,
      ),
      assert(
        (onBgImage == null ||
                !onBgImage.endsWith(".svg") ||
                !onBgImage.endsWith(".avif")) &&
            (offBgImage == null ||
                !offBgImage.endsWith(".svg") ||
                !offBgImage.endsWith(".avif")),
        SVG_ASSERTION,
      ),
      assert(
        !switcherRadius.bottomLeft.isNegative ||
            !switcherRadius.bottomRight.isNegative ||
            !switcherRadius.topLeft.isNegative ||
            !switcherRadius.topRight.isNegative,
        SWTICHER_NEGATIVE_RADIUS,
      );