@@ -33,7 +33,8 @@ const FlexSubThemesData _commonSubThemesData = FlexSubThemesData(
33
33
// Helper function to apply common text theme customizations
34
34
TextTheme _customizeTextTheme (
35
35
TextTheme baseTextTheme, {
36
- required AppTextScaleFactor appTextScaleFactor, // Added parameter
36
+ required AppTextScaleFactor appTextScaleFactor,
37
+ required AppFontWeight appFontWeight, // Added parameter
37
38
}) {
38
39
// Define font size factors
39
40
double factor;
@@ -52,39 +53,60 @@ TextTheme _customizeTextTheme(
52
53
double ? applyFactor (double ? baseSize) =>
53
54
baseSize != null ? (baseSize * factor).roundToDouble () : null ;
54
55
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
+
55
70
return baseTextTheme.copyWith (
56
71
// --- 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.
57
75
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
60
78
),
61
79
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
64
82
),
65
83
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
68
86
),
69
87
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
72
90
),
73
91
74
92
// --- Body/Content Styles ---
93
+ // Apply user-selected font weight to body text
75
94
bodyLarge: baseTextTheme.bodyLarge? .copyWith (
76
- fontSize: applyFactor (16 ), // Apply factor
95
+ fontSize: applyFactor (16 ),
77
96
height: 1.5 ,
97
+ fontWeight: selectedFontWeight, // Apply selected weight
78
98
),
79
99
bodyMedium: baseTextTheme.bodyMedium? .copyWith (
80
- fontSize: applyFactor (14 ), // Apply factor
100
+ fontSize: applyFactor (14 ),
81
101
height: 1.4 ,
102
+ fontWeight: selectedFontWeight, // Apply selected weight
82
103
),
83
104
84
105
// --- Metadata/Caption Styles ---
106
+ // Captions might also benefit from user-defined weight or stay regular.
85
107
labelSmall: baseTextTheme.labelSmall? .copyWith (
86
- fontSize: applyFactor (12 ), // Apply factor
87
- fontWeight: FontWeight .normal,
108
+ fontSize: applyFactor (12 ),
109
+ fontWeight: selectedFontWeight, // Apply selected weight
88
110
),
89
111
90
112
// --- Button Style (Usually default is fine) ---
@@ -120,10 +142,11 @@ TextTheme Function([TextTheme?]) _getGoogleFontTextTheme(String? fontFamily) {
120
142
121
143
/// Defines the application's light theme using FlexColorScheme.
122
144
///
123
- /// Takes the active [scheme] , [appTextScaleFactor] , and optional [fontFamily] .
145
+ /// Takes the active [scheme] , [appTextScaleFactor] , [appFontWeight] , and optional [fontFamily] .
124
146
ThemeData lightTheme ({
125
147
required FlexScheme scheme,
126
- required AppTextScaleFactor appTextScaleFactor, // Added parameter
148
+ required AppTextScaleFactor appTextScaleFactor,
149
+ required AppFontWeight appFontWeight, // Added parameter
127
150
String ? fontFamily,
128
151
}) {
129
152
final textThemeGetter = _getGoogleFontTextTheme (fontFamily);
@@ -132,21 +155,22 @@ ThemeData lightTheme({
132
155
return FlexThemeData .light (
133
156
scheme: scheme,
134
157
fontFamily: fontFamily,
135
- // Pass appTextScaleFactor to customizeTextTheme
136
158
textTheme: _customizeTextTheme (
137
159
baseTextTheme,
138
160
appTextScaleFactor: appTextScaleFactor,
161
+ appFontWeight: appFontWeight, // Pass new parameter
139
162
),
140
163
subThemesData: _commonSubThemesData,
141
164
);
142
165
}
143
166
144
167
/// Defines the application's dark theme using FlexColorScheme.
145
168
///
146
- /// Takes the active [scheme] , [appTextScaleFactor] , and optional [fontFamily] .
169
+ /// Takes the active [scheme] , [appTextScaleFactor] , [appFontWeight] , and optional [fontFamily] .
147
170
ThemeData darkTheme ({
148
171
required FlexScheme scheme,
149
- required AppTextScaleFactor appTextScaleFactor, // Added parameter
172
+ required AppTextScaleFactor appTextScaleFactor,
173
+ required AppFontWeight appFontWeight, // Added parameter
150
174
String ? fontFamily,
151
175
}) {
152
176
final textThemeGetter = _getGoogleFontTextTheme (fontFamily);
@@ -157,10 +181,10 @@ ThemeData darkTheme({
157
181
return FlexThemeData .dark (
158
182
scheme: scheme,
159
183
fontFamily: fontFamily,
160
- // Pass appTextScaleFactor to customizeTextTheme
161
184
textTheme: _customizeTextTheme (
162
185
baseTextTheme,
163
186
appTextScaleFactor: appTextScaleFactor,
187
+ appFontWeight: appFontWeight, // Pass new parameter
164
188
),
165
189
subThemesData: _commonSubThemesData,
166
190
);
0 commit comments