forked from firka/firka
feat(theming): theme editor
This commit is contained in:
@@ -12,6 +12,7 @@ import 'package:firka_common/data/models/token_model.dart';
|
||||
import 'package:firka/services/notification_delivery_service.dart';
|
||||
import 'package:firka/services/progress_notification_service.dart';
|
||||
import 'package:firka/data/widget.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka/core/settings/settings_effects.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
@@ -57,12 +58,15 @@ Future<void> initLang(AppInitialization data) async {
|
||||
}
|
||||
}
|
||||
|
||||
void initTheme(AppInitialization data) {
|
||||
final themeCubit = data.themeCubit;
|
||||
|
||||
final brightness =
|
||||
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
||||
|
||||
/// Builds a full style for an explicit brightness, applying all custom color
|
||||
/// overrides — independent of the device's/app's actual current brightness.
|
||||
/// Used by [initTheme] itself, and by screens (like the theme editor) that
|
||||
/// need to preview a brightness other than the one currently on screen.
|
||||
FirkaStyle buildStyleForBrightness(
|
||||
bool isLight, {
|
||||
bool? isCustomTheme,
|
||||
bool forceCustomColors = false,
|
||||
}) {
|
||||
final titleFont = Settings.titleFont.value;
|
||||
final titleWeight = Settings.titleWeight.value;
|
||||
final fonts = buildAppFonts(
|
||||
@@ -70,6 +74,28 @@ void initTheme(AppInitialization data) {
|
||||
headingWeight: titleWeight,
|
||||
supportsWeight: titleFont.supportsWeight,
|
||||
);
|
||||
final coreId = Settings.selectedCoreThemeId.value;
|
||||
final gradeId = Settings.selectedGradeThemeId.value;
|
||||
|
||||
final style = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: isLight,
|
||||
fonts: fonts,
|
||||
);
|
||||
_applyCustomColors(
|
||||
style,
|
||||
isCustomTheme: isCustomTheme,
|
||||
force: forceCustomColors,
|
||||
);
|
||||
return style;
|
||||
}
|
||||
|
||||
void initTheme(AppInitialization data) {
|
||||
final themeCubit = data.themeCubit;
|
||||
|
||||
final brightness =
|
||||
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
||||
|
||||
appHeadingTextCase = switch (Settings.titleCapitalization.value) {
|
||||
TitleCapitalization.lower => HeadingTextCase.lower,
|
||||
@@ -77,50 +103,197 @@ void initTheme(AppInitialization data) {
|
||||
TitleCapitalization.normal => HeadingTextCase.normal,
|
||||
};
|
||||
|
||||
FirkaStyle baseStyle;
|
||||
final coreId = Settings.selectedCoreThemeId.value;
|
||||
final gradeId = Settings.selectedGradeThemeId.value;
|
||||
switch (Settings.themeBrightness.value) {
|
||||
case ThemeBrightness.light:
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: true,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(true);
|
||||
break;
|
||||
case ThemeBrightness.dark:
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: false,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(false);
|
||||
break;
|
||||
case ThemeBrightness.auto:
|
||||
if (brightness == Brightness.dark) {
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: false,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(false);
|
||||
} else {
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: true,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(true);
|
||||
}
|
||||
final isLight = switch (Settings.themeBrightness.value) {
|
||||
ThemeBrightness.light => true,
|
||||
ThemeBrightness.dark => false,
|
||||
ThemeBrightness.auto => brightness != Brightness.dark,
|
||||
};
|
||||
themeCubit.setLightMode(isLight);
|
||||
appStyle = buildStyleForBrightness(isLight);
|
||||
}
|
||||
|
||||
void _applyCustomColors(
|
||||
FirkaStyle style, {
|
||||
bool? isCustomTheme,
|
||||
bool force = false,
|
||||
}) {
|
||||
final colors = style.colors;
|
||||
|
||||
colors.grade5 = Settings.customGradeColor5.value.toColorFromHexSetting();
|
||||
colors.grade4 = Settings.customGradeColor4.value.toColorFromHexSetting();
|
||||
colors.grade3 = Settings.customGradeColor3.value.toColorFromHexSetting();
|
||||
colors.grade2 = Settings.customGradeColor2.value.toColorFromHexSetting();
|
||||
colors.grade1 = Settings.customGradeColor1.value.toColorFromHexSetting();
|
||||
|
||||
final customActive =
|
||||
isCustomTheme ?? !isBuiltinThemeId(Settings.selectedThemeId.value);
|
||||
if (!force && !customActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
appStyle = baseStyle;
|
||||
final isLight = style.isLight;
|
||||
|
||||
colors.accent =
|
||||
(isLight
|
||||
? Settings.customAccentColorLight
|
||||
: Settings.customAccentColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
colors.a10p = colors.accent.withAlpha(0x1a);
|
||||
colors.a15p = colors.accent.withAlpha(0x26);
|
||||
|
||||
colors.background =
|
||||
(isLight
|
||||
? Settings.customBackgroundColorLight
|
||||
: Settings.customBackgroundColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
colors.background0p = colors.background.withAlpha(0);
|
||||
|
||||
colors.card =
|
||||
(isLight
|
||||
? Settings.customCardColorLight
|
||||
: Settings.customCardColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
colors.cardTranslucent = colors.card.withAlpha(0x80);
|
||||
|
||||
colors.buttonSecondaryFill =
|
||||
(isLight
|
||||
? Settings.customButtonColorLight
|
||||
: Settings.customButtonColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
|
||||
colors.secondary =
|
||||
(isLight
|
||||
? Settings.customSecondaryColorLight
|
||||
: Settings.customSecondaryColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
colors.buttonDisabledIcon = colors.secondary.withAlpha(0x80);
|
||||
|
||||
final customTextLight = Settings.customTextColorLight.value;
|
||||
final customTextDark = Settings.customTextColorDark.value;
|
||||
final isCustomTextLight =
|
||||
customTextLight != SettingsRegistry.customTextColorLight.defaultValue;
|
||||
final isCustomTextDark =
|
||||
customTextDark != SettingsRegistry.customTextColorDark.defaultValue;
|
||||
|
||||
final textLight = customTextLight.toColorFromHexSetting();
|
||||
final textDark = customTextDark.toColorFromHexSetting();
|
||||
colors.textPrimary = isLight ? textLight : textDark;
|
||||
|
||||
final customSecLight = Settings.customTextSecondaryColorLight.value;
|
||||
final customSecDark = Settings.customTextSecondaryColorDark.value;
|
||||
final isCustomSecLight = customSecLight !=
|
||||
SettingsRegistry.customTextSecondaryColorLight.defaultValue;
|
||||
final isCustomSecDark = customSecDark !=
|
||||
SettingsRegistry.customTextSecondaryColorDark.defaultValue;
|
||||
|
||||
colors.textSecondary = isLight
|
||||
? (isCustomSecLight
|
||||
? customSecLight.toColorFromHexSetting()
|
||||
: (isCustomTextLight
|
||||
? textLight.withAlpha(0xCC)
|
||||
: customSecLight.toColorFromHexSetting()))
|
||||
: (isCustomSecDark
|
||||
? customSecDark.toColorFromHexSetting()
|
||||
: (isCustomTextDark
|
||||
? textDark.withAlpha(0xB3)
|
||||
: customSecDark.toColorFromHexSetting()));
|
||||
|
||||
final customTertLight = Settings.customTextTertiaryColorLight.value;
|
||||
final customTertDark = Settings.customTextTertiaryColorDark.value;
|
||||
final isCustomTertLight = customTertLight !=
|
||||
SettingsRegistry.customTextTertiaryColorLight.defaultValue;
|
||||
final isCustomTertDark = customTertDark !=
|
||||
SettingsRegistry.customTextTertiaryColorDark.defaultValue;
|
||||
|
||||
colors.textTertiary = isLight
|
||||
? (isCustomTertLight
|
||||
? customTertLight.toColorFromHexSetting()
|
||||
: (isCustomTextLight
|
||||
? textLight.withAlpha(0x80)
|
||||
: customTertLight.toColorFromHexSetting()))
|
||||
: (isCustomTertDark
|
||||
? customTertDark.toColorFromHexSetting()
|
||||
: (isCustomTextDark
|
||||
? textDark.withAlpha(0x80)
|
||||
: customTertDark.toColorFromHexSetting()));
|
||||
colors.textTeritary = colors.textTertiary;
|
||||
|
||||
colors.textPrimaryLight = textLight;
|
||||
colors.textSecondaryLight = isCustomSecLight
|
||||
? customSecLight.toColorFromHexSetting()
|
||||
: (isCustomTextLight
|
||||
? textLight.withAlpha(0xCC)
|
||||
: customSecLight.toColorFromHexSetting());
|
||||
colors.textTertiaryLight = isCustomTertLight
|
||||
? customTertLight.toColorFromHexSetting()
|
||||
: (isCustomTextLight
|
||||
? textLight.withAlpha(0x80)
|
||||
: customTertLight.toColorFromHexSetting());
|
||||
|
||||
colors.shadowColor =
|
||||
(isLight
|
||||
? Settings.customShadowColorLight
|
||||
: Settings.customShadowColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
|
||||
colors.success =
|
||||
(isLight
|
||||
? Settings.customSuccessColorLight
|
||||
: Settings.customSuccessColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
|
||||
colors.warningAccent =
|
||||
(isLight
|
||||
? Settings.customWarningAccentColorLight
|
||||
: Settings.customWarningAccentColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
colors.warning15p = colors.warningAccent.withAlpha(0x26);
|
||||
|
||||
colors.warningText =
|
||||
(isLight
|
||||
? Settings.customWarningTextColorLight
|
||||
: Settings.customWarningTextColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
|
||||
colors.warningCard =
|
||||
(isLight
|
||||
? Settings.customWarningCardColorLight
|
||||
: Settings.customWarningCardColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
|
||||
colors.errorAccent =
|
||||
(isLight
|
||||
? Settings.customErrorAccentColorLight
|
||||
: Settings.customErrorAccentColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
colors.error15p = colors.errorAccent.withAlpha(0x26);
|
||||
|
||||
colors.errorText =
|
||||
(isLight
|
||||
? Settings.customErrorTextColorLight
|
||||
: Settings.customErrorTextColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
|
||||
colors.errorCard =
|
||||
(isLight
|
||||
? Settings.customErrorCardColorLight
|
||||
: Settings.customErrorCardColorDark)
|
||||
.value
|
||||
.toColorFromHexSetting();
|
||||
}
|
||||
|
||||
DateTime? _lastInitDataAt;
|
||||
String? _lastInitDataUsername;
|
||||
|
||||
@@ -291,11 +464,17 @@ Future<void> initializeApp() async {
|
||||
registerSettingsEffects(initData.settings, initData);
|
||||
|
||||
try {
|
||||
await NotificationDeliveryService.initialize().timeout(const Duration(seconds: 8));
|
||||
await NotificationDeliveryService.initialize().timeout(
|
||||
const Duration(seconds: 8),
|
||||
);
|
||||
} on TimeoutException catch (e, st) {
|
||||
logger.warning('NotificationDeliveryService init timed out: $e', e, st);
|
||||
} catch (e, st) {
|
||||
logger.severe('Failed to initialize NotificationDeliveryService: $e', e, st);
|
||||
logger.severe(
|
||||
'Failed to initialize NotificationDeliveryService: $e',
|
||||
e,
|
||||
st,
|
||||
);
|
||||
}
|
||||
|
||||
await _initData(initData);
|
||||
|
||||
@@ -296,6 +296,15 @@ extension RandomColorExtension on Random {
|
||||
}
|
||||
}
|
||||
|
||||
extension ColorHexExtension on Color {
|
||||
String toHexSetting() =>
|
||||
"0x${toARGB32().toRadixString(16).toUpperCase().padLeft(8, '0')}";
|
||||
}
|
||||
|
||||
extension HexSettingExtension on String {
|
||||
Color toColorFromHexSetting() => Color(int.tryParse(this) ?? 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
extension StringExtension on String {
|
||||
bool isNumeric() {
|
||||
final regex = RegExp(r'^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$');
|
||||
|
||||
@@ -60,6 +60,55 @@ void registerSettingsEffects(
|
||||
|
||||
repo.onChange(SettingsRegistry.selectedCoreThemeId, refreshPresetTheme);
|
||||
repo.onChange(SettingsRegistry.selectedGradeThemeId, refreshPresetTheme);
|
||||
repo.onChange(SettingsRegistry.selectedThemeId, refreshPresetTheme);
|
||||
|
||||
Future<void> refreshCustomColors(_) async {
|
||||
initTheme(initData);
|
||||
initData.themeCubit.refresh();
|
||||
initData.homeRefreshCubit.requestRefresh();
|
||||
}
|
||||
|
||||
for (final setting in [
|
||||
SettingsRegistry.customGradeColor5,
|
||||
SettingsRegistry.customGradeColor4,
|
||||
SettingsRegistry.customGradeColor3,
|
||||
SettingsRegistry.customGradeColor2,
|
||||
SettingsRegistry.customGradeColor1,
|
||||
SettingsRegistry.customAccentColorLight,
|
||||
SettingsRegistry.customAccentColorDark,
|
||||
SettingsRegistry.customBackgroundColorLight,
|
||||
SettingsRegistry.customBackgroundColorDark,
|
||||
SettingsRegistry.customCardColorLight,
|
||||
SettingsRegistry.customCardColorDark,
|
||||
SettingsRegistry.customButtonColorLight,
|
||||
SettingsRegistry.customButtonColorDark,
|
||||
SettingsRegistry.customSecondaryColorLight,
|
||||
SettingsRegistry.customSecondaryColorDark,
|
||||
SettingsRegistry.customTextColorLight,
|
||||
SettingsRegistry.customTextColorDark,
|
||||
SettingsRegistry.customTextSecondaryColorLight,
|
||||
SettingsRegistry.customTextSecondaryColorDark,
|
||||
SettingsRegistry.customTextTertiaryColorLight,
|
||||
SettingsRegistry.customTextTertiaryColorDark,
|
||||
SettingsRegistry.customShadowColorLight,
|
||||
SettingsRegistry.customShadowColorDark,
|
||||
SettingsRegistry.customSuccessColorLight,
|
||||
SettingsRegistry.customSuccessColorDark,
|
||||
SettingsRegistry.customWarningAccentColorLight,
|
||||
SettingsRegistry.customWarningAccentColorDark,
|
||||
SettingsRegistry.customWarningTextColorLight,
|
||||
SettingsRegistry.customWarningTextColorDark,
|
||||
SettingsRegistry.customWarningCardColorLight,
|
||||
SettingsRegistry.customWarningCardColorDark,
|
||||
SettingsRegistry.customErrorAccentColorLight,
|
||||
SettingsRegistry.customErrorAccentColorDark,
|
||||
SettingsRegistry.customErrorTextColorLight,
|
||||
SettingsRegistry.customErrorTextColorDark,
|
||||
SettingsRegistry.customErrorCardColorLight,
|
||||
SettingsRegistry.customErrorCardColorDark,
|
||||
]) {
|
||||
repo.onChange(setting, refreshCustomColors);
|
||||
}
|
||||
|
||||
repo.onChange(SettingsRegistry.wearOsSupport, (enabled) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
|
||||
@@ -211,4 +211,102 @@ abstract class SettingsSchema {
|
||||
|
||||
@StringSetting(id: 1054, defaultValue: "0xFFFF54A1")
|
||||
String get customGradeColor1;
|
||||
|
||||
// Custom theme colors stored as 0xAARRGGBB hex strings.
|
||||
// Defaults match the firka core theme.
|
||||
@StringSetting(id: 1055, defaultValue: "0xFFA7DC22")
|
||||
String get customAccentColorLight;
|
||||
|
||||
@StringSetting(id: 1056, defaultValue: "0xFFA7DC22")
|
||||
String get customAccentColorDark;
|
||||
|
||||
@StringSetting(id: 1057, defaultValue: "0xFFFAFFF0")
|
||||
String get customBackgroundColorLight;
|
||||
|
||||
@StringSetting(id: 1058, defaultValue: "0xFF0D1202")
|
||||
String get customBackgroundColorDark;
|
||||
|
||||
@StringSetting(id: 1059, defaultValue: "0xFFF3FBDE")
|
||||
String get customCardColorLight;
|
||||
|
||||
@StringSetting(id: 1060, defaultValue: "0xFF141905")
|
||||
String get customCardColorDark;
|
||||
|
||||
@StringSetting(id: 1061, defaultValue: "0xFFFEFFFD")
|
||||
String get customButtonColorLight;
|
||||
|
||||
@StringSetting(id: 1062, defaultValue: "0xFF20290B")
|
||||
String get customButtonColorDark;
|
||||
|
||||
@StringSetting(id: 1063, defaultValue: "0xFF6E8F1B")
|
||||
String get customSecondaryColorLight;
|
||||
|
||||
@StringSetting(id: 1064, defaultValue: "0xFFCBEE71")
|
||||
String get customSecondaryColorDark;
|
||||
|
||||
@StringSetting(id: 1065, defaultValue: "0xFF394C0A")
|
||||
String get customTextColorLight;
|
||||
|
||||
@StringSetting(id: 1066, defaultValue: "0xFFEAF7CC")
|
||||
String get customTextColorDark;
|
||||
|
||||
@StringSetting(id: 1067, defaultValue: "0xCC394C0A")
|
||||
String get customTextSecondaryColorLight;
|
||||
|
||||
@StringSetting(id: 1068, defaultValue: "0xB3EAF7CC")
|
||||
String get customTextSecondaryColorDark;
|
||||
|
||||
@StringSetting(id: 1069, defaultValue: "0x80394C0A")
|
||||
String get customTextTertiaryColorLight;
|
||||
|
||||
@StringSetting(id: 1070, defaultValue: "0x80EAF7CC")
|
||||
String get customTextTertiaryColorDark;
|
||||
|
||||
@StringSetting(id: 1071, defaultValue: "0x33647E22")
|
||||
String get customShadowColorLight;
|
||||
|
||||
@StringSetting(id: 1072, defaultValue: "0x26CBEE71")
|
||||
String get customShadowColorDark;
|
||||
|
||||
@StringSetting(id: 1073, defaultValue: "0xFF92EA3B")
|
||||
String get customSuccessColorLight;
|
||||
|
||||
@StringSetting(id: 1074, defaultValue: "0xFF92EA3B")
|
||||
String get customSuccessColorDark;
|
||||
|
||||
@StringSetting(id: 1075, defaultValue: "0xFFFFA046")
|
||||
String get customWarningAccentColorLight;
|
||||
|
||||
@StringSetting(id: 1076, defaultValue: "0xFFFFA046")
|
||||
String get customWarningAccentColorDark;
|
||||
|
||||
@StringSetting(id: 1077, defaultValue: "0xFF8F531B")
|
||||
String get customWarningTextColorLight;
|
||||
|
||||
@StringSetting(id: 1078, defaultValue: "0xFFF0B37A")
|
||||
String get customWarningTextColorDark;
|
||||
|
||||
@StringSetting(id: 1079, defaultValue: "0xFFFAEBDC")
|
||||
String get customWarningCardColorLight;
|
||||
|
||||
@StringSetting(id: 1080, defaultValue: "0xFF201203")
|
||||
String get customWarningCardColorDark;
|
||||
|
||||
@StringSetting(id: 1081, defaultValue: "0xFFFF54A1")
|
||||
String get customErrorAccentColorLight;
|
||||
|
||||
@StringSetting(id: 1082, defaultValue: "0xFFFF54A1")
|
||||
String get customErrorAccentColorDark;
|
||||
|
||||
@StringSetting(id: 1083, defaultValue: "0xFF8F1B4F")
|
||||
String get customErrorTextColorLight;
|
||||
|
||||
@StringSetting(id: 1084, defaultValue: "0xFFF59EC5")
|
||||
String get customErrorTextColorDark;
|
||||
|
||||
@StringSetting(id: 1085, defaultValue: "0xFFFADCE9")
|
||||
String get customErrorCardColorLight;
|
||||
|
||||
@StringSetting(id: 1086, defaultValue: "0xFF1E030F")
|
||||
String get customErrorCardColorDark;
|
||||
}
|
||||
|
||||
@@ -52,9 +52,41 @@ class SettingsRegistry {
|
||||
static const customGradeColor3 = StringSetting(id: 1052, defaultValue: "0xFFF9CF00");
|
||||
static const customGradeColor2 = StringSetting(id: 1053, defaultValue: "0xFFFFA046");
|
||||
static const customGradeColor1 = StringSetting(id: 1054, defaultValue: "0xFFFF54A1");
|
||||
static const customAccentColorLight = StringSetting(id: 1055, defaultValue: "0xFFA7DC22");
|
||||
static const customAccentColorDark = StringSetting(id: 1056, defaultValue: "0xFFA7DC22");
|
||||
static const customBackgroundColorLight = StringSetting(id: 1057, defaultValue: "0xFFFAFFF0");
|
||||
static const customBackgroundColorDark = StringSetting(id: 1058, defaultValue: "0xFF0D1202");
|
||||
static const customCardColorLight = StringSetting(id: 1059, defaultValue: "0xFFF3FBDE");
|
||||
static const customCardColorDark = StringSetting(id: 1060, defaultValue: "0xFF141905");
|
||||
static const customButtonColorLight = StringSetting(id: 1061, defaultValue: "0xFFFEFFFD");
|
||||
static const customButtonColorDark = StringSetting(id: 1062, defaultValue: "0xFF20290B");
|
||||
static const customSecondaryColorLight = StringSetting(id: 1063, defaultValue: "0xFF6E8F1B");
|
||||
static const customSecondaryColorDark = StringSetting(id: 1064, defaultValue: "0xFFCBEE71");
|
||||
static const customTextColorLight = StringSetting(id: 1065, defaultValue: "0xFF394C0A");
|
||||
static const customTextColorDark = StringSetting(id: 1066, defaultValue: "0xFFEAF7CC");
|
||||
static const customTextSecondaryColorLight = StringSetting(id: 1067, defaultValue: "0xCC394C0A");
|
||||
static const customTextSecondaryColorDark = StringSetting(id: 1068, defaultValue: "0xB3EAF7CC");
|
||||
static const customTextTertiaryColorLight = StringSetting(id: 1069, defaultValue: "0x80394C0A");
|
||||
static const customTextTertiaryColorDark = StringSetting(id: 1070, defaultValue: "0x80EAF7CC");
|
||||
static const customShadowColorLight = StringSetting(id: 1071, defaultValue: "0x33647E22");
|
||||
static const customShadowColorDark = StringSetting(id: 1072, defaultValue: "0x26CBEE71");
|
||||
static const customSuccessColorLight = StringSetting(id: 1073, defaultValue: "0xFF92EA3B");
|
||||
static const customSuccessColorDark = StringSetting(id: 1074, defaultValue: "0xFF92EA3B");
|
||||
static const customWarningAccentColorLight = StringSetting(id: 1075, defaultValue: "0xFFFFA046");
|
||||
static const customWarningAccentColorDark = StringSetting(id: 1076, defaultValue: "0xFFFFA046");
|
||||
static const customWarningTextColorLight = StringSetting(id: 1077, defaultValue: "0xFF8F531B");
|
||||
static const customWarningTextColorDark = StringSetting(id: 1078, defaultValue: "0xFFF0B37A");
|
||||
static const customWarningCardColorLight = StringSetting(id: 1079, defaultValue: "0xFFFAEBDC");
|
||||
static const customWarningCardColorDark = StringSetting(id: 1080, defaultValue: "0xFF201203");
|
||||
static const customErrorAccentColorLight = StringSetting(id: 1081, defaultValue: "0xFFFF54A1");
|
||||
static const customErrorAccentColorDark = StringSetting(id: 1082, defaultValue: "0xFFFF54A1");
|
||||
static const customErrorTextColorLight = StringSetting(id: 1083, defaultValue: "0xFF8F1B4F");
|
||||
static const customErrorTextColorDark = StringSetting(id: 1084, defaultValue: "0xFFF59EC5");
|
||||
static const customErrorCardColorLight = StringSetting(id: 1085, defaultValue: "0xFFFADCE9");
|
||||
static const customErrorCardColorDark = StringSetting(id: 1086, defaultValue: "0xFF1E030F");
|
||||
|
||||
static const all = <Setting>[
|
||||
bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId, mockBackendEnabled, mockBackendUrl, lastSeen, surpriseGrades, seasonalAppIcons, uwuMode, notifyAll, notifyGrades, notifyHomeworkTests, notifyAbsences, notifyLessons, notifyMessages, notifyMutedSubjects, notifyWakeupInterval, fcmDebugNotifyOnMessage, notificationDeliveryMethod, lessonCacheKeyMigrationDone, progressNotificationEnabled, customGradeColor5, customGradeColor4, customGradeColor3, customGradeColor2, customGradeColor1,
|
||||
bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId, mockBackendEnabled, mockBackendUrl, lastSeen, surpriseGrades, seasonalAppIcons, uwuMode, notifyAll, notifyGrades, notifyHomeworkTests, notifyAbsences, notifyLessons, notifyMessages, notifyMutedSubjects, notifyWakeupInterval, fcmDebugNotifyOnMessage, notificationDeliveryMethod, lessonCacheKeyMigrationDone, progressNotificationEnabled, customGradeColor5, customGradeColor4, customGradeColor3, customGradeColor2, customGradeColor1, customAccentColorLight, customAccentColorDark, customBackgroundColorLight, customBackgroundColorDark, customCardColorLight, customCardColorDark, customButtonColorLight, customButtonColorDark, customSecondaryColorLight, customSecondaryColorDark, customTextColorLight, customTextColorDark, customTextSecondaryColorLight, customTextSecondaryColorDark, customTextTertiaryColorLight, customTextTertiaryColorDark, customShadowColorLight, customShadowColorDark, customSuccessColorLight, customSuccessColorDark, customWarningAccentColorLight, customWarningAccentColorDark, customWarningTextColorLight, customWarningTextColorDark, customWarningCardColorLight, customWarningCardColorDark, customErrorAccentColorLight, customErrorAccentColorDark, customErrorTextColorLight, customErrorTextColorDark, customErrorCardColorLight, customErrorCardColorDark,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -108,4 +140,36 @@ extension SettingsAccessors on SettingsRepository {
|
||||
SilentlySettable<String> get customGradeColor3 => SilentlySettable(this, SettingsRegistry.customGradeColor3);
|
||||
SilentlySettable<String> get customGradeColor2 => SilentlySettable(this, SettingsRegistry.customGradeColor2);
|
||||
SilentlySettable<String> get customGradeColor1 => SilentlySettable(this, SettingsRegistry.customGradeColor1);
|
||||
SilentlySettable<String> get customAccentColorLight => SilentlySettable(this, SettingsRegistry.customAccentColorLight);
|
||||
SilentlySettable<String> get customAccentColorDark => SilentlySettable(this, SettingsRegistry.customAccentColorDark);
|
||||
SilentlySettable<String> get customBackgroundColorLight => SilentlySettable(this, SettingsRegistry.customBackgroundColorLight);
|
||||
SilentlySettable<String> get customBackgroundColorDark => SilentlySettable(this, SettingsRegistry.customBackgroundColorDark);
|
||||
SilentlySettable<String> get customCardColorLight => SilentlySettable(this, SettingsRegistry.customCardColorLight);
|
||||
SilentlySettable<String> get customCardColorDark => SilentlySettable(this, SettingsRegistry.customCardColorDark);
|
||||
SilentlySettable<String> get customButtonColorLight => SilentlySettable(this, SettingsRegistry.customButtonColorLight);
|
||||
SilentlySettable<String> get customButtonColorDark => SilentlySettable(this, SettingsRegistry.customButtonColorDark);
|
||||
SilentlySettable<String> get customSecondaryColorLight => SilentlySettable(this, SettingsRegistry.customSecondaryColorLight);
|
||||
SilentlySettable<String> get customSecondaryColorDark => SilentlySettable(this, SettingsRegistry.customSecondaryColorDark);
|
||||
SilentlySettable<String> get customTextColorLight => SilentlySettable(this, SettingsRegistry.customTextColorLight);
|
||||
SilentlySettable<String> get customTextColorDark => SilentlySettable(this, SettingsRegistry.customTextColorDark);
|
||||
SilentlySettable<String> get customTextSecondaryColorLight => SilentlySettable(this, SettingsRegistry.customTextSecondaryColorLight);
|
||||
SilentlySettable<String> get customTextSecondaryColorDark => SilentlySettable(this, SettingsRegistry.customTextSecondaryColorDark);
|
||||
SilentlySettable<String> get customTextTertiaryColorLight => SilentlySettable(this, SettingsRegistry.customTextTertiaryColorLight);
|
||||
SilentlySettable<String> get customTextTertiaryColorDark => SilentlySettable(this, SettingsRegistry.customTextTertiaryColorDark);
|
||||
SilentlySettable<String> get customShadowColorLight => SilentlySettable(this, SettingsRegistry.customShadowColorLight);
|
||||
SilentlySettable<String> get customShadowColorDark => SilentlySettable(this, SettingsRegistry.customShadowColorDark);
|
||||
SilentlySettable<String> get customSuccessColorLight => SilentlySettable(this, SettingsRegistry.customSuccessColorLight);
|
||||
SilentlySettable<String> get customSuccessColorDark => SilentlySettable(this, SettingsRegistry.customSuccessColorDark);
|
||||
SilentlySettable<String> get customWarningAccentColorLight => SilentlySettable(this, SettingsRegistry.customWarningAccentColorLight);
|
||||
SilentlySettable<String> get customWarningAccentColorDark => SilentlySettable(this, SettingsRegistry.customWarningAccentColorDark);
|
||||
SilentlySettable<String> get customWarningTextColorLight => SilentlySettable(this, SettingsRegistry.customWarningTextColorLight);
|
||||
SilentlySettable<String> get customWarningTextColorDark => SilentlySettable(this, SettingsRegistry.customWarningTextColorDark);
|
||||
SilentlySettable<String> get customWarningCardColorLight => SilentlySettable(this, SettingsRegistry.customWarningCardColorLight);
|
||||
SilentlySettable<String> get customWarningCardColorDark => SilentlySettable(this, SettingsRegistry.customWarningCardColorDark);
|
||||
SilentlySettable<String> get customErrorAccentColorLight => SilentlySettable(this, SettingsRegistry.customErrorAccentColorLight);
|
||||
SilentlySettable<String> get customErrorAccentColorDark => SilentlySettable(this, SettingsRegistry.customErrorAccentColorDark);
|
||||
SilentlySettable<String> get customErrorTextColorLight => SilentlySettable(this, SettingsRegistry.customErrorTextColorLight);
|
||||
SilentlySettable<String> get customErrorTextColorDark => SilentlySettable(this, SettingsRegistry.customErrorTextColorDark);
|
||||
SilentlySettable<String> get customErrorCardColorLight => SilentlySettable(this, SettingsRegistry.customErrorCardColorLight);
|
||||
SilentlySettable<String> get customErrorCardColorDark => SilentlySettable(this, SettingsRegistry.customErrorCardColorDark);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import 'package:firka/ui/phone/screens/message/message_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/home/home_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/settings/settings_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/grade_colors/grade_colors_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/theme_editor/theme_editor_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/themes/theme_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/themes/themes_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/themes/user_theme.dart';
|
||||
@@ -123,6 +124,13 @@ GoRouter createAppRouter() {
|
||||
child: GradeColorsScreen(initData, key: state.pageKey),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/theme-editor',
|
||||
builder: (context, state) => DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: ThemeEditorScreen(initData, key: state.pageKey),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/message',
|
||||
builder: (context, state) {
|
||||
|
||||
@@ -57,14 +57,6 @@ Color _defaultFor(int grade) {
|
||||
}
|
||||
}
|
||||
|
||||
Color _parseColor(String hex) {
|
||||
final value = int.tryParse(hex) ?? 0xFFFFFFFF;
|
||||
return Color(value);
|
||||
}
|
||||
|
||||
String _encodeColor(Color color) =>
|
||||
"0x${color.toARGB32().toRadixString(16).toUpperCase().padLeft(8, '0')}";
|
||||
|
||||
class _GradeColorsScreenState extends State<GradeColorsScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late int _selectedGrade;
|
||||
@@ -104,12 +96,12 @@ class _GradeColorsScreenState extends State<GradeColorsScreen>
|
||||
|
||||
Color _currentColor(int grade) {
|
||||
final raw = _settings.get(_settingFor(grade));
|
||||
return _parseColor(raw);
|
||||
return raw.toColorFromHexSetting();
|
||||
}
|
||||
|
||||
void _syncHexField() {
|
||||
if (!_hexFocused) {
|
||||
final hex = _encodeColor(_hsv.toColor()).substring(4);
|
||||
final hex = _hsv.toColor().toHexSetting().substring(4);
|
||||
_hexController.text = hex.toUpperCase();
|
||||
}
|
||||
}
|
||||
@@ -119,7 +111,7 @@ class _GradeColorsScreenState extends State<GradeColorsScreen>
|
||||
_syncHexField();
|
||||
await _settings.set(
|
||||
_settingFor(_selectedGrade),
|
||||
_encodeColor(hsv.toColor()),
|
||||
hsv.toColor().toHexSetting(),
|
||||
);
|
||||
if (!mounted) return;
|
||||
context.read<ThemeCubit>().refresh();
|
||||
|
||||
@@ -7,6 +7,7 @@ import "package:firka/core/settings/settings_schema.dart";
|
||||
import "package:firka/core/settings/settings_ui.dart";
|
||||
import "package:firka/core/settings/title_font.dart";
|
||||
import "package:firka/l10n/app_localizations.dart";
|
||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
||||
import "package:firka/ui/shared/firka_icon.dart";
|
||||
import "package:firka/ui/theme/style.dart";
|
||||
import "package:firka_common/ui/components/firka_card.dart";
|
||||
@@ -50,9 +51,7 @@ class _SettingsPersonalizationViewState
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 8, top: 16),
|
||||
child: Text(
|
||||
text,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -78,29 +77,20 @@ class _SettingsPersonalizationViewState
|
||||
final left = <Widget>[];
|
||||
if (iconType != null && iconData != null) {
|
||||
left.add(
|
||||
FirkaIconWidget(
|
||||
iconType,
|
||||
iconData,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
FirkaIconWidget(iconType, iconData, color: appStyle.colors.accent),
|
||||
);
|
||||
left.add(const SizedBox(width: 8));
|
||||
}
|
||||
left.add(
|
||||
Text(
|
||||
title,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
style: appStyle.fonts.B_16SB.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: FirkaCard(
|
||||
left: left,
|
||||
right: [_externalArrow()],
|
||||
),
|
||||
child: FirkaCard(left: left, right: [_externalArrow()]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,12 +118,7 @@ class _SettingsPersonalizationViewState
|
||||
}
|
||||
|
||||
List<Color> _coreSwatch(CoreThemeColors colors) {
|
||||
return [
|
||||
colors.secondary,
|
||||
colors.accent,
|
||||
colors.background,
|
||||
colors.card,
|
||||
];
|
||||
return [colors.secondary, colors.accent, colors.background, colors.card];
|
||||
}
|
||||
|
||||
List<Color> _gradeSwatch(GradeThemeColors colors) {
|
||||
@@ -147,6 +132,27 @@ class _SettingsPersonalizationViewState
|
||||
}
|
||||
|
||||
Widget _coreThemePager() {
|
||||
final isCustomTheme =
|
||||
!isBuiltinThemeId(_settings.get(SettingsRegistry.selectedThemeId));
|
||||
|
||||
if (isCustomTheme) {
|
||||
return IgnorePointer(
|
||||
child: _PresetSwatchPager(
|
||||
key: const ValueKey("core-themes-custom"),
|
||||
swatches: [
|
||||
[
|
||||
appStyle.colors.secondary,
|
||||
appStyle.colors.accent,
|
||||
appStyle.colors.background,
|
||||
appStyle.colors.card,
|
||||
],
|
||||
],
|
||||
selectedIndex: 0,
|
||||
onSelected: (_) {},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final cores = coreThemes.values.toList(growable: false);
|
||||
final selectedId = _settings.get(SettingsRegistry.selectedCoreThemeId);
|
||||
var selectedIndex = cores.indexWhere((theme) => theme.id == selectedId);
|
||||
@@ -190,19 +196,6 @@ class _SettingsPersonalizationViewState
|
||||
);
|
||||
}
|
||||
|
||||
Widget _stubCustomizeButton() {
|
||||
return FirkaCard(
|
||||
left: [
|
||||
Text(
|
||||
_l10n.s_c_customize,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _customizeButton({required String route}) {
|
||||
return GestureDetector(
|
||||
onTap: () => context.push(route),
|
||||
@@ -241,9 +234,7 @@ class _SettingsPersonalizationViewState
|
||||
left: [
|
||||
Text(
|
||||
label,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
],
|
||||
right: selected
|
||||
@@ -281,12 +272,8 @@ class _SettingsPersonalizationViewState
|
||||
},
|
||||
child: FirkaCard(
|
||||
color: selected ? _selectedSurface : _mutedCardColor,
|
||||
left: [
|
||||
Text(font.displayName, style: style),
|
||||
],
|
||||
right: selected
|
||||
? [_checkMark(), const SizedBox(width: 8)]
|
||||
: const [],
|
||||
left: [Text(font.displayName, style: style)],
|
||||
right: selected ? [_checkMark(), const SizedBox(width: 8)] : const [],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -322,10 +309,7 @@ class _SettingsPersonalizationViewState
|
||||
Widget _fontPicker(TitleFont selected) {
|
||||
if (!_fontPickerExpanded) {
|
||||
return Column(
|
||||
children: [
|
||||
_fontCard(selected, selected: true),
|
||||
_changeRow(),
|
||||
],
|
||||
children: [_fontCard(selected, selected: true), _changeRow()],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -447,7 +431,8 @@ class _SettingsPersonalizationViewState
|
||||
final thickLeft = thickRight - thickWidth;
|
||||
|
||||
final showThin = thumbRight < thinLeft || thumbLeft > thinRight;
|
||||
final showThick = thumbRight < thickLeft || thumbLeft > thickRight;
|
||||
final showThick =
|
||||
thumbRight < thickLeft || thumbLeft > thickRight;
|
||||
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
@@ -621,15 +606,18 @@ class _SettingsPersonalizationViewState
|
||||
_shortcutRow(
|
||||
title: _l10n.s_c_change_app_icon,
|
||||
onTap: () {
|
||||
context.push("/settings", extra: [
|
||||
SettingsUiBackHeader(_l10n.s_customization, () => true),
|
||||
...widget.item.appIconPickerChildren,
|
||||
]);
|
||||
context.push(
|
||||
"/settings",
|
||||
extra: [
|
||||
SettingsUiBackHeader(_l10n.s_customization, () => true),
|
||||
...widget.item.appIconPickerChildren,
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
_sectionLabel(_l10n.s_c_colors_header),
|
||||
_coreThemePager(),
|
||||
_stubCustomizeButton(),
|
||||
_customizeButton(route: "/theme-editor"),
|
||||
_sectionLabel(_l10n.s_c_theme_header),
|
||||
_themeOption(_l10n.s_c_theme_auto, ThemeBrightness.auto),
|
||||
_themeOption(_l10n.s_c_theme_light, ThemeBrightness.light),
|
||||
@@ -802,11 +790,7 @@ class _SwatchPageDots extends StatelessWidget {
|
||||
height: size,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Color.lerp(
|
||||
accent.withValues(alpha: 0.28),
|
||||
accent,
|
||||
t,
|
||||
),
|
||||
color: Color.lerp(accent.withValues(alpha: 0.28), accent, t),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
833
firka/lib/ui/phone/screens/theme_editor/theme_editor_screen.dart
Normal file
833
firka/lib/ui/phone/screens/theme_editor/theme_editor_screen.dart
Normal file
@@ -0,0 +1,833 @@
|
||||
import "dart:math" as math;
|
||||
|
||||
import "package:carousel_slider/carousel_slider.dart";
|
||||
import "package:firka/app/app_state.dart";
|
||||
import "package:firka/app/initialization.dart";
|
||||
import "package:firka/core/bloc/theme_cubit.dart";
|
||||
import "package:firka/core/extensions.dart";
|
||||
import "package:firka/core/settings/setting.dart";
|
||||
import "package:firka/core/settings/settings_repository.dart";
|
||||
import "package:firka/core/settings/settings_schema.dart";
|
||||
import "package:firka/core/snowflake.dart";
|
||||
import "package:firka/ui/components/color_slider.dart";
|
||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
||||
import "package:firka/ui/phone/screens/themes/preview/theme_preview_data.dart";
|
||||
import "package:firka/ui/phone/screens/themes/preview/theme_preview_pages.dart";
|
||||
import "package:firka/ui/phone/screens/themes/user_theme.dart";
|
||||
import "package:firka/ui/shared/firka_icon.dart";
|
||||
import "package:firka/ui/theme/style.dart";
|
||||
import "package:firka_common/data/database.dart";
|
||||
import "package:firka_common/data/models/user_theme_model.dart";
|
||||
import "package:firka_common/ui/components/firka_card.dart";
|
||||
import "package:firka_common/ui/theme/style.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter/services.dart";
|
||||
import "package:flutter_bloc/flutter_bloc.dart";
|
||||
import "package:go_router/go_router.dart";
|
||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
||||
|
||||
enum _ThemeSlot {
|
||||
accent,
|
||||
background,
|
||||
card,
|
||||
button,
|
||||
secondary,
|
||||
text,
|
||||
textSecondary,
|
||||
textTertiary,
|
||||
shadow,
|
||||
success,
|
||||
warningAccent,
|
||||
warningText,
|
||||
warningCard,
|
||||
errorAccent,
|
||||
errorText,
|
||||
errorCard,
|
||||
}
|
||||
|
||||
enum _BrightnessMode { both, light, dark }
|
||||
|
||||
class ThemeEditorScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
|
||||
const ThemeEditorScreen(this.data, {super.key});
|
||||
|
||||
@override
|
||||
State<ThemeEditorScreen> createState() => _ThemeEditorScreenState();
|
||||
}
|
||||
|
||||
const _defaults = <_ThemeSlot, (Color light, Color dark)>{
|
||||
_ThemeSlot.accent: (Color(0xFFA7DC22), Color(0xFFA7DC22)),
|
||||
_ThemeSlot.background: (Color(0xFFFAFFF0), Color(0xFF0D1202)),
|
||||
_ThemeSlot.card: (Color(0xFFF3FBDE), Color(0xFF141905)),
|
||||
_ThemeSlot.button: (Color(0xFFFEFFFD), Color(0xFF20290B)),
|
||||
_ThemeSlot.secondary: (Color(0xFF6E8F1B), Color(0xFFCBEE71)),
|
||||
_ThemeSlot.text: (Color(0xFF394C0A), Color(0xFFEAF7CC)),
|
||||
_ThemeSlot.textSecondary: (Color(0xCC394C0A), Color(0xB3EAF7CC)),
|
||||
_ThemeSlot.textTertiary: (Color(0x80394C0A), Color(0x80EAF7CC)),
|
||||
_ThemeSlot.shadow: (Color(0x33647E22), Color(0x26CBEE71)),
|
||||
_ThemeSlot.success: (Color(0xFF92EA3B), Color(0xFF92EA3B)),
|
||||
_ThemeSlot.warningAccent: (Color(0xFFFFA046), Color(0xFFFFA046)),
|
||||
_ThemeSlot.warningText: (Color(0xFF8F531B), Color(0xFFF0B37A)),
|
||||
_ThemeSlot.warningCard: (Color(0xFFFAEBDC), Color(0xFF201203)),
|
||||
_ThemeSlot.errorAccent: (Color(0xFFFF54A1), Color(0xFFFF54A1)),
|
||||
_ThemeSlot.errorText: (Color(0xFF8F1B4F), Color(0xFFF59EC5)),
|
||||
_ThemeSlot.errorCard: (Color(0xFFFADCE9), Color(0xFF1E030F)),
|
||||
};
|
||||
|
||||
(StringSetting, StringSetting) _settingsFor(_ThemeSlot slot) {
|
||||
switch (slot) {
|
||||
case _ThemeSlot.accent:
|
||||
return (
|
||||
SettingsRegistry.customAccentColorLight,
|
||||
SettingsRegistry.customAccentColorDark,
|
||||
);
|
||||
case _ThemeSlot.background:
|
||||
return (
|
||||
SettingsRegistry.customBackgroundColorLight,
|
||||
SettingsRegistry.customBackgroundColorDark,
|
||||
);
|
||||
case _ThemeSlot.card:
|
||||
return (
|
||||
SettingsRegistry.customCardColorLight,
|
||||
SettingsRegistry.customCardColorDark,
|
||||
);
|
||||
case _ThemeSlot.button:
|
||||
return (
|
||||
SettingsRegistry.customButtonColorLight,
|
||||
SettingsRegistry.customButtonColorDark,
|
||||
);
|
||||
case _ThemeSlot.secondary:
|
||||
return (
|
||||
SettingsRegistry.customSecondaryColorLight,
|
||||
SettingsRegistry.customSecondaryColorDark,
|
||||
);
|
||||
case _ThemeSlot.text:
|
||||
return (
|
||||
SettingsRegistry.customTextColorLight,
|
||||
SettingsRegistry.customTextColorDark,
|
||||
);
|
||||
case _ThemeSlot.textSecondary:
|
||||
return (
|
||||
SettingsRegistry.customTextSecondaryColorLight,
|
||||
SettingsRegistry.customTextSecondaryColorDark,
|
||||
);
|
||||
case _ThemeSlot.textTertiary:
|
||||
return (
|
||||
SettingsRegistry.customTextTertiaryColorLight,
|
||||
SettingsRegistry.customTextTertiaryColorDark,
|
||||
);
|
||||
case _ThemeSlot.shadow:
|
||||
return (
|
||||
SettingsRegistry.customShadowColorLight,
|
||||
SettingsRegistry.customShadowColorDark,
|
||||
);
|
||||
case _ThemeSlot.success:
|
||||
return (
|
||||
SettingsRegistry.customSuccessColorLight,
|
||||
SettingsRegistry.customSuccessColorDark,
|
||||
);
|
||||
case _ThemeSlot.warningAccent:
|
||||
return (
|
||||
SettingsRegistry.customWarningAccentColorLight,
|
||||
SettingsRegistry.customWarningAccentColorDark,
|
||||
);
|
||||
case _ThemeSlot.warningText:
|
||||
return (
|
||||
SettingsRegistry.customWarningTextColorLight,
|
||||
SettingsRegistry.customWarningTextColorDark,
|
||||
);
|
||||
case _ThemeSlot.warningCard:
|
||||
return (
|
||||
SettingsRegistry.customWarningCardColorLight,
|
||||
SettingsRegistry.customWarningCardColorDark,
|
||||
);
|
||||
case _ThemeSlot.errorAccent:
|
||||
return (
|
||||
SettingsRegistry.customErrorAccentColorLight,
|
||||
SettingsRegistry.customErrorAccentColorDark,
|
||||
);
|
||||
case _ThemeSlot.errorText:
|
||||
return (
|
||||
SettingsRegistry.customErrorTextColorLight,
|
||||
SettingsRegistry.customErrorTextColorDark,
|
||||
);
|
||||
case _ThemeSlot.errorCard:
|
||||
return (
|
||||
SettingsRegistry.customErrorCardColorLight,
|
||||
SettingsRegistry.customErrorCardColorDark,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _applySlotColor(FirkaColors colors, _ThemeSlot slot, Color color) {
|
||||
switch (slot) {
|
||||
case _ThemeSlot.accent:
|
||||
colors.accent = color;
|
||||
colors.a10p = color.withAlpha(0x1a);
|
||||
colors.a15p = color.withAlpha(0x26);
|
||||
case _ThemeSlot.background:
|
||||
colors.background = color;
|
||||
colors.background0p = color.withAlpha(0);
|
||||
case _ThemeSlot.card:
|
||||
colors.card = color;
|
||||
colors.cardTranslucent = color.withAlpha(0x80);
|
||||
case _ThemeSlot.button:
|
||||
colors.buttonSecondaryFill = color;
|
||||
case _ThemeSlot.secondary:
|
||||
colors.secondary = color;
|
||||
colors.buttonDisabledIcon = color.withAlpha(0x80);
|
||||
case _ThemeSlot.text:
|
||||
colors.textPrimary = color;
|
||||
case _ThemeSlot.textSecondary:
|
||||
colors.textSecondary = color;
|
||||
case _ThemeSlot.textTertiary:
|
||||
colors.textTertiary = color;
|
||||
colors.textTeritary = color;
|
||||
case _ThemeSlot.shadow:
|
||||
colors.shadowColor = color;
|
||||
case _ThemeSlot.success:
|
||||
colors.success = color;
|
||||
case _ThemeSlot.warningAccent:
|
||||
colors.warningAccent = color;
|
||||
colors.warning15p = color.withAlpha(0x26);
|
||||
case _ThemeSlot.warningText:
|
||||
colors.warningText = color;
|
||||
case _ThemeSlot.warningCard:
|
||||
colors.warningCard = color;
|
||||
case _ThemeSlot.errorAccent:
|
||||
colors.errorAccent = color;
|
||||
colors.error15p = color.withAlpha(0x26);
|
||||
case _ThemeSlot.errorText:
|
||||
colors.errorText = color;
|
||||
case _ThemeSlot.errorCard:
|
||||
colors.errorCard = color;
|
||||
}
|
||||
}
|
||||
|
||||
class _ThemeEditorScreenState extends State<ThemeEditorScreen> {
|
||||
_ThemeSlot? _slot = _ThemeSlot.accent;
|
||||
_BrightnessMode _mode = _BrightnessMode.both;
|
||||
late HSVColor _hsv;
|
||||
late final ThemePreviewData _preview;
|
||||
|
||||
// The app's real brightness before this screen started overriding
|
||||
// `appStyle` for live preview — used as the reference for "both" mode,
|
||||
// and restored when leaving the screen.
|
||||
late final bool _originalIsLight;
|
||||
|
||||
final _hexController = TextEditingController();
|
||||
bool _hexFocused = false;
|
||||
|
||||
SettingsRepository get _settings => widget.data.settings;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_originalIsLight = appStyle.isLight;
|
||||
_preview = ThemePreviewData.build();
|
||||
_hsv = HSVColor.fromColor(
|
||||
_colorForSlotAndMode(_slot!, _mode),
|
||||
);
|
||||
_syncHexField();
|
||||
_refreshPreviewStyle();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
initTheme(widget.data);
|
||||
_hexController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _previewIsLight => switch (_mode) {
|
||||
_BrightnessMode.light => true,
|
||||
_BrightnessMode.dark => false,
|
||||
_BrightnessMode.both => _originalIsLight,
|
||||
};
|
||||
|
||||
// Rebuilds the global `appStyle` for whichever brightness is currently
|
||||
// being previewed, patching in the *live* (possibly not-yet-persisted)
|
||||
// slot color so the preview always reflects what's on screen, not just
|
||||
// what's already saved.
|
||||
void _refreshPreviewStyle() {
|
||||
final isLight = _previewIsLight;
|
||||
final style = buildStyleForBrightness(isLight, isCustomTheme: true);
|
||||
final slot = _slot;
|
||||
if (slot != null) {
|
||||
final editingLight = _mode != _BrightnessMode.dark;
|
||||
if (_mode == _BrightnessMode.both || editingLight == isLight) {
|
||||
_applySlotColor(style.colors, slot, _hsv.toColor());
|
||||
}
|
||||
}
|
||||
appStyle = style;
|
||||
}
|
||||
|
||||
void _popAndRestore() {
|
||||
initTheme(widget.data);
|
||||
context.pop();
|
||||
}
|
||||
|
||||
Color _currentColor(_ThemeSlot slot, {required bool isLightSource}) {
|
||||
final (light, dark) = _settingsFor(slot);
|
||||
final raw = _settings.get(isLightSource ? light : dark);
|
||||
return raw.toColorFromHexSetting();
|
||||
}
|
||||
|
||||
Color _colorForSlotAndMode(_ThemeSlot slot, _BrightnessMode mode) {
|
||||
final light = _currentColor(slot, isLightSource: true);
|
||||
final dark = _currentColor(slot, isLightSource: false);
|
||||
switch (mode) {
|
||||
case _BrightnessMode.light:
|
||||
return light;
|
||||
case _BrightnessMode.dark:
|
||||
return dark;
|
||||
case _BrightnessMode.both:
|
||||
return light == dark
|
||||
? light
|
||||
: _currentColor(slot, isLightSource: _originalIsLight);
|
||||
}
|
||||
}
|
||||
|
||||
void _syncHexField() {
|
||||
if (!_hexFocused) {
|
||||
final color = _hsv.toColor();
|
||||
final hex = color.toHexSetting();
|
||||
_hexController.text =
|
||||
(color.a >= 1.0 ? hex.substring(4) : hex.substring(2))
|
||||
.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _applyHsv(HSVColor hsv) async {
|
||||
final slot = _slot;
|
||||
if (slot == null) return;
|
||||
|
||||
setState(() {
|
||||
_hsv = hsv;
|
||||
// Instant feedback: patch the preview before the settings roundtrip.
|
||||
_refreshPreviewStyle();
|
||||
});
|
||||
_syncHexField();
|
||||
|
||||
final color = hsv.toColor();
|
||||
final hex = color.toHexSetting();
|
||||
final (light, dark) = _settingsFor(slot);
|
||||
|
||||
switch (_mode) {
|
||||
case _BrightnessMode.both:
|
||||
await _settings.set(light, hex);
|
||||
await _settings.set(dark, hex);
|
||||
case _BrightnessMode.light:
|
||||
await _settings.set(light, hex);
|
||||
case _BrightnessMode.dark:
|
||||
await _settings.set(dark, hex);
|
||||
}
|
||||
|
||||
if (isBuiltinThemeId(Settings.selectedThemeId.value)) {
|
||||
final id = Snowflake.nextId();
|
||||
final theme = UserTheme(
|
||||
id: id,
|
||||
name: widget.data.l10n.s_c_themes_own_label,
|
||||
origin: ThemeOrigin.own,
|
||||
swatch: UserTheme.swatchFromAppStyle(),
|
||||
);
|
||||
await isarInit.writeTxn(() async {
|
||||
await isarInit.userThemeModels.putByThemeId(theme.toModel());
|
||||
});
|
||||
await Settings.selectedThemeId.set(id);
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
// Persisting re-triggers initTheme via the settings effect, which
|
||||
// resets `appStyle` to the app's real brightness — reassert the
|
||||
// preview override on top of that.
|
||||
setState(_refreshPreviewStyle);
|
||||
context.read<ThemeCubit>().refresh();
|
||||
}
|
||||
|
||||
void _selectSlot(_ThemeSlot slot) {
|
||||
setState(() {
|
||||
if (_slot == slot) {
|
||||
_slot = null;
|
||||
_refreshPreviewStyle();
|
||||
return;
|
||||
}
|
||||
_slot = slot;
|
||||
_hsv = HSVColor.fromColor(_colorForSlotAndMode(slot, _mode));
|
||||
_refreshPreviewStyle();
|
||||
});
|
||||
_syncHexField();
|
||||
}
|
||||
|
||||
void _selectMode(_BrightnessMode mode) {
|
||||
setState(() {
|
||||
_mode = mode;
|
||||
final slot = _slot;
|
||||
if (slot != null) {
|
||||
_hsv = HSVColor.fromColor(_colorForSlotAndMode(slot, mode));
|
||||
}
|
||||
_refreshPreviewStyle();
|
||||
});
|
||||
_syncHexField();
|
||||
}
|
||||
|
||||
Future<void> _reset() async {
|
||||
final slot = _slot;
|
||||
if (slot == null) return;
|
||||
|
||||
final (lightSetting, darkSetting) = _settingsFor(slot);
|
||||
final (lightDefault, darkDefault) = _defaults[slot]!;
|
||||
|
||||
// Each brightness variant is restored to its *own* proper default —
|
||||
// in "both" mode this must not collapse light and dark to the same
|
||||
// color, since e.g. background's light/dark defaults are intentionally
|
||||
// very different.
|
||||
switch (_mode) {
|
||||
case _BrightnessMode.both:
|
||||
await _settings.set(lightSetting, lightDefault.toHexSetting());
|
||||
await _settings.set(darkSetting, darkDefault.toHexSetting());
|
||||
case _BrightnessMode.light:
|
||||
await _settings.set(lightSetting, lightDefault.toHexSetting());
|
||||
case _BrightnessMode.dark:
|
||||
await _settings.set(darkSetting, darkDefault.toHexSetting());
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_hsv = HSVColor.fromColor(
|
||||
switch (_mode) {
|
||||
_BrightnessMode.light => lightDefault,
|
||||
_BrightnessMode.dark => darkDefault,
|
||||
_BrightnessMode.both => lightDefault == darkDefault
|
||||
? lightDefault
|
||||
: (_originalIsLight ? lightDefault : darkDefault),
|
||||
},
|
||||
);
|
||||
_refreshPreviewStyle();
|
||||
});
|
||||
_syncHexField();
|
||||
context.read<ThemeCubit>().refresh();
|
||||
}
|
||||
|
||||
Future<void> _randomize() async {
|
||||
await _applyHsv(math.Random().nextVividHSVColor());
|
||||
}
|
||||
|
||||
void _onHexSubmit(String value) {
|
||||
final cleaned = value.replaceAll("#", "").trim();
|
||||
if (cleaned.length == 6) {
|
||||
final parsed = int.tryParse("0xFF$cleaned");
|
||||
if (parsed == null) return;
|
||||
_applyHsv(HSVColor.fromColor(Color(parsed)));
|
||||
} else if (cleaned.length == 8) {
|
||||
final parsed = int.tryParse("0x$cleaned");
|
||||
if (parsed == null) return;
|
||||
_applyHsv(HSVColor.fromColor(Color(parsed)));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (didPop) return;
|
||||
_popAndRestore();
|
||||
},
|
||||
child: BlocProvider<ThemeCubit>.value(
|
||||
value: widget.data.themeCubit,
|
||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, _) {
|
||||
return Scaffold(
|
||||
backgroundColor: appStyle.colors.background,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: _header(context),
|
||||
),
|
||||
Expanded(child: _previewCarousel()),
|
||||
_bottomEditor(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _header(BuildContext context) {
|
||||
final l10n = widget.data.l10n;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: GestureDetector(
|
||||
onTap: _popAndRestore,
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
l10n.s_customization,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
headingText(l10n.s_c_colors_theme_header),
|
||||
style: appStyle.fonts.H_H1.apply(color: appStyle.colors.textPrimary),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _previewCarousel() {
|
||||
return CarouselSlider(
|
||||
options: CarouselOptions(
|
||||
height: double.infinity,
|
||||
viewportFraction: 1.0,
|
||||
enableInfiniteScroll: false,
|
||||
enlargeCenterPage: false,
|
||||
padEnds: false,
|
||||
),
|
||||
items: buildThemePreviewCarouselItems(
|
||||
data: widget.data,
|
||||
preview: _preview,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _bottomEditor() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 20),
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.card,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: appStyle.colors.shadowColor,
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, -4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (_slot != null) ...[
|
||||
_hueSlider(),
|
||||
const SizedBox(height: 8),
|
||||
_saturationSlider(),
|
||||
const SizedBox(height: 8),
|
||||
_valueSlider(),
|
||||
const SizedBox(height: 8),
|
||||
_opacitySlider(),
|
||||
const SizedBox(height: 12),
|
||||
_hexRow(),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
_slotBar(),
|
||||
const SizedBox(height: 12),
|
||||
_modeBar(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _hueSlider() {
|
||||
return ColorSlider(
|
||||
value: _hsv.hue / 360,
|
||||
trackGradient: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFFFF0000),
|
||||
Color(0xFFFFFF00),
|
||||
Color(0xFF00FF00),
|
||||
Color(0xFF00FFFF),
|
||||
Color(0xFF0000FF),
|
||||
Color(0xFFFF00FF),
|
||||
Color(0xFFFF0000),
|
||||
],
|
||||
),
|
||||
thumbColor: _hsv.toColor(),
|
||||
onChanged: (t) => _applyHsv(_hsv.withHue(t * 360)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _saturationSlider() {
|
||||
final fullSat = _hsv.withSaturation(1).withValue(1).toColor();
|
||||
return ColorSlider(
|
||||
value: _hsv.saturation,
|
||||
trackGradient: LinearGradient(colors: [Colors.white, fullSat]),
|
||||
thumbColor: _hsv.withValue(1).toColor(),
|
||||
onChanged: (t) => _applyHsv(_hsv.withSaturation(t)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _valueSlider() {
|
||||
final fullV = _hsv.withValue(1).toColor();
|
||||
return ColorSlider(
|
||||
value: _hsv.value,
|
||||
trackGradient: LinearGradient(colors: [Colors.black, fullV]),
|
||||
thumbColor: _hsv.toColor(),
|
||||
onChanged: (t) => _applyHsv(_hsv.withValue(t)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _opacitySlider() {
|
||||
final solid = _hsv.toColor().withAlpha(255);
|
||||
return ColorSlider(
|
||||
value: _hsv.alpha,
|
||||
trackGradient: LinearGradient(
|
||||
colors: [
|
||||
solid.withAlpha(0),
|
||||
solid,
|
||||
],
|
||||
),
|
||||
thumbColor: _hsv.toColor(),
|
||||
onChanged: (t) => _applyHsv(_hsv.withAlpha(t.clamp(0.0, 1.0))),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _hexRow() {
|
||||
return FirkaCard(
|
||||
left: [
|
||||
_iconCircle(icon: Majesticon.reloadLine, onTap: _reset, faded: true),
|
||||
const SizedBox(width: 12),
|
||||
Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _hsv.toColor(),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: appStyle.colors.shadowColor,
|
||||
blurRadius: appStyle.isLight ? 3 : 0,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
"HEX",
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
SizedBox(
|
||||
width: 96,
|
||||
child: Focus(
|
||||
onFocusChange: (focused) => setState(() => _hexFocused = focused),
|
||||
child: TextField(
|
||||
controller: _hexController,
|
||||
keyboardType: TextInputType.text,
|
||||
textCapitalization: TextCapitalization.characters,
|
||||
maxLength: 8,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r'[0-9a-fA-F]')),
|
||||
],
|
||||
onSubmitted: _onHexSubmit,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
counterText: "",
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
hintText: "FFFFFF",
|
||||
hintStyle: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
right: [
|
||||
_iconCircle(
|
||||
icon: Majesticon.repeatCircleLine,
|
||||
onTap: _randomize,
|
||||
accent: true,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _iconCircle({
|
||||
required Object icon,
|
||||
required VoidCallback onTap,
|
||||
bool faded = false,
|
||||
bool accent = false,
|
||||
}) {
|
||||
final bgColor = accent
|
||||
? appStyle.colors.accent
|
||||
: appStyle.colors.buttonSecondaryFill;
|
||||
final iconColor = accent
|
||||
? appStyle.colors.textPrimary
|
||||
: appStyle.colors.textSecondary;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: bgColor,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: appStyle.colors.shadowColor,
|
||||
blurRadius: appStyle.isLight ? 2 : 0,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
icon,
|
||||
size: 18,
|
||||
color: iconColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _slotBar() {
|
||||
final l10n = widget.data.l10n;
|
||||
final labels = <_ThemeSlot, String>{
|
||||
_ThemeSlot.accent: l10n.s_c_slot_accent,
|
||||
_ThemeSlot.background: l10n.s_c_slot_background,
|
||||
_ThemeSlot.card: l10n.s_c_slot_cards,
|
||||
_ThemeSlot.button: l10n.s_c_slot_buttons,
|
||||
_ThemeSlot.secondary: l10n.s_c_slot_secondary,
|
||||
_ThemeSlot.text: l10n.s_c_slot_text,
|
||||
_ThemeSlot.textSecondary: l10n.s_c_slot_text_secondary,
|
||||
_ThemeSlot.textTertiary: l10n.s_c_slot_text_tertiary,
|
||||
_ThemeSlot.shadow: l10n.s_c_slot_shadow,
|
||||
_ThemeSlot.success: l10n.s_c_slot_success,
|
||||
_ThemeSlot.warningAccent: l10n.s_c_slot_warning,
|
||||
_ThemeSlot.warningText: l10n.s_c_slot_warning_text,
|
||||
_ThemeSlot.warningCard: l10n.s_c_slot_warning_card,
|
||||
_ThemeSlot.errorAccent: l10n.s_c_slot_error,
|
||||
_ThemeSlot.errorText: l10n.s_c_slot_error_text,
|
||||
_ThemeSlot.errorCard: l10n.s_c_slot_error_card,
|
||||
};
|
||||
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (final slot in _ThemeSlot.values) ...[
|
||||
_pill(
|
||||
labels[slot]!,
|
||||
selected: slot == _slot,
|
||||
onTap: () => _selectSlot(slot),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _modeBar() {
|
||||
final l10n = widget.data.l10n;
|
||||
final labels = <_BrightnessMode, String>{
|
||||
_BrightnessMode.both: l10n.s_c_mode_both,
|
||||
_BrightnessMode.light: l10n.s_c_theme_light,
|
||||
_BrightnessMode.dark: l10n.s_c_theme_dark,
|
||||
};
|
||||
|
||||
return FirkaCard.single(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final mode in _BrightnessMode.values)
|
||||
Expanded(
|
||||
child: _segment(
|
||||
labels[mode]!,
|
||||
selected: mode == _mode,
|
||||
onTap: () => _selectMode(mode),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _pill(
|
||||
String label, {
|
||||
required bool selected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOut,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? appStyle.colors.accent : appStyle.colors.card,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: appStyle.fonts.B_14SB.apply(
|
||||
color: selected
|
||||
? appStyle.colors.textPrimary
|
||||
: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _segment(
|
||||
String label, {
|
||||
required bool selected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOut,
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? appStyle.colors.card : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
label,
|
||||
style: appStyle.fonts.B_14SB.apply(
|
||||
color: selected
|
||||
? appStyle.colors.textPrimary
|
||||
: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import "package:carousel_slider/carousel_slider.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_bloc/flutter_bloc.dart";
|
||||
import "package:go_router/go_router.dart";
|
||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
||||
|
||||
import "package:firka/app/app_state.dart";
|
||||
import "package:firka/app/initialization.dart";
|
||||
import "package:firka/core/bloc/theme_cubit.dart";
|
||||
import "package:firka/ui/components/firka_icon_button.dart";
|
||||
import "package:firka/ui/phone/screens/themes/preview/theme_preview_data.dart";
|
||||
import "package:firka/ui/phone/screens/themes/preview/theme_preview_pages.dart";
|
||||
@@ -34,6 +37,16 @@ class _ThemeScreenState extends State<ThemeScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_preview = ThemePreviewData.build();
|
||||
appStyle = buildStyleForBrightness(
|
||||
appStyle.isLight,
|
||||
isCustomTheme: !_theme.isBuiltin,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
initTheme(widget.data);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String get _originLabel {
|
||||
@@ -60,92 +73,107 @@ class _ThemeScreenState extends State<ThemeScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = widget.data.l10n;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: appStyle.colors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: GestureDetector(
|
||||
onTap: () => context.pop(),
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 1),
|
||||
child: Text(
|
||||
l10n.s_c_theme_header,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
return BlocBuilder<ThemeCubit, ThemeState>(
|
||||
bloc: widget.data.themeCubit,
|
||||
builder: (context, _) {
|
||||
return Scaffold(
|
||||
backgroundColor: appStyle.colors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ThemeSwatchIcon(swatch: _theme.swatch, size: 48),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ThemeNameLabel(
|
||||
name: _theme.name,
|
||||
editable: _theme.canRename,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
onChanged: (value) {
|
||||
setState(() => _theme.name = value);
|
||||
widget.args.onChanged();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_originLabel,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
Row(
|
||||
children: [
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 0),
|
||||
child: GestureDetector(
|
||||
onTap: () => context.pop(),
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.chevronLeftLine,
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: const Offset(-4, 1),
|
||||
child: Text(
|
||||
l10n.s_c_theme_header,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (_theme.isOwn) ...[
|
||||
FirkaIconButton(
|
||||
onTap: () {},
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Line,
|
||||
size: 18,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
ThemeSwatchIcon(swatch: _theme.swatch, size: 48),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ThemeNameLabel(
|
||||
name: _theme.name,
|
||||
editable: _theme.canRename,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
onChanged: (value) {
|
||||
setState(() => _theme.name = value);
|
||||
widget.args.onChanged();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_originLabel,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
FirkaIconButton(
|
||||
onTap: () {},
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.shareLine,
|
||||
size: 18,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (_theme.isOwn) ...[
|
||||
FirkaIconButton(
|
||||
onTap: () async {
|
||||
await context.push("/theme-editor");
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_theme.swatch =
|
||||
UserTheme.swatchFromAppStyle();
|
||||
appStyle = buildStyleForBrightness(
|
||||
appStyle.isLight,
|
||||
isCustomTheme: true,
|
||||
);
|
||||
});
|
||||
widget.args.onChanged();
|
||||
},
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.editPen4Line,
|
||||
size: 18,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
FirkaIconButton(
|
||||
onTap: () {},
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.shareLine,
|
||||
size: 18,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_theme.canDelete)
|
||||
FirkaIconButton(
|
||||
onTap: _delete,
|
||||
@@ -203,5 +231,7 @@ class _ThemeScreenState extends State<ThemeScreen> {
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,6 +338,10 @@ class _ThemesScreenState extends State<ThemesScreen> {
|
||||
onTap: () {},
|
||||
),
|
||||
_sectionLabel(l10n.s_c_themes_own),
|
||||
_themeRow(
|
||||
_builtin,
|
||||
selected: isBuiltinThemeId(_selectedId),
|
||||
),
|
||||
for (final theme in _ownThemes)
|
||||
_themeRow(
|
||||
theme,
|
||||
|
||||
@@ -13,7 +13,7 @@ class UserTheme {
|
||||
final String id;
|
||||
String name;
|
||||
final ThemeOrigin origin;
|
||||
final List<Color> swatch;
|
||||
List<Color> swatch;
|
||||
|
||||
UserTheme({
|
||||
required this.id,
|
||||
|
||||
@@ -54,7 +54,7 @@ class BottomTimeTableNavIconWidget extends StatelessWidget {
|
||||
style: appStyle.fonts.H_16px.apply(
|
||||
color: active
|
||||
? appStyle.colors.textPrimary
|
||||
: appStyle.colors.textTeritary,
|
||||
: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
@@ -62,7 +62,7 @@ class BottomTimeTableNavIconWidget extends StatelessWidget {
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: active
|
||||
? appStyle.colors.textSecondary
|
||||
: appStyle.colors.textTeritary,
|
||||
: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user