Skip to content

Commit b40532e

Browse files
committed
refactor(theme): tighten the colour helper API
Address review feedback on the new colour system. Drop getAvailabilityColor's separate brightness parameter and read it from the ColorScheme instead, so a caller can no longer pass a dark scheme alongside Brightness.light. Nothing outside this PR calls it yet, so the signature is free to change now. Correct getAccentColor's doc comment: the unknown-category fallback is adapted for dark surfaces like any other hue, so the dark fallback is a lifted navy rather than the navy literal the comment claimed. No behaviour change; goldens unaffected.
1 parent 3206ddc commit b40532e

4 files changed

Lines changed: 12 additions & 23 deletions

File tree

lib/screens/my_festival_screen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@ class _MyFestivalScreenState extends State<MyFestivalScreen> {
504504
final color = CategoryColorHelper.getAvailabilityColor(
505505
atRisk,
506506
theme.colorScheme,
507-
theme.brightness,
508507
);
509508
return Container(
510509
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),

lib/utils/category_color_helper.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ class CategoryColorHelper {
7070
/// rows and the similar-drinks carousel.
7171
///
7272
/// Derived from [brightness]: the fixed hue in light mode, a lightness-lifted
73-
/// variant in dark mode so the edge reads against a dark surface. Falls back
74-
/// to CBF navy for unknown categories.
73+
/// variant in dark mode so the edge reads against a dark surface.
74+
///
75+
/// An unrecognised category falls back to CBF navy, which is adapted for
76+
/// dark surfaces the same way a real category is — so the dark fallback is a
77+
/// lifted navy, not the navy literal.
7578
static Color getAccentColor(String category, Brightness brightness) {
7679
final hue = _categoryHues[category] ?? _fallbackHue;
7780
return brightness == Brightness.dark ? _liftForDark(hue) : hue;
@@ -109,12 +112,14 @@ class CategoryColorHelper {
109112
/// should track the app's error language, so [colorScheme] is required.
110113
/// Every other state uses a fixed light/dark pair chosen for legibility on
111114
/// both surfaces.
115+
///
116+
/// Brightness is read from [colorScheme] rather than taken separately, so a
117+
/// caller cannot pass a dark scheme alongside a light brightness.
112118
static Color getAvailabilityColor(
113119
AvailabilityStatus status,
114120
ColorScheme colorScheme,
115-
Brightness brightness,
116121
) {
117-
final isDark = brightness == Brightness.dark;
122+
final isDark = colorScheme.brightness == Brightness.dark;
118123
switch (status) {
119124
case AvailabilityStatus.plenty:
120125
return isDark ? const Color(0xFF4CAF50) : const Color(0xFF2E7D32);

lib/widgets/drink_card.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ class _AvailabilityChip extends StatelessWidget {
273273
final color = CategoryColorHelper.getAvailabilityColor(
274274
status,
275275
theme.colorScheme,
276-
theme.brightness,
277276
);
278277
String label;
279278
IconData icon;

test/category_color_helper_test.dart

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,12 @@ void main() {
149149
};
150150
for (final entry in expected.entries) {
151151
expect(
152-
CategoryColorHelper.getAvailabilityColor(
153-
entry.key,
154-
lightScheme,
155-
Brightness.light,
156-
),
152+
CategoryColorHelper.getAvailabilityColor(entry.key, lightScheme),
157153
entry.value.$1,
158154
reason: '${entry.key} light',
159155
);
160156
expect(
161-
CategoryColorHelper.getAvailabilityColor(
162-
entry.key,
163-
darkScheme,
164-
Brightness.dark,
165-
),
157+
CategoryColorHelper.getAvailabilityColor(entry.key, darkScheme),
166158
entry.value.$2,
167159
reason: '${entry.key} dark',
168160
);
@@ -174,15 +166,13 @@ void main() {
174166
CategoryColorHelper.getAvailabilityColor(
175167
AvailabilityStatus.out,
176168
lightScheme,
177-
Brightness.light,
178169
),
179170
lightScheme.error,
180171
);
181172
expect(
182173
CategoryColorHelper.getAvailabilityColor(
183174
AvailabilityStatus.out,
184175
darkScheme,
185-
Brightness.dark,
186176
),
187177
darkScheme.error,
188178
);
@@ -191,11 +181,7 @@ void main() {
191181
test('covers every AvailabilityStatus', () {
192182
for (final status in AvailabilityStatus.values) {
193183
expect(
194-
() => CategoryColorHelper.getAvailabilityColor(
195-
status,
196-
lightScheme,
197-
Brightness.light,
198-
),
184+
() => CategoryColorHelper.getAvailabilityColor(status, lightScheme),
199185
returnsNormally,
200186
);
201187
}

0 commit comments

Comments
 (0)