Skip to content

Commit 0bf24ae

Browse files
committed
refactor(theme): Use switch for font selection
- Improved readability - Added 'SystemDefault' case - Handles null fontFamily
1 parent d0a35ea commit 0bf24ae

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

lib/shared/theme/app_theme.dart

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,32 +121,28 @@ TextTheme _customizeTextTheme(
121121
// Corrected return type to match GoogleFonts functions (positional optional)
122122
TextTheme Function([TextTheme?]) _getGoogleFontTextTheme(String? fontFamily) {
123123
print('[_getGoogleFontTextTheme] Received fontFamily: $fontFamily');
124-
// Map font family names (as used in AppBloc mapping) to GoogleFonts functions
125-
if (fontFamily == GoogleFonts.roboto().fontFamily) {
126-
print('[_getGoogleFontTextTheme] Returning GoogleFonts.robotoTextTheme');
127-
return GoogleFonts.robotoTextTheme;
124+
switch (fontFamily) {
125+
case 'Roboto':
126+
print('[_getGoogleFontTextTheme] Returning GoogleFonts.robotoTextTheme');
127+
return GoogleFonts.robotoTextTheme;
128+
case 'OpenSans':
129+
print('[_getGoogleFontTextTheme] Returning GoogleFonts.openSansTextTheme');
130+
return GoogleFonts.openSansTextTheme;
131+
case 'Lato':
132+
print('[_getGoogleFontTextTheme] Returning GoogleFonts.latoTextTheme');
133+
return GoogleFonts.latoTextTheme;
134+
case 'Montserrat':
135+
print('[_getGoogleFontTextTheme] Returning GoogleFonts.montserratTextTheme');
136+
return GoogleFonts.montserratTextTheme;
137+
case 'Merriweather':
138+
print('[_getGoogleFontTextTheme] Returning GoogleFonts.merriweatherTextTheme');
139+
return GoogleFonts.merriweatherTextTheme;
140+
case 'SystemDefault':
141+
case null:
142+
default:
143+
print('[_getGoogleFontTextTheme] Defaulting to GoogleFonts.notoSansTextTheme for input: $fontFamily');
144+
return GoogleFonts.notoSansTextTheme;
128145
}
129-
if (fontFamily == GoogleFonts.openSans().fontFamily) {
130-
print('[_getGoogleFontTextTheme] Returning GoogleFonts.openSansTextTheme');
131-
return GoogleFonts.openSansTextTheme;
132-
}
133-
if (fontFamily == GoogleFonts.lato().fontFamily) {
134-
print('[_getGoogleFontTextTheme] Returning GoogleFonts.latoTextTheme');
135-
return GoogleFonts.latoTextTheme;
136-
}
137-
if (fontFamily == GoogleFonts.montserrat().fontFamily) {
138-
print('[_getGoogleFontTextTheme] Returning GoogleFonts.montserratTextTheme');
139-
return GoogleFonts.montserratTextTheme;
140-
}
141-
if (fontFamily == GoogleFonts.merriweather().fontFamily) {
142-
print('[_getGoogleFontTextTheme] Returning GoogleFonts.merriweatherTextTheme');
143-
return GoogleFonts.merriweatherTextTheme;
144-
}
145-
// Add mappings for other AppFontType values if needed
146-
147-
// Default fallback if fontFamily is null or not recognized
148-
print('[_getGoogleFontTextTheme] Defaulting to GoogleFonts.notoSansTextTheme');
149-
return GoogleFonts.notoSansTextTheme;
150146
}
151147

152148
/// Defines the application's light theme using FlexColorScheme.

0 commit comments

Comments
 (0)