Skip to content

Commit

Permalink
fix: Example app color button
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Sep 4, 2024
1 parent d55b401 commit 190cc39
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
34 changes: 29 additions & 5 deletions example/lib/utils/theme_color_switch.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,21 +12,38 @@ class ZetaThemeColorSwitch extends StatefulWidget {
class _ZetaThemeColorSwitchState extends State<ZetaThemeColorSwitch> {
String currentTheme = "default";

final Map<String, ZetaColorSwatch> appThemes = {
"default": ZetaPrimitivesLight().blue,
final Map<String, ZetaColorSwatch?> 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<String>(
value: currentTheme,
value: currentValue,
elevation: 0,
padding: EdgeInsets.all(8),
icon: Nothing(),
Expand All @@ -38,8 +56,14 @@ class _ZetaThemeColorSwitchState extends State<ZetaThemeColorSwitch> {
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(),
Expand Down
4 changes: 1 addition & 3 deletions example/lib/utils/theme_mode_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThemeMode>(
Expand All @@ -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<ThemeMode>(
value: e,
alignment: Alignment.center,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/theme/theme_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 190cc39

Please sign in to comment.