Skip to content

Commit 61e8e13

Browse files
authored
Merge pull request #57 from splashbyte/56-clip-behavior
adds clipBehavior parameter
2 parents c022d03 + 7aff835 commit 61e8e13

5 files changed

Lines changed: 114 additions & 87 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.2 (2024-02-26)
2+
3+
- adds `clipBehavior` to `AnimatedToggleSwitch` ([#56](https://github.com/splashbyte/animated_toggle_switch/issues/56))
4+
15
## 0.8.1 (2024-02-06)
26

37
- adds `indicatorGradient` to `ToggleStyle` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/44))

example/pubspec.lock

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
path: ".."
88
relative: true
99
source: path
10-
version: "0.8.1"
10+
version: "0.8.2"
1111
async:
1212
dependency: transitive
1313
description:
@@ -44,10 +44,10 @@ packages:
4444
dependency: transitive
4545
description:
4646
name: collection
47-
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
47+
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
4848
url: "https://pub.dev"
4949
source: hosted
50-
version: "1.17.2"
50+
version: "1.18.0"
5151
fake_async:
5252
dependency: transitive
5353
description:
@@ -71,38 +71,62 @@ packages:
7171
description: flutter
7272
source: sdk
7373
version: "0.0.0"
74+
leak_tracker:
75+
dependency: transitive
76+
description:
77+
name: leak_tracker
78+
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
79+
url: "https://pub.dev"
80+
source: hosted
81+
version: "10.0.0"
82+
leak_tracker_flutter_testing:
83+
dependency: transitive
84+
description:
85+
name: leak_tracker_flutter_testing
86+
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
87+
url: "https://pub.dev"
88+
source: hosted
89+
version: "2.0.1"
90+
leak_tracker_testing:
91+
dependency: transitive
92+
description:
93+
name: leak_tracker_testing
94+
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
95+
url: "https://pub.dev"
96+
source: hosted
97+
version: "2.0.1"
7498
matcher:
7599
dependency: transitive
76100
description:
77101
name: matcher
78-
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
102+
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
79103
url: "https://pub.dev"
80104
source: hosted
81-
version: "0.12.16"
105+
version: "0.12.16+1"
82106
material_color_utilities:
83107
dependency: transitive
84108
description:
85109
name: material_color_utilities
86-
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
110+
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
87111
url: "https://pub.dev"
88112
source: hosted
89-
version: "0.5.0"
113+
version: "0.8.0"
90114
meta:
91115
dependency: transitive
92116
description:
93117
name: meta
94-
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
118+
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
95119
url: "https://pub.dev"
96120
source: hosted
97-
version: "1.9.1"
121+
version: "1.11.0"
98122
path:
99123
dependency: transitive
100124
description:
101125
name: path
102-
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
126+
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
103127
url: "https://pub.dev"
104128
source: hosted
105-
version: "1.8.3"
129+
version: "1.9.0"
106130
plugin_platform_interface:
107131
dependency: transitive
108132
description:
@@ -128,18 +152,18 @@ packages:
128152
dependency: transitive
129153
description:
130154
name: stack_trace
131-
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
155+
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
132156
url: "https://pub.dev"
133157
source: hosted
134-
version: "1.11.0"
158+
version: "1.11.1"
135159
stream_channel:
136160
dependency: transitive
137161
description:
138162
name: stream_channel
139-
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
163+
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
140164
url: "https://pub.dev"
141165
source: hosted
142-
version: "2.1.1"
166+
version: "2.1.2"
143167
string_scanner:
144168
dependency: transitive
145169
description:
@@ -160,10 +184,10 @@ packages:
160184
dependency: transitive
161185
description:
162186
name: test_api
163-
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
187+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
164188
url: "https://pub.dev"
165189
source: hosted
166-
version: "0.6.0"
190+
version: "0.6.1"
167191
url_launcher:
168192
dependency: "direct main"
169193
description:
@@ -236,14 +260,14 @@ packages:
236260
url: "https://pub.dev"
237261
source: hosted
238262
version: "2.1.4"
239-
web:
263+
vm_service:
240264
dependency: transitive
241265
description:
242-
name: web
243-
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
266+
name: vm_service
267+
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
244268
url: "https://pub.dev"
245269
source: hosted
246-
version: "0.1.4-beta"
270+
version: "13.0.0"
247271
sdks:
248-
dart: ">=3.1.0-185.0.dev <4.0.0"
272+
dart: ">=3.2.0-0 <4.0.0"
249273
flutter: ">=3.10.0"

lib/src/widgets/animated_toggle_switch.dart

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ class AnimatedToggleSwitch<T extends Object?>
278278
/// Listener for the current position and [ToggleMode] of the indicator.
279279
final PositionListener<T>? positionListener;
280280

281+
/// [Clip] of the switch wrapper.
282+
final Clip clipBehavior;
283+
281284
final bool animateStyleChanges = true;
282285

283286
/// Constructor of AnimatedToggleSwitch with all possible settings.
@@ -331,6 +334,7 @@ class AnimatedToggleSwitch<T extends Object?>
331334
this.inactiveOpacityCurve = Curves.easeInOut,
332335
this.inactiveOpacityDuration = const Duration(milliseconds: 350),
333336
this.positionListener,
337+
this.clipBehavior = Clip.antiAlias,
334338
}) : _iconArrangement = IconArrangement.row,
335339
super(
336340
values: values,
@@ -394,6 +398,7 @@ class AnimatedToggleSwitch<T extends Object?>
394398
this.inactiveOpacityCurve = Curves.easeInOut,
395399
this.inactiveOpacityDuration = const Duration(milliseconds: 350),
396400
this.positionListener,
401+
this.clipBehavior = Clip.antiAlias,
397402
}) : spacing = spacing * (height - 2 * borderWidth),
398403
indicatorSize = indicatorSize * (height - 2 * borderWidth),
399404
_iconArrangement = IconArrangement.row,
@@ -459,6 +464,7 @@ class AnimatedToggleSwitch<T extends Object?>
459464
this.inactiveOpacityCurve = Curves.easeInOut,
460465
this.inactiveOpacityDuration = const Duration(milliseconds: 350),
461466
this.positionListener,
467+
this.clipBehavior = Clip.antiAlias,
462468
}) : animatedIconBuilder = _iconSizeBuilder<T>(
463469
iconBuilder, customIconBuilder, iconList, selectedIconScale),
464470
_iconArrangement = IconArrangement.row,
@@ -527,6 +533,7 @@ class AnimatedToggleSwitch<T extends Object?>
527533
this.inactiveOpacityCurve = Curves.easeInOut,
528534
this.inactiveOpacityDuration = const Duration(milliseconds: 350),
529535
this.positionListener,
536+
this.clipBehavior = Clip.antiAlias,
530537
}) : indicatorSize = indicatorSize * (height - 2 * borderWidth),
531538
spacing = spacing * (height - 2 * borderWidth),
532539
animatedIconBuilder = _iconSizeBuilder<T>(
@@ -622,6 +629,7 @@ class AnimatedToggleSwitch<T extends Object?>
622629
this.inactiveOpacityCurve = Curves.easeInOut,
623630
this.inactiveOpacityDuration = const Duration(milliseconds: 350),
624631
this.positionListener,
632+
this.clipBehavior = Clip.antiAlias,
625633
double indicatorIconScale = 1.0,
626634
}) : iconAnimationCurve = Curves.linear,
627635
iconAnimationDuration = Duration.zero,
@@ -704,6 +712,7 @@ class AnimatedToggleSwitch<T extends Object?>
704712
this.inactiveOpacityCurve = Curves.easeInOut,
705713
this.inactiveOpacityDuration = const Duration(milliseconds: 350),
706714
this.positionListener,
715+
this.clipBehavior = Clip.antiAlias,
707716
double indicatorIconScale = 1.0,
708717
}) : iconAnimationCurve = Curves.linear,
709718
spacing = spacing * (height - 2 * borderWidth),
@@ -902,6 +911,7 @@ class AnimatedToggleSwitch<T extends Object?>
902911
this.inactiveOpacityCurve = Curves.easeInOut,
903912
this.inactiveOpacityDuration = const Duration(milliseconds: 350),
904913
this.positionListener,
914+
this.clipBehavior = Clip.antiAlias,
905915
}) : assert(clipAnimation || opacityAnimation),
906916
iconOpacity = 1.0,
907917
selectedIconOpacity = 1.0,
@@ -970,7 +980,7 @@ class AnimatedToggleSwitch<T extends Object?>
970980

971981
return Align(
972982
alignment: alignment,
973-
child: _CustomClipRect(
983+
child: ClipRect(
974984
clipBehavior: clipAnimation ? Clip.hardEdge : Clip.none,
975985
child: Align(
976986
alignment: alignment,
@@ -1121,6 +1131,7 @@ class AnimatedToggleSwitch<T extends Object?>
11211131
borderRadius: style._borderRadius?.value,
11221132
),
11231133
child: ClipRRect(
1134+
clipBehavior: clipBehavior,
11241135
borderRadius:
11251136
style._borderRadius?.value ?? BorderRadius.zero,
11261137
child: child,
@@ -1288,34 +1299,6 @@ class AnimatedToggleSwitch<T extends Object?>
12881299
}
12891300
}
12901301

1291-
class _CustomClipRect extends StatefulWidget {
1292-
final Clip clipBehavior;
1293-
final Widget child;
1294-
1295-
const _CustomClipRect({
1296-
Key? key,
1297-
this.clipBehavior = Clip.hardEdge,
1298-
required this.child,
1299-
}) : super(key: key);
1300-
1301-
@override
1302-
_CustomClipRectState createState() => _CustomClipRectState();
1303-
}
1304-
1305-
class _CustomClipRectState extends State<_CustomClipRect> {
1306-
final _childKey = GlobalKey();
1307-
1308-
@override
1309-
Widget build(BuildContext context) {
1310-
Widget child = _EmptyWidget(key: _childKey, child: widget.child);
1311-
if (widget.clipBehavior == Clip.none) return child;
1312-
return ClipRect(
1313-
clipBehavior: widget.clipBehavior,
1314-
child: child,
1315-
);
1316-
}
1317-
}
1318-
13191302
class _MyLoading extends StatelessWidget {
13201303
const _MyLoading({Key? key}) : super(key: key);
13211304

0 commit comments

Comments
 (0)