From 3cfe93ef018ae3b5d40f6d70add1083848665a7d Mon Sep 17 00:00:00 2001 From: Daniyil Yakovlev Date: Tue, 5 Dec 2023 20:48:25 +0200 Subject: [PATCH] fix: using default switch theme color and add inActiveSwitchColor --- lib/src/tiles/platforms/android_settings_tile.dart | 4 ++++ lib/src/tiles/platforms/ios_settings_tile.dart | 4 ++++ lib/src/tiles/platforms/web_settings_tile.dart | 13 +++++++++---- lib/src/tiles/settings_tile.dart | 7 +++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/src/tiles/platforms/android_settings_tile.dart b/lib/src/tiles/platforms/android_settings_tile.dart index 5d10b2a..e040255 100644 --- a/lib/src/tiles/platforms/android_settings_tile.dart +++ b/lib/src/tiles/platforms/android_settings_tile.dart @@ -12,6 +12,7 @@ class AndroidSettingsTile extends StatelessWidget { required this.value, required this.initialValue, required this.activeSwitchColor, + required this.inActiveSwitchColor, required this.enabled, required this.trailing, this.titlePadding, @@ -31,6 +32,7 @@ class AndroidSettingsTile extends StatelessWidget { final bool initialValue; final bool enabled; final Color? activeSwitchColor; + final Color? inActiveSwitchColor; final Widget? trailing; final EdgeInsetsGeometry? titlePadding; final EdgeInsetsGeometry? leadingPadding; @@ -151,6 +153,8 @@ class AndroidSettingsTile extends StatelessWidget { activeColor: enabled ? activeSwitchColor : theme.themeData.inactiveTitleColor, + inactiveTrackColor: inActiveSwitchColor?.withOpacity(0.4), + inactiveThumbColor: inActiveSwitchColor, ), ) else if (trailing != null) diff --git a/lib/src/tiles/platforms/ios_settings_tile.dart b/lib/src/tiles/platforms/ios_settings_tile.dart index 1763f0a..46d4a9c 100644 --- a/lib/src/tiles/platforms/ios_settings_tile.dart +++ b/lib/src/tiles/platforms/ios_settings_tile.dart @@ -14,6 +14,7 @@ class IOSSettingsTile extends StatefulWidget { required this.value, required this.initialValue, required this.activeSwitchColor, + required this.inActiveSwitchColor, required this.enabled, required this.trailing, this.titlePadding, @@ -33,6 +34,7 @@ class IOSSettingsTile extends StatefulWidget { final bool? initialValue; final bool enabled; final Color? activeSwitchColor; + final Color? inActiveSwitchColor; final Widget? trailing; final EdgeInsetsGeometry? titlePadding; final EdgeInsetsGeometry? leadingPadding; @@ -149,9 +151,11 @@ class IOSSettingsTileState extends State { CupertinoSwitch( value: widget.initialValue ?? true, onChanged: widget.onToggle, + applyTheme: true, activeColor: widget.enabled ? widget.activeSwitchColor : theme.themeData.inactiveTitleColor, + trackColor: widget.inActiveSwitchColor, ), if (widget.tileType == SettingsTileType.navigationTile && widget.value != null) diff --git a/lib/src/tiles/platforms/web_settings_tile.dart b/lib/src/tiles/platforms/web_settings_tile.dart index 07d5cc4..050f47b 100644 --- a/lib/src/tiles/platforms/web_settings_tile.dart +++ b/lib/src/tiles/platforms/web_settings_tile.dart @@ -12,6 +12,7 @@ class WebSettingsTile extends StatelessWidget { required this.value, required this.initialValue, required this.activeSwitchColor, + required this.inActiveSwitchColor, required this.enabled, required this.trailing, this.titlePadding, @@ -32,6 +33,7 @@ class WebSettingsTile extends StatelessWidget { final bool enabled; final Widget? trailing; final Color? activeSwitchColor; + final Color? inActiveSwitchColor; final EdgeInsetsGeometry? titlePadding; final EdgeInsetsGeometry? leadingPadding; final EdgeInsetsGeometry? trailingPadding; @@ -156,9 +158,11 @@ class WebSettingsTile extends StatelessWidget { padding: const EdgeInsetsDirectional.only(end: 8), child: Switch( activeColor: enabled - ? (activeSwitchColor ?? - const Color.fromRGBO(138, 180, 248, 1.0)) + ? activeSwitchColor : theme.themeData.inactiveTitleColor, + inactiveTrackColor: + inActiveSwitchColor?.withOpacity(0.4), + inactiveThumbColor: inActiveSwitchColor, value: initialValue, onChanged: onToggle, ), @@ -171,9 +175,10 @@ class WebSettingsTile extends StatelessWidget { child: Switch( value: initialValue, activeColor: enabled - ? (activeSwitchColor ?? - const Color.fromRGBO(138, 180, 248, 1.0)) + ? activeSwitchColor : theme.themeData.inactiveTitleColor, + inactiveTrackColor: inActiveSwitchColor?.withOpacity(0.4), + inactiveThumbColor: inActiveSwitchColor, onChanged: onToggle, ), ) diff --git a/lib/src/tiles/settings_tile.dart b/lib/src/tiles/settings_tile.dart index af57bfa..100e554 100644 --- a/lib/src/tiles/settings_tile.dart +++ b/lib/src/tiles/settings_tile.dart @@ -28,6 +28,7 @@ class SettingsTile extends AbstractSettingsTile { onToggle = null; initialValue = null; activeSwitchColor = null; + inActiveSwitchColor = null; tileType = SettingsTileType.simpleTile; } @@ -50,6 +51,7 @@ class SettingsTile extends AbstractSettingsTile { onToggle = null; initialValue = null; activeSwitchColor = null; + inActiveSwitchColor = null; tileType = SettingsTileType.navigationTile; } @@ -57,6 +59,7 @@ class SettingsTile extends AbstractSettingsTile { required this.initialValue, required this.onToggle, this.activeSwitchColor, + this.inActiveSwitchColor, this.leading, this.trailing, required this.title, @@ -100,6 +103,7 @@ class SettingsTile extends AbstractSettingsTile { final EdgeInsetsGeometry? titleDescriptionPadding; late final Color? activeSwitchColor; + late final Color? inActiveSwitchColor; late final Widget? value; late final Function(bool value)? onToggle; late final SettingsTileType tileType; @@ -124,6 +128,7 @@ class SettingsTile extends AbstractSettingsTile { title: title, enabled: enabled, activeSwitchColor: activeSwitchColor, + inActiveSwitchColor: inActiveSwitchColor, initialValue: initialValue ?? false, trailing: trailing, titlePadding: titlePadding, @@ -146,6 +151,7 @@ class SettingsTile extends AbstractSettingsTile { trailing: trailing, enabled: enabled, activeSwitchColor: activeSwitchColor, + inActiveSwitchColor: inActiveSwitchColor, initialValue: initialValue ?? false, titlePadding: titlePadding, leadingPadding: leadingPadding, @@ -163,6 +169,7 @@ class SettingsTile extends AbstractSettingsTile { enabled: enabled, trailing: trailing, activeSwitchColor: activeSwitchColor, + inActiveSwitchColor: inActiveSwitchColor, initialValue: initialValue ?? false, titlePadding: titlePadding, leadingPadding: leadingPadding,