generate method
ThemeSpec
generate(
- int seed,
- ThemeFamily family,
- int engineVersion, {
- bool accessible = false,
- int? seedHueTenths,
The theme for (seed, family, engineVersion) — and the Accessible
lock when accessible (labels and display text ≥ 7:1).
Throws UnsupportedEngineVersion for versions this build cannot
reproduce, and ArgumentError for ThemeFamily.plain and for
families engineVersion has not shipped (their placeholder
definitions are not frozen, so their output would not be a pure
function of the version).
seedHueTenths (0–3599, M3 Expressive only) is the Android "Match my
wallpaper" variant (spec §5.3 #1): it replaces the palette stream's
base-hue draw (every other draw is unchanged), the result is marked
ThemeVariant.wallpaper, and every guardrail runs exactly as for a
generated theme.
Implementation
ThemeSpec generate(
int seed,
ThemeFamily family,
int engineVersion, {
bool accessible = false,
int? seedHueTenths,
}) {
if (!supportedEngineVersions.contains(engineVersion)) {
throw UnsupportedEngineVersion(engineVersion);
}
if (family == ThemeFamily.plain) {
throw ArgumentError.value(family, 'family', 'plain is never generated');
}
if (!familyShippedAt(family, engineVersion)) {
throw ArgumentError.value(
family,
'family',
'not shipped at engine version $engineVersion',
);
}
if (seedHueTenths != null && family != ThemeFamily.m3Expressive) {
throw ArgumentError.value(
family,
'family',
'only Material 3 Expressive has a wallpaper variant',
);
}
final s = seed & 0xFFFFFFFF;
for (var attempt = 0; attempt < maxAttempts; attempt++) {
final candidate = buildCandidate(
s,
family,
engineVersion,
attempt: attempt,
accessible: accessible,
seedHueTenths: seedHueTenths,
);
final fixed = repairTheme(candidate);
if (fixed != null) return fixed;
}
return heroFallback(s, family, accessible: accessible);
}