Line data Source code
1 : // ThemeExtension has no home outside material.dart on the supported SDKs.
2 : // ignore: deprecated_member_use
3 : import 'package:flutter/material.dart' show ThemeExtension;
4 : import 'package:flutter/widgets.dart';
5 : import 'package:theme_tailor_annotation/theme_tailor_annotation.dart';
6 :
7 : part 'foss_colors.tailor.dart';
8 : part '_foss_palette.dart';
9 :
10 : /// Semantic color roles, one field per role. [light] and [dark] are baked
11 : /// constant sets; every blend and translucent overlay is resolved to a fixed
12 : /// sRGB color, so no color math runs at runtime.
13 : ///
14 : /// Components read these through `context.fossTheme`, never the private
15 : /// primitive palette. Override roles per app with [copyWith].
16 : ///
17 : /// ```dart
18 : /// const c = FossColors.light;
19 : /// final action = c.primary;
20 : /// final brand = c.copyWith(primary: const Color(0xFF6D28D9));
21 : /// ```
22 : @TailorMixin(themeGetter: ThemeGetter.none)
23 : class FossColors extends ThemeExtension<FossColors>
24 : with _$FossColorsTailorMixin {
25 : /// Creates a semantic color set. Prefer [light] or [dark] unless retheming.
26 5 : const FossColors({
27 : required this.background,
28 : required this.foreground,
29 : required this.card,
30 : required this.cardForeground,
31 : required this.popover,
32 : required this.popoverForeground,
33 : required this.primary,
34 : required this.primaryForeground,
35 : required this.secondary,
36 : required this.secondaryForeground,
37 : required this.muted,
38 : required this.mutedForeground,
39 : required this.accent,
40 : required this.accentForeground,
41 : required this.destructive,
42 : required this.destructiveForeground,
43 : required this.destructiveForegroundOn,
44 : required this.info,
45 : required this.infoForeground,
46 : required this.success,
47 : required this.successForeground,
48 : required this.warning,
49 : required this.warningForeground,
50 : required this.border,
51 : required this.input,
52 : required this.ring,
53 : });
54 :
55 : /// App background.
56 : @override
57 : final Color background;
58 :
59 : /// Default text/icon color on [background].
60 : @override
61 : final Color foreground;
62 :
63 : /// Card surface.
64 : @override
65 : final Color card;
66 :
67 : /// Text/icon color on [card].
68 : @override
69 : final Color cardForeground;
70 :
71 : /// Popover and menu surface.
72 : @override
73 : final Color popover;
74 :
75 : /// Text/icon color on [popover].
76 : @override
77 : final Color popoverForeground;
78 :
79 : /// Primary action color (solid buttons, active states).
80 : @override
81 : final Color primary;
82 :
83 : /// Text/icon color on [primary].
84 : @override
85 : final Color primaryForeground;
86 :
87 : /// Secondary surface (subtle fills).
88 : @override
89 : final Color secondary;
90 :
91 : /// Text/icon color on [secondary].
92 : @override
93 : final Color secondaryForeground;
94 :
95 : /// Muted surface (disabled, low-emphasis fills).
96 : @override
97 : final Color muted;
98 :
99 : /// Low-emphasis text color.
100 : @override
101 : final Color mutedForeground;
102 :
103 : /// Accent surface (hover fills, highlights).
104 : @override
105 : final Color accent;
106 :
107 : /// Text/icon color on [accent].
108 : @override
109 : final Color accentForeground;
110 :
111 : /// Destructive action color (delete, errors).
112 : @override
113 : final Color destructive;
114 :
115 : /// Text/icon color paired with [destructive].
116 : @override
117 : final Color destructiveForeground;
118 :
119 : /// Text/icon color on a solid [destructive] fill.
120 : @override
121 : final Color destructiveForegroundOn;
122 :
123 : /// Informational accent.
124 : @override
125 : final Color info;
126 :
127 : /// Text/icon color paired with [info].
128 : @override
129 : final Color infoForeground;
130 :
131 : /// Success accent.
132 : @override
133 : final Color success;
134 :
135 : /// Text/icon color paired with [success].
136 : @override
137 : final Color successForeground;
138 :
139 : /// Warning accent.
140 : @override
141 : final Color warning;
142 :
143 : /// Text/icon color paired with [warning].
144 : @override
145 : final Color warningForeground;
146 :
147 : /// Default border/divider color.
148 : @override
149 : final Color border;
150 :
151 : /// Form-control border color.
152 : @override
153 : final Color input;
154 :
155 : /// Focus ring color.
156 : @override
157 : final Color ring;
158 :
159 : /// Whether this is a dark set, judged by [background] luminance. Drives the
160 : /// dark-only surface lifts and rim highlights components paint at rest.
161 156 : bool get isDark => background.computeLuminance() < 0.5;
162 :
163 : /// The default light color set.
164 : static const light = FossColors(
165 : background: Color(0xFFFFFFFF),
166 : foreground: _FossPalette.neutral800,
167 : card: Color(0xFFFFFFFF),
168 : cardForeground: _FossPalette.neutral800,
169 : popover: Color(0xFFFFFFFF),
170 : popoverForeground: _FossPalette.neutral800,
171 : primary: _FossPalette.neutral800,
172 : primaryForeground: _FossPalette.neutral50,
173 : secondary: Color(0x0A000000), // black at 4% alpha
174 : secondaryForeground: _FossPalette.neutral800,
175 : muted: Color(0x0A000000), // black at 4% alpha
176 : mutedForeground: Color(0xFF686868), // neutral-500, 90% over black
177 : accent: Color(0x0A000000), // black at 4% alpha
178 : accentForeground: _FossPalette.neutral800,
179 : destructive: _FossPalette.red500,
180 : destructiveForeground: _FossPalette.red700,
181 : destructiveForegroundOn: Color(0xFFFFFFFF),
182 : info: _FossPalette.blue500,
183 : infoForeground: _FossPalette.blue700,
184 : success: _FossPalette.emerald500,
185 : successForeground: _FossPalette.emerald700,
186 : warning: _FossPalette.amber500,
187 : warningForeground: _FossPalette.amber700,
188 : border: Color(0x14000000), // black at 8% alpha
189 : input: Color(0x1A000000), // black at 10% alpha
190 : ring: _FossPalette.neutral400,
191 : );
192 :
193 : /// The default dark color set.
194 : static const dark = FossColors(
195 : background: Color(0xFF141414), // darkest neutral, 96% over white
196 : foreground: _FossPalette.neutral100,
197 : card: Color(0xFF191919), // background, 98% over white
198 : cardForeground: _FossPalette.neutral100,
199 : popover: Color(0xFF1D1D1D), // background, 96% over white
200 : popoverForeground: _FossPalette.neutral100,
201 : primary: _FossPalette.neutral100,
202 : primaryForeground: _FossPalette.neutral800,
203 : secondary: Color(0x0AFFFFFF), // white at 4% alpha
204 : secondaryForeground: _FossPalette.neutral100,
205 : muted: Color(0x0AFFFFFF), // white at 4% alpha
206 : mutedForeground: Color(0xFF818181), // neutral-500, 90% over white
207 : accent: Color(0x0AFFFFFF), // white at 4% alpha
208 : accentForeground: _FossPalette.neutral100,
209 : destructive: Color(0xFFFB414A), // red-500, 90% over white
210 : destructiveForeground: _FossPalette.red400,
211 : destructiveForegroundOn: Color(0xFFFFFFFF),
212 : info: _FossPalette.blue500,
213 : infoForeground: _FossPalette.blue400,
214 : success: _FossPalette.emerald500,
215 : successForeground: _FossPalette.emerald400,
216 : warning: _FossPalette.amber500,
217 : warningForeground: _FossPalette.amber400,
218 : border: Color(0x0FFFFFFF), // white at 6% alpha
219 : input: Color(0x14FFFFFF), // white at 8% alpha
220 : ring: _FossPalette.neutral500,
221 : );
222 : }
|