From c360f2fad7d44d5f5b1eeab1f1d13c90e551beb9 Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Sun, 8 Oct 2023 09:48:30 +0200 Subject: [PATCH] removes animateThemeChanges --- CHANGELOG.md | 2 +- lib/src/style.dart | 13 ++++++++ lib/src/widgets/animated_toggle_switch.dart | 34 +++------------------ 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aad3a0..fc33dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ - adds `indicatorGradient` to `ToggleStyle` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/44)) - fixes problems with `backgroundGradient` and `backgroundColor` ([#46](https://github.com/splashbyte/animated_toggle_switch/issues/46)) - adds `AnimationType.none` -- adds `animateThemeChanges` to `AnimatedToggleSwitch` +- introduces `CustomToggleStyle` for disabling the animation of single style properties ## 0.8.0 (2023-09-02) diff --git a/lib/src/style.dart b/lib/src/style.dart index 786d303..f348509 100644 --- a/lib/src/style.dart +++ b/lib/src/style.dart @@ -250,6 +250,19 @@ class ToggleStyle extends BaseToggleStyle { this.boxShadow, }) : super._(); + const ToggleStyle._({ + required this.indicatorColor, + required this.indicatorGradient, + required this.backgroundColor, + required this.backgroundGradient, + required this.borderColor, + required this.borderRadius, + required this.indicatorBorderRadius, + required this.indicatorBorder, + required this.indicatorBoxShadow, + required this.boxShadow, + }) : super._(); + @override ToggleStyleProperty? get _backgroundColor => ToggleStyleProperty.nullable(backgroundColor); diff --git a/lib/src/widgets/animated_toggle_switch.dart b/lib/src/widgets/animated_toggle_switch.dart index cf6f58f..7c6614f 100644 --- a/lib/src/widgets/animated_toggle_switch.dart +++ b/lib/src/widgets/animated_toggle_switch.dart @@ -275,11 +275,6 @@ class AnimatedToggleSwitch /// For deactivating this animation please set [inactiveOpacity] to [1.0]. final Duration inactiveOpacityDuration; - /// Indicates whether external changes to the [Theme] will be animated. - /// - /// This is useful if the theme is already animated externally. - final bool animateThemeChanges; - /// Constructor of AnimatedToggleSwitch with all possible settings. /// /// Consider using [CustomAnimatedToggleSwitch] for maximum customizability. @@ -330,7 +325,6 @@ class AnimatedToggleSwitch this.inactiveOpacity = 0.6, this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), - this.animateThemeChanges = true, }) : _iconArrangement = IconArrangement.row, super( values: values, @@ -393,7 +387,6 @@ class AnimatedToggleSwitch this.inactiveOpacity = 0.6, this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), - this.animateThemeChanges = true, }) : spacing = spacing * (height - 2 * borderWidth), indicatorSize = indicatorSize * (height - 2 * borderWidth), _iconArrangement = IconArrangement.row, @@ -458,7 +451,6 @@ class AnimatedToggleSwitch this.inactiveOpacity = 0.6, this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), - this.animateThemeChanges = true, }) : animatedIconBuilder = _iconSizeBuilder( iconBuilder, customIconBuilder, iconList, selectedIconScale), _iconArrangement = IconArrangement.row, @@ -526,7 +518,6 @@ class AnimatedToggleSwitch this.inactiveOpacity = 0.6, this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), - this.animateThemeChanges = true, }) : indicatorSize = indicatorSize * (height - 2 * borderWidth), spacing = spacing * (height - 2 * borderWidth), animatedIconBuilder = _iconSizeBuilder( @@ -622,7 +613,6 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), double indicatorIconScale = 1.0, - this.animateThemeChanges = true, }) : iconAnimationCurve = Curves.linear, iconAnimationDuration = Duration.zero, selectedIconOpacity = iconOpacity, @@ -704,7 +694,6 @@ class AnimatedToggleSwitch this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), double indicatorIconScale = 1.0, - this.animateThemeChanges = true, }) : iconAnimationCurve = Curves.linear, spacing = spacing * (height - 2 * borderWidth), iconAnimationDuration = Duration.zero, @@ -901,7 +890,6 @@ class AnimatedToggleSwitch this.inactiveOpacity = 0.6, this.inactiveOpacityCurve = Curves.easeInOut, this.inactiveOpacityDuration = const Duration(milliseconds: 350), - this.animateThemeChanges = true, }) : assert(clipAnimation || opacityAnimation), iconOpacity = 1.0, selectedIconOpacity = 1.0, @@ -1036,25 +1024,13 @@ class AnimatedToggleSwitch ThemeData theme = Theme.of(context); BorderRadiusGeometry defaultBorderRadius = BorderRadius.circular(height / 2); - final style = CustomToggleStyle._( - indicatorColor: ToggleStyleProperty( - theme.colorScheme.secondary, - animationEnabled: animateThemeChanges, - ), + final style = ToggleStyle._( + indicatorColor: theme.colorScheme.secondary, indicatorGradient: null, - backgroundColor: ToggleStyleProperty( - theme.colorScheme.surface, - animationEnabled: animateThemeChanges, - ), + backgroundColor: theme.colorScheme.surface, backgroundGradient: null, - borderColor: ToggleStyleProperty( - theme.colorScheme.secondary, - animationEnabled: animateThemeChanges, - ), - borderRadius: ToggleStyleProperty( - defaultBorderRadius, - animationEnabled: animateThemeChanges, - ), + borderColor: theme.colorScheme.secondary, + borderRadius: defaultBorderRadius, indicatorBorderRadius: null, indicatorBorder: null, indicatorBoxShadow: null,