MorphSwitch constructor
MorphSwitch({
- Key? key,
- required bool stateValue,
- void onSwitch()?,
- void onSwipeLeft()?,
- void onSwipeRight()?,
- double borderWidth = 1.3,
- bool hasHover = true,
- String? offBgImage,
- String offLabel = "",
- String onLabel = "",
- TextStyle? onLabelStyle,
- TextStyle? offLabelStyle,
- String? onBgImage,
- IconData? thumbOnIcon,
- IconData? thumbOffIcon,
- Color borderColor = const Color(0xFF4B2B30),
- Color? onBgColor,
- Color? offBgColor,
- Color thumbBorderColor = const Color(0x00000000),
- Color thumbOnBgColor = const Color(0xFF2196F3),
- Color thumbOffBgColor = const Color(0xFF9E9E9E),
- double thumbRadius = 18.0,
- bool isVertical = false,
- Curve switchCurve = Curves.bounceOut,
- IconData? onBgIcon,
- IconData? offBgIcon,
- double? width,
- double? height,
- bool applyThumbRotationAnimation = true,
- EdgeInsetsGeometry margin = EdgeInsets.zero,
- double squareThumbRadius = 7.0,
- double thumbBorderWidth = 1.0,
- Color? thumbIconColor,
- int durationInMs = 1000,
- double offOpacity = 1.0,
- double textPadding = 12.0,
- TextDirection direction = TextDirection.ltr,
- List<
BoxShadow> ? boxShadow, - ImageTransitionAnimationStyle imageTransitionStyle = ImageTransitionAnimationStyle.fade,
- SwitcherRadius switcherRadius = const SwitcherRadius.all(radius: 5.0),
- IconTransitionStyle iconTransitionStyle = IconTransitionStyle.scale,
- GlassProperties glassProperties = const GlassProperties.init(),
- ThumbType thumbType = ThumbType.circle,
- SwitcherSize size = SwitcherSize.xSmall,
- bool disabled = false,
- LinearGradient? onGradient,
- 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,
);