feat: usar a cor escolhida tal e qual e opcao de suavizar
- TatuPalette.scheme aceita softenPrimary e passa a usar a seed como primary, onPrimary por contraste e surfaceTint, em vez da paleta tonal do Material 3 - nova opcao AppSettings.softenThemeColor (default false, ou seja cor exacta) - interruptor 'Suavizar cor do tema' em Configuracoes > Aparencia, com l10n en/pt - a opcao e sincronizada via account data (soften_theme_color) e mantida localmente como fallback, tal como a cor do tema - setApplicationAccountColor e updateApplicationAccountConfig preservam o novo campo - um unico sync de account data actualiza cor e opcao - testes de serializacao e round-trip para o novo campo
This commit is contained in:
@@ -97,7 +97,14 @@ abstract class TatuPalette {
|
||||
/// When a [seed] is provided (e.g. a color chosen by the user or a system
|
||||
/// dynamic color), its tonal values are used for the primary family while
|
||||
/// the brand surfaces, accent and error colors are preserved.
|
||||
static ColorScheme scheme(Brightness brightness, [Color? seed]) {
|
||||
///
|
||||
/// Unless [softenPrimary] is set, the seed is used verbatim as the primary
|
||||
/// color, because the Material 3 tonal palette noticeably dulls it down.
|
||||
static ColorScheme scheme(
|
||||
Brightness brightness, [
|
||||
Color? seed,
|
||||
bool softenPrimary = false,
|
||||
]) {
|
||||
final isDark = brightness == Brightness.dark;
|
||||
final p = isDark ? _dark : _light;
|
||||
final base = ColorScheme.fromSeed(
|
||||
@@ -106,12 +113,17 @@ abstract class TatuPalette {
|
||||
dynamicSchemeVariant: DynamicSchemeVariant.rainbow,
|
||||
);
|
||||
final useBrandPrimary = seed == null;
|
||||
// Only force the exact color when the caller did not ask for the soft
|
||||
// Material 3 palette. `null` here means "keep the value from [base]".
|
||||
final exactPrimary = !useBrandPrimary && !softenPrimary ? seed : null;
|
||||
return base.copyWith(
|
||||
primary: useBrandPrimary ? p.primary : null,
|
||||
onPrimary: useBrandPrimary ? p.onPrimary : null,
|
||||
primary: useBrandPrimary ? p.primary : exactPrimary,
|
||||
onPrimary: useBrandPrimary
|
||||
? p.onPrimary
|
||||
: (exactPrimary == null ? null : _contrastOn(exactPrimary)),
|
||||
primaryContainer: useBrandPrimary ? p.primaryContainer : null,
|
||||
onPrimaryContainer: useBrandPrimary ? p.onPrimaryContainer : null,
|
||||
surfaceTint: useBrandPrimary ? p.primary : null,
|
||||
surfaceTint: useBrandPrimary ? p.primary : exactPrimary,
|
||||
secondary: p.secondary,
|
||||
onSecondary: p.onSecondary,
|
||||
secondaryContainer: p.secondaryContainer,
|
||||
@@ -141,6 +153,12 @@ abstract class TatuPalette {
|
||||
surfaceBright: p.surfaceBright,
|
||||
);
|
||||
}
|
||||
|
||||
/// Picks the readable foreground for an arbitrary background color.
|
||||
static Color _contrastOn(Color background) =>
|
||||
ThemeData.estimateBrightnessForColor(background) == Brightness.dark
|
||||
? Colors.white
|
||||
: Colors.black;
|
||||
}
|
||||
|
||||
class _Scheme {
|
||||
@@ -209,4 +227,4 @@ class _Scheme {
|
||||
final Color surfaceHighest;
|
||||
final Color surfaceDim;
|
||||
final Color surfaceBright;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user