diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d9eaa0..a6e91e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.8.2 (2024-02-26) + +- adds `clipBehavior` to `AnimatedToggleSwitch` ([#56](https://github.com/splashbyte/animated_toggle_switch/issues/56)) + ## 0.8.1 (2024-02-06) - adds `indicatorGradient` to `ToggleStyle` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/44)) diff --git a/example/pubspec.lock b/example/pubspec.lock index 986d508..ae37264 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -44,10 +44,10 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" fake_async: dependency: transitive description: @@ -71,38 +71,62 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.11.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" plugin_platform_interface: dependency: transitive description: @@ -128,18 +152,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -160,10 +184,10 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" url_launcher: dependency: "direct main" description: @@ -236,14 +260,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "13.0.0" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.2.0-0 <4.0.0" flutter: ">=3.10.0" diff --git a/lib/src/widgets/animated_toggle_switch.dart b/lib/src/widgets/animated_toggle_switch.dart index fd4b9f6..7a06803 100644 --- a/lib/src/widgets/animated_toggle_switch.dart +++ b/lib/src/widgets/animated_toggle_switch.dart @@ -278,6 +278,9 @@ class AnimatedToggleSwitch /// Listener for the current position and [ToggleMode] of the indicator. final PositionListener? positionListener; + /// [Clip] of the switch wrapper. + final Clip clipBehavior; + final bool animateStyleChanges = true; /// Constructor of AnimatedToggleSwitch with all possible settings. @@ -331,6 +334,7 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), this.positionListener, + this.clipBehavior = Clip.antiAlias, }) : _iconArrangement = IconArrangement.row, super( values: values, @@ -394,6 +398,7 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), this.positionListener, + this.clipBehavior = Clip.antiAlias, }) : spacing = spacing * (height - 2 * borderWidth), indicatorSize = indicatorSize * (height - 2 * borderWidth), _iconArrangement = IconArrangement.row, @@ -459,6 +464,7 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), this.positionListener, + this.clipBehavior = Clip.antiAlias, }) : animatedIconBuilder = _iconSizeBuilder( iconBuilder, customIconBuilder, iconList, selectedIconScale), _iconArrangement = IconArrangement.row, @@ -527,6 +533,7 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), this.positionListener, + this.clipBehavior = Clip.antiAlias, }) : indicatorSize = indicatorSize * (height - 2 * borderWidth), spacing = spacing * (height - 2 * borderWidth), animatedIconBuilder = _iconSizeBuilder( @@ -622,6 +629,7 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), this.positionListener, + this.clipBehavior = Clip.antiAlias, double indicatorIconScale = 1.0, }) : iconAnimationCurve = Curves.linear, iconAnimationDuration = Duration.zero, @@ -704,6 +712,7 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), this.positionListener, + this.clipBehavior = Clip.antiAlias, double indicatorIconScale = 1.0, }) : iconAnimationCurve = Curves.linear, spacing = spacing * (height - 2 * borderWidth), @@ -902,6 +911,7 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), this.positionListener, + this.clipBehavior = Clip.antiAlias, }) : assert(clipAnimation || opacityAnimation), iconOpacity = 1.0, selectedIconOpacity = 1.0, @@ -970,7 +980,7 @@ class AnimatedToggleSwitch return Align( alignment: alignment, - child: _CustomClipRect( + child: ClipRect( clipBehavior: clipAnimation ? Clip.hardEdge : Clip.none, child: Align( alignment: alignment, @@ -1121,6 +1131,7 @@ class AnimatedToggleSwitch borderRadius: style._borderRadius?.value, ), child: ClipRRect( + clipBehavior: clipBehavior, borderRadius: style._borderRadius?.value ?? BorderRadius.zero, child: child, @@ -1288,34 +1299,6 @@ class AnimatedToggleSwitch } } -class _CustomClipRect extends StatefulWidget { - final Clip clipBehavior; - final Widget child; - - const _CustomClipRect({ - Key? key, - this.clipBehavior = Clip.hardEdge, - required this.child, - }) : super(key: key); - - @override - _CustomClipRectState createState() => _CustomClipRectState(); -} - -class _CustomClipRectState extends State<_CustomClipRect> { - final _childKey = GlobalKey(); - - @override - Widget build(BuildContext context) { - Widget child = _EmptyWidget(key: _childKey, child: widget.child); - if (widget.clipBehavior == Clip.none) return child; - return ClipRect( - clipBehavior: widget.clipBehavior, - child: child, - ); - } -} - class _MyLoading extends StatelessWidget { const _MyLoading({Key? key}) : super(key: key); diff --git a/pubspec.lock b/pubspec.lock index 4e8adf1..cb65570 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" convert: dependency: transitive description: @@ -207,10 +207,10 @@ packages: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" mime: dependency: transitive description: @@ -332,18 +332,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -364,26 +364,26 @@ packages: dependency: transitive description: name: test - sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46" + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f url: "https://pub.dev" source: hosted - version: "1.24.3" + version: "1.24.9" test_api: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" test_core: dependency: transitive description: name: test_core - sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e" + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a url: "https://pub.dev" source: hosted - version: "0.5.3" + version: "0.5.9" typed_data: dependency: transitive description: @@ -420,10 +420,10 @@ packages: dependency: transitive description: name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "0.3.0" web_socket_channel: dependency: transitive description: @@ -449,5 +449,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.2.0-194.0.dev <4.0.0" flutter: ">=1.17.0"