main
dart 51 lines 1.62 KB
Raw
1 import 'package:hugeicons/hugeicons.dart';
2 import 'package:flutter/material.dart';
3 import 'package:flutter_riverpod/flutter_riverpod.dart';
4 import 'package:shadcn_ui/shadcn_ui.dart';
5 import '../../../core/providers/app_providers.dart';
6 import '../../../core/theme/app_theme.dart';
7
8 class ThemeToggleButton extends ConsumerWidget {
9 const ThemeToggleButton({super.key});
10
11 @override
12 Widget build(BuildContext context, WidgetRef ref) {
13 final themeMode = ref.watch(themeModeProvider);
14
15 return ShadIconButton.ghost(
16 onPressed: () {
17 // Cycle through: System -> Light -> Dark -> Claude -> System
18 final nextMode = AppThemeType
19 .values[(themeMode.index + 1) % AppThemeType.values.length];
20 ref.read(themeModeProvider.notifier).setThemeMode(nextMode);
21 },
22 icon: AnimatedSwitcher(
23 duration: const Duration(milliseconds: 300),
24 transitionBuilder: (child, animation) {
25 return RotationTransition(
26 turns: animation,
27 child: FadeTransition(opacity: animation, child: child),
28 );
29 },
30 child: HugeIcon(
31 icon: _getIconForMode(themeMode),
32 key: ValueKey(themeMode),
33 size: 20,
34 ),
35 ),
36 );
37 }
38
39 List<List<dynamic>> _getIconForMode(AppThemeType mode) {
40 switch (mode) {
41 case AppThemeType.system:
42 return HugeIcons.strokeRoundedComputer;
43 case AppThemeType.light:
44 return HugeIcons.strokeRoundedSun01;
45 case AppThemeType.dark:
46 return HugeIcons.strokeRoundedMoon02;
47 case AppThemeType.claude:
48 return HugeIcons.strokeRoundedTree01;
49 }
50 }
51 }