Skip to content

Commit af81459

Browse files
committed
feat(theme): add font weight customization
- Added appFontWeight parameter - Applied font weight to body text - Support light, regular, and bold
1 parent cea66af commit af81459

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

lib/shared/theme/app_theme.dart

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const FlexSubThemesData _commonSubThemesData = FlexSubThemesData(
3333
// Helper function to apply common text theme customizations
3434
TextTheme _customizeTextTheme(
3535
TextTheme baseTextTheme, {
36-
required AppTextScaleFactor appTextScaleFactor, // Added parameter
36+
required AppTextScaleFactor appTextScaleFactor,
37+
required AppFontWeight appFontWeight, // Added parameter
3738
}) {
3839
// Define font size factors
3940
double factor;
@@ -52,39 +53,60 @@ TextTheme _customizeTextTheme(
5253
double? applyFactor(double? baseSize) =>
5354
baseSize != null ? (baseSize * factor).roundToDouble() : null;
5455

56+
// Map AppFontWeight to FontWeight
57+
FontWeight selectedFontWeight;
58+
switch (appFontWeight) {
59+
case AppFontWeight.light:
60+
selectedFontWeight = FontWeight.w300;
61+
break;
62+
case AppFontWeight.regular:
63+
selectedFontWeight = FontWeight.w400;
64+
break;
65+
case AppFontWeight.bold:
66+
selectedFontWeight = FontWeight.w700;
67+
break;
68+
}
69+
5570
return baseTextTheme.copyWith(
5671
// --- Headline/Title Styles ---
72+
// Headlines and titles often have their own explicit weights,
73+
// but we can make them configurable if needed. For now, let's assume
74+
// body text is the primary target for user-defined weight.
5775
headlineLarge: baseTextTheme.headlineLarge?.copyWith(
58-
fontSize: applyFactor(28), // Apply factor
59-
fontWeight: FontWeight.bold,
76+
fontSize: applyFactor(28),
77+
fontWeight: FontWeight.bold, // Keeping titles bold by default
6078
),
6179
headlineMedium: baseTextTheme.headlineMedium?.copyWith(
62-
fontSize: applyFactor(24), // Apply factor
63-
fontWeight: FontWeight.bold,
80+
fontSize: applyFactor(24),
81+
fontWeight: FontWeight.bold, // Keeping titles bold by default
6482
),
6583
titleLarge: baseTextTheme.titleLarge?.copyWith(
66-
fontSize: applyFactor(18), // Apply factor
67-
fontWeight: FontWeight.w600,
84+
fontSize: applyFactor(18),
85+
fontWeight: FontWeight.w600, // Keeping titles semi-bold by default
6886
),
6987
titleMedium: baseTextTheme.titleMedium?.copyWith(
70-
fontSize: applyFactor(16), // Apply factor
71-
fontWeight: FontWeight.w600,
88+
fontSize: applyFactor(16),
89+
fontWeight: FontWeight.w600, // Keeping titles semi-bold by default
7290
),
7391

7492
// --- Body/Content Styles ---
93+
// Apply user-selected font weight to body text
7594
bodyLarge: baseTextTheme.bodyLarge?.copyWith(
76-
fontSize: applyFactor(16), // Apply factor
95+
fontSize: applyFactor(16),
7796
height: 1.5,
97+
fontWeight: selectedFontWeight, // Apply selected weight
7898
),
7999
bodyMedium: baseTextTheme.bodyMedium?.copyWith(
80-
fontSize: applyFactor(14), // Apply factor
100+
fontSize: applyFactor(14),
81101
height: 1.4,
102+
fontWeight: selectedFontWeight, // Apply selected weight
82103
),
83104

84105
// --- Metadata/Caption Styles ---
106+
// Captions might also benefit from user-defined weight or stay regular.
85107
labelSmall: baseTextTheme.labelSmall?.copyWith(
86-
fontSize: applyFactor(12), // Apply factor
87-
fontWeight: FontWeight.normal,
108+
fontSize: applyFactor(12),
109+
fontWeight: selectedFontWeight, // Apply selected weight
88110
),
89111

90112
// --- Button Style (Usually default is fine) ---
@@ -120,10 +142,11 @@ TextTheme Function([TextTheme?]) _getGoogleFontTextTheme(String? fontFamily) {
120142

121143
/// Defines the application's light theme using FlexColorScheme.
122144
///
123-
/// Takes the active [scheme], [appTextScaleFactor], and optional [fontFamily].
145+
/// Takes the active [scheme], [appTextScaleFactor], [appFontWeight], and optional [fontFamily].
124146
ThemeData lightTheme({
125147
required FlexScheme scheme,
126-
required AppTextScaleFactor appTextScaleFactor, // Added parameter
148+
required AppTextScaleFactor appTextScaleFactor,
149+
required AppFontWeight appFontWeight, // Added parameter
127150
String? fontFamily,
128151
}) {
129152
final textThemeGetter = _getGoogleFontTextTheme(fontFamily);
@@ -132,21 +155,22 @@ ThemeData lightTheme({
132155
return FlexThemeData.light(
133156
scheme: scheme,
134157
fontFamily: fontFamily,
135-
// Pass appTextScaleFactor to customizeTextTheme
136158
textTheme: _customizeTextTheme(
137159
baseTextTheme,
138160
appTextScaleFactor: appTextScaleFactor,
161+
appFontWeight: appFontWeight, // Pass new parameter
139162
),
140163
subThemesData: _commonSubThemesData,
141164
);
142165
}
143166

144167
/// Defines the application's dark theme using FlexColorScheme.
145168
///
146-
/// Takes the active [scheme], [appTextScaleFactor], and optional [fontFamily].
169+
/// Takes the active [scheme], [appTextScaleFactor], [appFontWeight], and optional [fontFamily].
147170
ThemeData darkTheme({
148171
required FlexScheme scheme,
149-
required AppTextScaleFactor appTextScaleFactor, // Added parameter
172+
required AppTextScaleFactor appTextScaleFactor,
173+
required AppFontWeight appFontWeight, // Added parameter
150174
String? fontFamily,
151175
}) {
152176
final textThemeGetter = _getGoogleFontTextTheme(fontFamily);
@@ -157,10 +181,10 @@ ThemeData darkTheme({
157181
return FlexThemeData.dark(
158182
scheme: scheme,
159183
fontFamily: fontFamily,
160-
// Pass appTextScaleFactor to customizeTextTheme
161184
textTheme: _customizeTextTheme(
162185
baseTextTheme,
163186
appTextScaleFactor: appTextScaleFactor,
187+
appFontWeight: appFontWeight, // Pass new parameter
164188
),
165189
subThemesData: _commonSubThemesData,
166190
);

0 commit comments

Comments
 (0)