diff --git a/example/lib/utils/theme_color_switch.dart b/example/lib/utils/theme_color_switch.dart index 16a92825..383b3889 100644 --- a/example/lib/utils/theme_color_switch.dart +++ b/example/lib/utils/theme_color_switch.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:collection/collection.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; class ZetaThemeColorSwitch extends StatefulWidget { @@ -11,21 +12,38 @@ class ZetaThemeColorSwitch extends StatefulWidget { class _ZetaThemeColorSwitchState extends State { String currentTheme = "default"; - final Map appThemes = { - "default": ZetaPrimitivesLight().blue, + final Map appThemes = { + "default": null, "teal": ZetaPrimitivesLight().teal, "yellow": ZetaPrimitivesLight().yellow, "red": ZetaPrimitivesLight().red, "purple": ZetaPrimitivesLight().purple, + "green": ZetaPrimitivesLight().green, }; + String get currentValue { + if (Zeta.of(context).brightness == Brightness.light) { + return appThemes.entries + .firstWhereOrNull((element) => element.value?.value == Zeta.of(context).colors.mainPrimary.value) + ?.key ?? + "default"; + } + if (Zeta.of(context).brightness == Brightness.dark) { + return appThemes.entries + .firstWhereOrNull((element) => element.value?.shade50.value == Zeta.of(context).colors.mainPrimary.value) + ?.key ?? + "default"; + } + return 'default'; + } + @override Widget build(BuildContext context) { final zeta = Zeta.of(context); return DropdownButtonHideUnderline( child: DropdownButton( - value: currentTheme, + value: currentValue, elevation: 0, padding: EdgeInsets.all(8), icon: Nothing(), @@ -38,8 +56,14 @@ class _ZetaThemeColorSwitchState extends State { alignment: Alignment.center, child: ZetaAvatar( size: ZetaAvatarSize.xxs, - backgroundColor: color, - image: ZetaIcon(Icons.color_lens, color: color), + backgroundColor: Zeta.of(context).colors.surfaceDefault, + image: ZetaIcon( + Icons.color_lens, + color: color ?? + (Zeta.of(context).brightness == Brightness.light + ? ZetaPrimitivesLight().blue + : ZetaPrimitivesDark().blue), + ), ), ); }).toList(), diff --git a/example/lib/utils/theme_mode_switch.dart b/example/lib/utils/theme_mode_switch.dart index f9f8d06e..f642cb20 100644 --- a/example/lib/utils/theme_mode_switch.dart +++ b/example/lib/utils/theme_mode_switch.dart @@ -13,6 +13,7 @@ class ZetaThemeModeSwitch extends StatelessWidget { @override Widget build(BuildContext context) { final zeta = Zeta.of(context); + final colors = zeta.colors; return DropdownButtonHideUnderline( child: DropdownButton( @@ -22,9 +23,6 @@ class ZetaThemeModeSwitch extends StatelessWidget { icon: Nothing(), dropdownColor: zeta.colors.borderDisabled, items: _themes.map((e) { - final colors = e == ThemeMode.dark - ? ZetaSemanticColorsAA(primitives: ZetaPrimitivesDark()) - : ZetaSemanticColorsAA(primitives: ZetaPrimitivesLight()); return DropdownMenuItem( value: e, alignment: Alignment.center, diff --git a/lib/src/theme/theme_service.dart b/lib/src/theme/theme_service.dart index 808b242e..7e787794 100644 --- a/lib/src/theme/theme_service.dart +++ b/lib/src/theme/theme_service.dart @@ -5,6 +5,8 @@ import 'contrast.dart'; const String _kThemeMode = 'themeMode'; const String _kContrast = 'contrast'; +const String _kColor = 'color'; +//TODO(thelukewalton): Revert this to include color also? /// `ZetaThemeService` is an abstract class. /// It provides the structure for loading and saving themes in Zeta application.