|
| 1 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
1 | 2 | import 'package:shadcn_flutter/shadcn_flutter.dart'; |
2 | 3 |
|
| 4 | +import '../../../theme/cubit/theme_cubit.dart'; |
| 5 | + |
3 | 6 | class ButtonThemes extends StatelessWidget { |
4 | 7 | const ButtonThemes({super.key, required this.child}); |
5 | 8 |
|
6 | 9 | final Widget child; |
7 | 10 |
|
8 | 11 | @override |
9 | 12 | Widget build(BuildContext context) { |
| 13 | + final isDark = context.watch<ThemeCubit>().state.isDarkMode; |
| 14 | + final bgColor = isDark ? Colors.gray[400] : Colors.gray[100]; |
| 15 | + final textColor = isDark ? Colors.black : Colors.blue[900]; |
| 16 | + final iconColor = textColor; |
10 | 17 | return ComponentTheme( |
11 | 18 | data: OutlineButtonTheme( |
12 | 19 | decoration: (context, states, defaultDecoration) { |
13 | | - return defaultDecoration; |
14 | | - // return defaultDecoration.copyWithIfBoxDecoration( |
15 | | - // color: Colors.red, |
16 | | - // border: Border.all(color: Colors.green, width: 10), |
17 | | - // ); |
| 20 | + if (states.contains(WidgetState.disabled)) { |
| 21 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 22 | + color: isDark ? Colors.gray[500] : Colors.gray[200], |
| 23 | + border: Border.all( |
| 24 | + color: isDark ? Colors.gray[600] : Colors.gray[300], |
| 25 | + ), |
| 26 | + ); |
| 27 | + } else if (states.contains(WidgetState.hovered)) { |
| 28 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 29 | + color: isDark ? Colors.gray[300] : Colors.gray[200], |
| 30 | + border: Border.all( |
| 31 | + color: isDark ? Colors.blue[300] : Colors.blue[600], |
| 32 | + ), |
| 33 | + ); |
| 34 | + } else { |
| 35 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 36 | + color: bgColor, |
| 37 | + border: Border.all( |
| 38 | + color: isDark ? Colors.blue[100] : Colors.blue[900], |
| 39 | + ), |
| 40 | + ); |
| 41 | + } |
| 42 | + }, |
| 43 | + textStyle: (context, states, defaultTextStyle) { |
| 44 | + return defaultTextStyle.copyWith(color: textColor); |
| 45 | + }, |
| 46 | + iconTheme: (context, states, defaultIconTheme) { |
| 47 | + return defaultIconTheme.copyWith(color: iconColor); |
18 | 48 | }, |
19 | 49 | ), |
20 | 50 | child: ComponentTheme( |
21 | 51 | data: SecondaryButtonTheme( |
22 | 52 | decoration: (context, states, defaultDecoration) { |
23 | | - return defaultDecoration; |
24 | | - // return defaultDecoration.copyWithIfBoxDecoration( |
25 | | - // color: Colors.red, |
26 | | - // border: Border.all(color: Colors.green, width: 10), |
27 | | - // ); |
| 53 | + if (states.contains(WidgetState.disabled)) { |
| 54 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 55 | + color: isDark ? Colors.gray[500] : Colors.gray[200], |
| 56 | + ); |
| 57 | + } else if (states.contains(WidgetState.hovered)) { |
| 58 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 59 | + color: isDark ? Colors.gray[300] : Colors.gray[200], |
| 60 | + ); |
| 61 | + } else { |
| 62 | + return defaultDecoration.copyWithIfBoxDecoration(color: bgColor); |
| 63 | + } |
28 | 64 | }, |
| 65 | + textStyle: (context, states, defaultTextStyle) { |
| 66 | + return defaultTextStyle.copyWith(color: textColor); |
| 67 | + }, |
| 68 | + iconTheme: (context, states, defaultIconTheme) { |
| 69 | + return defaultIconTheme.copyWith(color: iconColor); |
| 70 | + }, |
| 71 | + ), |
| 72 | + child: ComponentTheme( |
| 73 | + data: GhostButtonTheme( |
| 74 | + decoration: (context, states, defaultDecoration) { |
| 75 | + if (states.contains(WidgetState.disabled)) { |
| 76 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 77 | + color: Colors.transparent, |
| 78 | + ); |
| 79 | + } else if (states.contains(WidgetState.hovered)) { |
| 80 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 81 | + color: isDark ? Colors.gray[600] : Colors.gray[100], |
| 82 | + ); |
| 83 | + } else { |
| 84 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 85 | + color: Colors.transparent, |
| 86 | + ); |
| 87 | + } |
| 88 | + }, |
| 89 | + textStyle: (context, states, defaultTextStyle) { |
| 90 | + if (states.contains(WidgetState.disabled)) { |
| 91 | + return defaultTextStyle.copyWith( |
| 92 | + color: isDark ? Colors.gray[300] : Colors.gray[600], |
| 93 | + ); |
| 94 | + } else if (states.contains(WidgetState.hovered)) { |
| 95 | + return defaultTextStyle.copyWith( |
| 96 | + color: isDark ? Colors.gray[300] : Colors.blue[900], |
| 97 | + ); |
| 98 | + } else { |
| 99 | + return defaultTextStyle.copyWith( |
| 100 | + color: isDark ? Colors.gray[300] : Colors.blue[900], |
| 101 | + ); |
| 102 | + } |
| 103 | + }, |
| 104 | + iconTheme: (context, states, defaultIconTheme) { |
| 105 | + return defaultIconTheme.copyWith( |
| 106 | + color: isDark ? Colors.gray[300] : Colors.blue[900], |
| 107 | + ); |
| 108 | + }, |
| 109 | + ), |
| 110 | + child: ComponentTheme( |
| 111 | + data: DestructiveButtonTheme( |
| 112 | + decoration: (context, states, defaultDecoration) { |
| 113 | + if (states.contains(WidgetState.disabled)) { |
| 114 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 115 | + color: Colors.red[500], |
| 116 | + ); |
| 117 | + } else if (states.contains(WidgetState.hovered)) { |
| 118 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 119 | + color: Colors.red[700], |
| 120 | + border: Border.all(color: Colors.red[700]), |
| 121 | + ); |
| 122 | + } else { |
| 123 | + return defaultDecoration.copyWithIfBoxDecoration( |
| 124 | + color: Colors.red[500], |
| 125 | + border: Border.all(color: Colors.red[700]), |
| 126 | + ); |
| 127 | + } |
| 128 | + }, |
| 129 | + textStyle: (context, states, defaultTextStyle) { |
| 130 | + return defaultTextStyle.copyWith(color: Colors.white); |
| 131 | + }, |
| 132 | + iconTheme: (context, states, defaultIconTheme) { |
| 133 | + return defaultIconTheme.copyWith(color: Colors.white); |
| 134 | + }, |
| 135 | + ), |
| 136 | + child: ComponentTheme( |
| 137 | + data: LinkButtonTheme( |
| 138 | + textStyle: (context, states, defaultTextStyle) { |
| 139 | + if (states.contains(WidgetState.disabled)) { |
| 140 | + return defaultTextStyle.copyWith( |
| 141 | + color: isDark ? Colors.gray[400] : Colors.gray[600], |
| 142 | + ); |
| 143 | + } else { |
| 144 | + return defaultTextStyle.copyWith( |
| 145 | + color: isDark ? Colors.white : Colors.blue[900], |
| 146 | + ); |
| 147 | + } |
| 148 | + }, |
| 149 | + iconTheme: (context, states, defaultIconTheme) { |
| 150 | + if (states.contains(WidgetState.disabled)) { |
| 151 | + return defaultIconTheme.copyWith( |
| 152 | + color: isDark ? Colors.gray[400] : Colors.gray[600], |
| 153 | + ); |
| 154 | + } else { |
| 155 | + return defaultIconTheme.copyWith( |
| 156 | + color: isDark ? Colors.white : Colors.blue[900], |
| 157 | + ); |
| 158 | + } |
| 159 | + }, |
| 160 | + ), |
| 161 | + child: child, |
| 162 | + ), |
| 163 | + ), |
29 | 164 | ), |
30 | | - child: child, |
31 | 165 | ), |
32 | 166 | ); |
33 | 167 | } |
|
0 commit comments