From df4c133d63df5f5afad6e48b893e38ef242dc228 Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Thu, 5 Oct 2023 11:10:30 +0200 Subject: [PATCH 1/8] adds indicatorGradient to ToggleStyle --- example/lib/main.dart | 4 ++++ lib/src/style.dart | 18 ++++++++++++++++-- lib/src/widgets/animated_toggle_switch.dart | 9 +++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index a5179a4..0592721 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -517,6 +517,10 @@ class _MyHomePageState extends State { borderColor: Colors.transparent, borderRadius: BorderRadius.circular(10.0), ), + styleBuilder: (i) => ToggleStyle( + indicatorGradient: + LinearGradient(colors: [colorBuilder(i), colorBuilder((i + 1) % 4)]), + ), height: 55, spacing: 20.0, loading: loading, diff --git a/lib/src/style.dart b/lib/src/style.dart index 8f74423..1424885 100644 --- a/lib/src/style.dart +++ b/lib/src/style.dart @@ -6,6 +6,9 @@ class ToggleStyle { /// Defaults to [ThemeData.colorScheme.secondary]. final Color? indicatorColor; + /// Gradient of the indicator. Overwrites [indicatorColor] if not [null]. + final Gradient? indicatorGradient; + /// Background color of the switch. /// /// Defaults to [ThemeData.colorScheme.surface]. @@ -41,6 +44,7 @@ class ToggleStyle { /// Default constructor for [ToggleStyle]. const ToggleStyle({ this.indicatorColor, + this.indicatorGradient, this.backgroundColor, this.backgroundGradient, this.borderColor, @@ -52,8 +56,9 @@ class ToggleStyle { }); /// Private constructor for setting all possible parameters. - ToggleStyle._({ + const ToggleStyle._({ required this.indicatorColor, + required this.indicatorGradient, required this.backgroundColor, required this.backgroundGradient, required this.borderColor, @@ -72,9 +77,11 @@ class ToggleStyle { ? this : ToggleStyle._( indicatorColor: other.indicatorColor ?? indicatorColor, + indicatorGradient: other.indicatorGradient ?? + (other.indicatorColor != null ? null : indicatorGradient), backgroundColor: other.backgroundColor ?? backgroundColor, backgroundGradient: other.backgroundGradient ?? - (other.backgroundColor == null ? null : backgroundGradient), + (other.backgroundColor != null ? null : backgroundGradient), borderColor: other.borderColor ?? borderColor, borderRadius: other.borderRadius ?? borderRadius, indicatorBorderRadius: other.indicatorBorderRadius ?? @@ -93,6 +100,11 @@ class ToggleStyle { ToggleStyle._( indicatorColor: Color.lerp(style1.indicatorColor, style2.indicatorColor, t), + indicatorGradient: Gradient.lerp( + style1.indicatorGradient ?? style1.indicatorColor?.toGradient(), + style2.indicatorGradient ?? style2.indicatorColor?.toGradient(), + t, + ), backgroundColor: Color.lerp(style1.backgroundColor, style2.backgroundColor, t), backgroundGradient: Gradient.lerp( @@ -136,6 +148,7 @@ class ToggleStyle { other is ToggleStyle && runtimeType == other.runtimeType && indicatorColor == other.indicatorColor && + indicatorGradient == other.indicatorGradient && backgroundColor == other.backgroundColor && backgroundGradient == other.backgroundGradient && borderColor == other.borderColor && @@ -148,6 +161,7 @@ class ToggleStyle { @override int get hashCode => indicatorColor.hashCode ^ + indicatorGradient.hashCode ^ backgroundColor.hashCode ^ backgroundGradient.hashCode ^ borderColor.hashCode ^ diff --git a/lib/src/widgets/animated_toggle_switch.dart b/lib/src/widgets/animated_toggle_switch.dart index 956e4eb..fa3dd0b 100644 --- a/lib/src/widgets/animated_toggle_switch.dart +++ b/lib/src/widgets/animated_toggle_switch.dart @@ -158,12 +158,15 @@ class AnimatedToggleSwitch /// The [AnimationType] for [styleBuilder]. /// - /// The [AnimationType] for [ToggleStyle.indicatorColor], [ToggleStyle.indicatorBorderRadius], + /// The [AnimationType] for [ToggleStyle.indicatorColor], + /// [ToggleStyle.indicatorGradient], [ToggleStyle.indicatorBorderRadius], /// [ToggleStyle.indicatorBorder] and [ToggleStyle.indicatorBoxShadow]. /// is managed separately with [indicatorAnimationType]. final AnimationType styleAnimationType; - /// The [AnimationType] for the [ToggleStyle.indicatorColor]. + /// The [AnimationType] for [ToggleStyle.indicatorColor], + /// [ToggleStyle.indicatorGradient], [ToggleStyle.indicatorBorderRadius], + /// [ToggleStyle.indicatorBorder] and [ToggleStyle.indicatorBoxShadow] /// /// For the other style parameters, please use [styleAnimationType]. final AnimationType indicatorAnimationType; @@ -1020,6 +1023,7 @@ class AnimatedToggleSwitch BorderRadius.circular(height / 2); final style = ToggleStyle._( indicatorColor: theme.colorScheme.secondary, + indicatorGradient: null, backgroundColor: theme.colorScheme.surface, backgroundGradient: null, borderColor: theme.colorScheme.secondary, @@ -1227,6 +1231,7 @@ class AnimatedToggleSwitch return DecoratedBox( decoration: BoxDecoration( color: style.indicatorColor, + gradient: style.indicatorGradient, borderRadius: style.indicatorBorderRadius, border: style.indicatorBorder, boxShadow: style.indicatorBoxShadow, From 1e53e02f46d5f8a60bdc550fa14f6a0c3c282487 Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Thu, 5 Oct 2023 11:13:16 +0200 Subject: [PATCH 2/8] dart format --- example/lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 0592721..ef17b07 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -518,8 +518,8 @@ class _MyHomePageState extends State { borderRadius: BorderRadius.circular(10.0), ), styleBuilder: (i) => ToggleStyle( - indicatorGradient: - LinearGradient(colors: [colorBuilder(i), colorBuilder((i + 1) % 4)]), + indicatorGradient: LinearGradient( + colors: [colorBuilder(i), colorBuilder((i + 1) % 4)]), ), height: 55, spacing: 20.0, From 087d9c2956d09c794e40c9d3bbfc8c4f2db9e6de Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Thu, 5 Oct 2023 11:16:03 +0200 Subject: [PATCH 3/8] updates version to 0.8.1 --- CHANGELOG.md | 5 +++-- pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01a01c8..dcb8463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -## 0.8.0+1 -- fixes changelog of version 0.8.0 +## 0.8.1 (2023-10-05) + +- adds `indicatorGradient` to `ToggleStyle` ## 0.8.0 (2023-09-02) diff --git a/pubspec.yaml b/pubspec.yaml index e272f96..874995b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: animated_toggle_switch description: Fully customizable, draggable and animated switch with multiple choices and smooth loading animation. It has prebuilt constructors for rolling and size animations. -version: 0.8.0 +version: 0.8.1 repository: https://github.com/SplashByte/animated_toggle_switch issue_tracker: https://github.com/SplashByte/animated_toggle_switch/issues From e4c43115c65d75308f092a22f28ce4d99142af9b Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Thu, 5 Oct 2023 11:21:54 +0200 Subject: [PATCH 4/8] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcb8463..3aff5ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.8.1 (2023-10-05) -- adds `indicatorGradient` to `ToggleStyle` +- adds `indicatorGradient` to `ToggleStyle` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/44)) +- `backgroundColor` in `styleBuilder` overwrites `backgroundGradient` in `style` now ## 0.8.0 (2023-09-02) From 6801f6195d348ea8fd85b41be8c906a63d1c1caf Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Thu, 5 Oct 2023 11:24:09 +0200 Subject: [PATCH 5/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aff5ac..82099c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.8.1 (2023-10-05) - adds `indicatorGradient` to `ToggleStyle` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/44)) -- `backgroundColor` in `styleBuilder` overwrites `backgroundGradient` in `style` now +- minor fix: `backgroundColor` in `styleBuilder` overwrites `backgroundGradient` in `style` now ## 0.8.0 (2023-09-02) From 690179e600d83fe99e3b98bab5bad0e187d7560b Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Sat, 7 Oct 2023 10:46:54 +0200 Subject: [PATCH 6/8] updates changelog --- CHANGELOG.md | 2 +- example/pubspec.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82099c2..48736de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.8.1 (2023-10-05) - adds `indicatorGradient` to `ToggleStyle` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/44)) -- minor fix: `backgroundColor` in `styleBuilder` overwrites `backgroundGradient` in `style` now +- fixes problems with `backgroundGradient` and `backgroundColor` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/46)) ## 0.8.0 (2023-09-02) diff --git a/example/pubspec.lock b/example/pubspec.lock index c6ba98e..986d508 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "0.8.0" + version: "0.8.1" async: dependency: transitive description: From 1b4e45900ea63137792dfe400862cb04674e32dc Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Sat, 7 Oct 2023 10:47:13 +0200 Subject: [PATCH 7/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48736de..e28e0fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.8.1 (2023-10-05) - adds `indicatorGradient` to `ToggleStyle` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/44)) -- fixes problems with `backgroundGradient` and `backgroundColor` ([#44](https://github.com/splashbyte/animated_toggle_switch/issues/46)) +- fixes problems with `backgroundGradient` and `backgroundColor` ([#46](https://github.com/splashbyte/animated_toggle_switch/issues/46)) ## 0.8.0 (2023-09-02) From 47ad88f7c37c8ac82ff0a392bbf864c52ad92c56 Mon Sep 17 00:00:00 2001 From: MaddinMade Date: Sat, 7 Oct 2023 10:48:33 +0200 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e28e0fc..cf4c0b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.8.1 (2023-10-05) +## 0.8.1 - 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))