@@ -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-
13191302class _MyLoading extends StatelessWidget {
13201303 const _MyLoading ({Key ? key}) : super (key: key);
13211304
0 commit comments