Skip to content

Commit fc09afc

Browse files
committed
refactor: Inline button theme colors and refine GhostButtonTheme
This commit simplifies the `ButtonThemeOverride` by inlining theme-dependent color variables and cleaning up logic within `GhostButtonTheme`. ### Key Changes: * **Refactor Color Variables:** * Removed local variables (`bgColor`, `textColor`, `iconColor`) in favor of direct ternary expressions within `OutlineButtonTheme` and `SecondaryButtonTheme`. This improves clarity on how colors react to the current `isDarkMode` state. * **`GhostButtonTheme` Adjustments:** * Removed redundant `WidgetState.disabled` check for the background decoration. * Simplified `textStyle` by removing an identical `hovered` state override, falling back to the default style. * Updated `iconTheme` to explicitly handle the `disabled` state color, ensuring consistency with the text styling.
1 parent b60c853 commit fc09afc

1 file changed

Lines changed: 16 additions & 21 deletions

File tree

lib/screens/widgets/overrides/button_themes.dart

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class ButtonThemes extends StatelessWidget {
1111
@override
1212
Widget build(BuildContext context) {
1313
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;
1714
return ComponentTheme(
1815
data: OutlineButtonTheme(
1916
decoration: (context, states, defaultDecoration) {
@@ -33,18 +30,18 @@ class ButtonThemes extends StatelessWidget {
3330
);
3431
} else {
3532
return defaultDecoration.copyWithIfBoxDecoration(
36-
color: bgColor,
33+
color: isDark ? Colors.gray[400] : Colors.gray[100],
3734
border: Border.all(
3835
color: isDark ? Colors.blue[100] : Colors.blue[900],
3936
),
4037
);
4138
}
4239
},
4340
textStyle: (context, states, defaultTextStyle) {
44-
return defaultTextStyle.copyWith(color: textColor);
41+
return defaultTextStyle.copyWith(color: isDark ? Colors.black : Colors.blue[900]);
4542
},
4643
iconTheme: (context, states, defaultIconTheme) {
47-
return defaultIconTheme.copyWith(color: iconColor);
44+
return defaultIconTheme.copyWith(color: isDark ? Colors.black : Colors.blue[900]);
4845
},
4946
),
5047
child: ComponentTheme(
@@ -59,24 +56,20 @@ class ButtonThemes extends StatelessWidget {
5956
color: isDark ? Colors.gray[300] : Colors.gray[200],
6057
);
6158
} else {
62-
return defaultDecoration.copyWithIfBoxDecoration(color: bgColor);
59+
return defaultDecoration.copyWithIfBoxDecoration(color: isDark ? Colors.gray[400] : Colors.gray[100]);
6360
}
6461
},
6562
textStyle: (context, states, defaultTextStyle) {
66-
return defaultTextStyle.copyWith(color: textColor);
63+
return defaultTextStyle.copyWith(color: isDark ? Colors.black : Colors.blue[900]);
6764
},
6865
iconTheme: (context, states, defaultIconTheme) {
69-
return defaultIconTheme.copyWith(color: iconColor);
66+
return defaultIconTheme.copyWith(color: isDark ? Colors.black : Colors.blue[900]);
7067
},
7168
),
7269
child: ComponentTheme(
7370
data: GhostButtonTheme(
7471
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)) {
72+
if (states.contains(WidgetState.hovered)) {
8073
return defaultDecoration.copyWithIfBoxDecoration(
8174
color: isDark ? Colors.gray[600] : Colors.gray[100],
8275
);
@@ -91,20 +84,22 @@ class ButtonThemes extends StatelessWidget {
9184
return defaultTextStyle.copyWith(
9285
color: isDark ? Colors.gray[300] : Colors.gray[600],
9386
);
94-
} else if (states.contains(WidgetState.hovered)) {
95-
return defaultTextStyle.copyWith(
96-
color: isDark ? Colors.gray[300] : Colors.blue[900],
97-
);
9887
} else {
9988
return defaultTextStyle.copyWith(
10089
color: isDark ? Colors.gray[300] : Colors.blue[900],
10190
);
10291
}
10392
},
10493
iconTheme: (context, states, defaultIconTheme) {
105-
return defaultIconTheme.copyWith(
106-
color: isDark ? Colors.gray[300] : Colors.blue[900],
107-
);
94+
if (states.contains(WidgetState.disabled)) {
95+
return defaultIconTheme.copyWith(
96+
color: isDark ? Colors.gray[300] : Colors.gray[600],
97+
);
98+
} else {
99+
return defaultIconTheme.copyWith(
100+
color: isDark ? Colors.gray[300] : Colors.blue[900],
101+
);
102+
}
108103
},
109104
),
110105
child: ComponentTheme(

0 commit comments

Comments
 (0)