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

Implementation

MorphSwitch({
  super.key,
  required this.stateValue,
  this.onSwitch,
  this.onSwipeLeft,
  this.onSwipeRight,
  this.switcherRadius = const SwitcherRadius.all(radius: 5.0),
  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.thumbType = ThumbType.circle,
  this.imageTransitionStyle = ImageTransitionAnimationStyle.fade,
  this.iconTransitionStyle = IconTransitionStyle.scale,
  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.size = SwitcherSize.xSmall,
  this.boxShadow,
  this.glassProperties = const GlassProperties.init(),
  this.direction = TextDirection.ltr,
  this.disabled = false,
  this.onGradient,
  this.offGradient,
  this.textPadding = 12.0,
})  : 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,
      );