forked from firka/firka
feat(theming): m3 dynamic color scheme
This commit is contained in:
@@ -23,6 +23,7 @@ import 'package:firka/l10n/app_localizations_hu.dart';
|
||||
import 'package:firka/core/swear_generator.dart';
|
||||
import 'package:firka/ui/phone/screens/themes/builtin_theme_id.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
import 'package:firka_common/ui/theme/core_theme.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@@ -331,11 +332,13 @@ Future<void> _initData(AppInitialization init) async {
|
||||
await Settings.selectedThemeId.set(normalized);
|
||||
}
|
||||
await initLang(init);
|
||||
await regenerateM3eTheme();
|
||||
initTheme(init);
|
||||
|
||||
var dispatcher = SchedulerBinding.instance.platformDispatcher;
|
||||
|
||||
dispatcher.onPlatformBrightnessChanged = () {
|
||||
dispatcher.onPlatformBrightnessChanged = () async {
|
||||
await regenerateM3eTheme();
|
||||
initTheme(init);
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import "package:firka/services/notification_delivery_service.dart";
|
||||
import "package:firka/services/progress_notification_service.dart";
|
||||
import "package:firka/services/watch_sync_helper.dart";
|
||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
||||
import "package:firka_common/ui/theme/core_theme.dart";
|
||||
|
||||
import "package:firka/data/widget.dart";
|
||||
import "settings_repository.dart";
|
||||
@@ -28,6 +29,9 @@ void registerSettingsEffects(
|
||||
});
|
||||
|
||||
repo.onChange(SettingsRegistry.themeBrightness, (_) async {
|
||||
if (Settings.selectedCoreThemeId.value == "m3e") {
|
||||
await regenerateM3eTheme();
|
||||
}
|
||||
initTheme(initData);
|
||||
initData.themeCubit.refresh();
|
||||
initData.homeRefreshCubit.requestRefresh();
|
||||
@@ -44,6 +48,9 @@ void registerSettingsEffects(
|
||||
repo.onChange(SettingsRegistry.titleCapitalization, refreshTitleStyle);
|
||||
|
||||
Future<void> refreshPresetTheme(_) async {
|
||||
if (Settings.selectedCoreThemeId.value == "m3e") {
|
||||
await regenerateM3eTheme();
|
||||
}
|
||||
if (isBuiltinThemeId(Settings.selectedThemeId.value)) {
|
||||
final next = composeBuiltinThemeId(
|
||||
Settings.selectedCoreThemeId.value,
|
||||
|
||||
@@ -46,6 +46,14 @@ class _SettingsPersonalizationViewState
|
||||
|
||||
Color get _selectedSurface => appStyle.colors.buttonSecondaryFill;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
regenerateM3eTheme().then((_) {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
Widget _sectionLabel(String text) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 8, top: 16),
|
||||
|
||||
@@ -62,6 +62,7 @@ dependencies:
|
||||
go_router: ^17.1.0
|
||||
flutter_bloc: ^9.0.0
|
||||
vibration: ^3.1.8
|
||||
dynamic_color: ^2.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
162
firka_common/lib/ui/theme/core/m3e.dart
Normal file
162
firka_common/lib/ui/theme/core/m3e.dart
Normal file
@@ -0,0 +1,162 @@
|
||||
part of "../core_theme.dart";
|
||||
|
||||
const _defaultM3eSeed = Color(0xFF6750A4);
|
||||
|
||||
CoreThemeColors coreColorsFromColorScheme(ColorScheme scheme) {
|
||||
final isLight = scheme.brightness == Brightness.light;
|
||||
final bg = scheme.surface;
|
||||
final card = isLight ? scheme.surfaceContainerLow : scheme.surfaceContainer;
|
||||
final buttonFill =
|
||||
isLight ? scheme.surfaceContainerLowest : scheme.surfaceContainerHigh;
|
||||
final accent = scheme.primary;
|
||||
final secondary = scheme.secondary;
|
||||
|
||||
return CoreThemeColors(
|
||||
background: bg,
|
||||
backgroundGradient: null,
|
||||
backgroundAmoled: Colors.black,
|
||||
background0p: bg.withAlpha(0),
|
||||
success: isLight ? const Color(0xFF34C759) : const Color(0xFF32D74B),
|
||||
shadowBlur: isLight ? 2 : 0,
|
||||
textPrimary: scheme.onSurface,
|
||||
textSecondary: scheme.onSurfaceVariant,
|
||||
textTertiary: scheme.onSurface.withAlpha(0x80),
|
||||
textTeritary: scheme.outline,
|
||||
textPrimaryLight: scheme.onSurface,
|
||||
textSecondaryLight: scheme.onSurfaceVariant,
|
||||
textTertiaryLight: scheme.onSurface.withAlpha(0x80),
|
||||
card: card,
|
||||
cardTranslucent: card.withAlpha(0x80),
|
||||
buttonSecondaryFill: buttonFill,
|
||||
buttonDisabledIcon: scheme.outline.withAlpha(0x80),
|
||||
accent: accent,
|
||||
secondary: secondary,
|
||||
shadowColor: scheme.shadow.withAlpha(isLight ? 0x26 : 0x40),
|
||||
a10p: accent.withAlpha(0x1a),
|
||||
a15p: accent.withAlpha(0x26),
|
||||
warningAccent: const Color(0xFFFFA046),
|
||||
warningText: isLight ? const Color(0xFF8F531B) : const Color(0xFFF0B37A),
|
||||
warning15p: const Color(0x26FFA046),
|
||||
warningCard: isLight ? const Color(0xFFFAEBDC) : const Color(0xFF201203),
|
||||
errorAccent: scheme.error,
|
||||
errorText: isLight ? const Color(0xFF8F1B4F) : const Color(0xFFF59EC5),
|
||||
error15p: scheme.error.withAlpha(0x26),
|
||||
errorCard: isLight ? scheme.errorContainer : const Color(0xFF1E030F),
|
||||
);
|
||||
}
|
||||
|
||||
ColorScheme corePaletteToFlutterColorScheme(
|
||||
// ignore: deprecated_member_use
|
||||
CorePalette palette, {
|
||||
required bool isLight,
|
||||
}) {
|
||||
// ignore: deprecated_member_use
|
||||
final scheme = isLight
|
||||
// ignore: deprecated_member_use
|
||||
? Scheme.lightFromCorePalette(palette)
|
||||
// ignore: deprecated_member_use
|
||||
: Scheme.darkFromCorePalette(palette);
|
||||
|
||||
final base = ColorScheme.fromSeed(
|
||||
seedColor: Color(scheme.primary),
|
||||
brightness: isLight ? Brightness.light : Brightness.dark,
|
||||
);
|
||||
|
||||
return base.copyWith(
|
||||
primary: Color(scheme.primary),
|
||||
onPrimary: Color(scheme.onPrimary),
|
||||
primaryContainer: Color(scheme.primaryContainer),
|
||||
onPrimaryContainer: Color(scheme.onPrimaryContainer),
|
||||
secondary: Color(scheme.secondary),
|
||||
onSecondary: Color(scheme.onSecondary),
|
||||
secondaryContainer: Color(scheme.secondaryContainer),
|
||||
onSecondaryContainer: Color(scheme.onSecondaryContainer),
|
||||
tertiary: Color(scheme.tertiary),
|
||||
onTertiary: Color(scheme.onTertiary),
|
||||
tertiaryContainer: Color(scheme.tertiaryContainer),
|
||||
onTertiaryContainer: Color(scheme.onTertiaryContainer),
|
||||
error: Color(scheme.error),
|
||||
onError: Color(scheme.onError),
|
||||
errorContainer: Color(scheme.errorContainer),
|
||||
onErrorContainer: Color(scheme.onErrorContainer),
|
||||
outline: Color(scheme.outline),
|
||||
outlineVariant: Color(scheme.outlineVariant),
|
||||
surface: Color(scheme.surface),
|
||||
onSurface: Color(scheme.onSurface),
|
||||
onSurfaceVariant: Color(scheme.onSurfaceVariant),
|
||||
inverseSurface: Color(scheme.inverseSurface),
|
||||
onInverseSurface: Color(scheme.inverseOnSurface),
|
||||
inversePrimary: Color(scheme.inversePrimary),
|
||||
shadow: Color(scheme.shadow),
|
||||
surfaceTint: Color(scheme.primary),
|
||||
scrim: Color(scheme.scrim),
|
||||
);
|
||||
}
|
||||
|
||||
final _defaultM3eLight = coreColorsFromColorScheme(
|
||||
ColorScheme.fromSeed(
|
||||
seedColor: _defaultM3eSeed,
|
||||
brightness: Brightness.light,
|
||||
),
|
||||
);
|
||||
|
||||
final _defaultM3eDark = coreColorsFromColorScheme(
|
||||
ColorScheme.fromSeed(
|
||||
seedColor: _defaultM3eSeed,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
);
|
||||
|
||||
CoreTheme m3eCore = CoreTheme(
|
||||
id: "m3e",
|
||||
light: _defaultM3eLight,
|
||||
dark: _defaultM3eDark,
|
||||
);
|
||||
|
||||
void updateM3eFromColorSchemes({
|
||||
ColorScheme? light,
|
||||
ColorScheme? dark,
|
||||
}) {
|
||||
final lightColors =
|
||||
light != null ? coreColorsFromColorScheme(light) : _defaultM3eLight;
|
||||
final darkColors =
|
||||
dark != null ? coreColorsFromColorScheme(dark) : _defaultM3eDark;
|
||||
m3eCore = CoreTheme(
|
||||
id: "m3e",
|
||||
light: lightColors,
|
||||
dark: darkColors,
|
||||
);
|
||||
coreThemes["m3e"] = m3eCore;
|
||||
}
|
||||
|
||||
Future<void> regenerateM3eTheme() async {
|
||||
try {
|
||||
final corePalette = await DynamicColorPlugin.getCorePalette();
|
||||
if (corePalette != null) {
|
||||
final lightScheme =
|
||||
corePaletteToFlutterColorScheme(corePalette, isLight: true);
|
||||
final darkScheme =
|
||||
corePaletteToFlutterColorScheme(corePalette, isLight: false);
|
||||
updateM3eFromColorSchemes(light: lightScheme, dark: darkScheme);
|
||||
return;
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
final accentColor = await DynamicColorPlugin.getAccentColor();
|
||||
if (accentColor != null) {
|
||||
final lightScheme = ColorScheme.fromSeed(
|
||||
seedColor: accentColor,
|
||||
brightness: Brightness.light,
|
||||
);
|
||||
final darkScheme = ColorScheme.fromSeed(
|
||||
seedColor: accentColor,
|
||||
brightness: Brightness.dark,
|
||||
);
|
||||
updateM3eFromColorSchemes(light: lightScheme, dark: darkScheme);
|
||||
return;
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
updateM3eFromColorSchemes();
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
// ignore_for_file: deprecated_member_use
|
||||
import "package:dynamic_color/dynamic_color.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:material_color_utilities/material_color_utilities.dart";
|
||||
|
||||
part "core/butcher_vanity.dart";
|
||||
part "core/firka.dart";
|
||||
part "core/m3e.dart";
|
||||
part "core/refilc.dart";
|
||||
|
||||
const Map<String, CoreTheme> coreThemes = {
|
||||
final Map<String, CoreTheme> coreThemes = {
|
||||
"firka": firkaCore,
|
||||
"m3e": m3eCore,
|
||||
"refilc": refilcCore,
|
||||
"butcher_vanity": butcherVanityCore,
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ dependencies:
|
||||
isar_community: 3.3.0
|
||||
isar_community_flutter_libs: 3.3.0
|
||||
build_runner: any
|
||||
dynamic_color: ^2.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user