forked from firka/firka
feat: groundwork for customization
- Bring customization page up to par with design - Add a font picker - Add a themes page - Add theme previews - Add a theming system - Split built-in theme into core/grade themes
This commit is contained in:
@@ -18,6 +18,7 @@ import 'package:firka/l10n/app_localizations_de.dart';
|
||||
import 'package:firka/l10n/app_localizations_en.dart';
|
||||
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:intl/intl.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
@@ -96,34 +97,56 @@ void initTheme(AppInitialization data) {
|
||||
};
|
||||
|
||||
FirkaStyle baseStyle;
|
||||
final coreId = Settings.selectedCoreThemeId.value;
|
||||
final gradeId = Settings.selectedGradeThemeId.value;
|
||||
switch (Settings.themeBrightness.value) {
|
||||
case ThemeBrightness.light:
|
||||
baseStyle = lightStyle;
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: true,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(true);
|
||||
break;
|
||||
case ThemeBrightness.dark:
|
||||
baseStyle = darkStyle;
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: false,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(false);
|
||||
break;
|
||||
case ThemeBrightness.auto:
|
||||
if (brightness == Brightness.dark) {
|
||||
baseStyle = darkStyle;
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: false,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(false);
|
||||
} else {
|
||||
baseStyle = lightStyle;
|
||||
baseStyle = styleFor(
|
||||
coreId: coreId,
|
||||
gradeId: gradeId,
|
||||
isLight: true,
|
||||
fonts: fonts,
|
||||
);
|
||||
themeCubit.setLightMode(true);
|
||||
}
|
||||
}
|
||||
|
||||
appStyle = FirkaStyle(
|
||||
isLight: baseStyle.isLight,
|
||||
colors: baseStyle.colors,
|
||||
fonts: fonts,
|
||||
);
|
||||
appStyle = baseStyle;
|
||||
}
|
||||
|
||||
Future<void> _initData(AppInitialization init) async {
|
||||
await init.settings.loadAll();
|
||||
final selectedThemeId = Settings.selectedThemeId.value;
|
||||
final normalized = normalizeSelectedThemeId(selectedThemeId);
|
||||
if (normalized != selectedThemeId) {
|
||||
await Settings.selectedThemeId.set(normalized);
|
||||
}
|
||||
await initLang(init);
|
||||
initTheme(init);
|
||||
|
||||
|
||||
@@ -133,4 +133,13 @@ abstract class SettingsSchema {
|
||||
values: TitleCapitalization.values,
|
||||
)
|
||||
TitleCapitalization get titleCapitalization;
|
||||
|
||||
@StringSetting(id: 1029, defaultValue: "builtin-firka-firka")
|
||||
String get selectedThemeId;
|
||||
|
||||
@StringSetting(id: 1030, defaultValue: "firka")
|
||||
String get selectedCoreThemeId;
|
||||
|
||||
@StringSetting(id: 1031, defaultValue: "firka")
|
||||
String get selectedGradeThemeId;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,12 @@ class SettingsRegistry {
|
||||
static const titleFont = EnumSetting(id: 1026, defaultValue: TitleFont.montserrat, values: TitleFont.values);
|
||||
static const titleWeight = DoubleSetting(id: 1027, defaultValue: 700, min: 100, max: 900, precision: 0, step: 100);
|
||||
static const titleCapitalization = EnumSetting(id: 1028, defaultValue: TitleCapitalization.normal, values: TitleCapitalization.values);
|
||||
static const selectedThemeId = StringSetting(id: 1029, defaultValue: "builtin-firka-firka");
|
||||
static const selectedCoreThemeId = StringSetting(id: 1030, defaultValue: "firka");
|
||||
static const selectedGradeThemeId = StringSetting(id: 1031, defaultValue: "firka");
|
||||
|
||||
static const all = <Setting>[
|
||||
bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, liveActivityEnabled, liveActivityPrivacyEverDeclined, morningNotificationEnabled, morningNotificationTime, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization,
|
||||
bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, liveActivityEnabled, liveActivityPrivacyEverDeclined, morningNotificationEnabled, morningNotificationTime, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -64,4 +67,7 @@ extension SettingsAccessors on SettingsRepository {
|
||||
SilentlySettable<TitleFont> get titleFont => SilentlySettable(this, SettingsRegistry.titleFont);
|
||||
SilentlySettable<double> get titleWeight => SilentlySettable(this, SettingsRegistry.titleWeight);
|
||||
SilentlySettable<TitleCapitalization> get titleCapitalization => SilentlySettable(this, SettingsRegistry.titleCapitalization);
|
||||
SilentlySettable<String> get selectedThemeId => SilentlySettable(this, SettingsRegistry.selectedThemeId);
|
||||
SilentlySettable<String> get selectedCoreThemeId => SilentlySettable(this, SettingsRegistry.selectedCoreThemeId);
|
||||
SilentlySettable<String> get selectedGradeThemeId => SilentlySettable(this, SettingsRegistry.selectedGradeThemeId);
|
||||
}
|
||||
|
||||
31
firka/lib/core/snowflake.dart
Normal file
31
firka/lib/core/snowflake.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import "dart:math";
|
||||
|
||||
/// Local Twitter-style snowflake IDs (64-bit, decimal string).
|
||||
class Snowflake {
|
||||
static const int _epochMs = 1704067200000; // 2024-01-01 UTC
|
||||
static final int _workerId = Random().nextInt(1 << 10);
|
||||
static int _sequence = 0;
|
||||
static int _lastTimestamp = -1;
|
||||
|
||||
static String nextId() {
|
||||
var ts = DateTime.now().millisecondsSinceEpoch;
|
||||
if (ts < _lastTimestamp) {
|
||||
ts = _lastTimestamp;
|
||||
}
|
||||
|
||||
if (ts == _lastTimestamp) {
|
||||
_sequence = (_sequence + 1) & 0xFFF;
|
||||
if (_sequence == 0) {
|
||||
while (ts <= _lastTimestamp) {
|
||||
ts = DateTime.now().millisecondsSinceEpoch;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_sequence = 0;
|
||||
}
|
||||
|
||||
_lastTimestamp = ts;
|
||||
final id = ((ts - _epochMs) << 22) | (_workerId << 12) | _sequence;
|
||||
return id.toString();
|
||||
}
|
||||
}
|
||||
Submodule firka/lib/l10n updated: ccecd12c17...f4812ec3b3
@@ -20,6 +20,9 @@ import 'package:firka/ui/phone/screens/login/login_screen.dart';
|
||||
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/themes/theme_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/themes/themes_screen.dart';
|
||||
import 'package:firka/ui/phone/screens/themes/user_theme.dart';
|
||||
import 'package:firka/routing/chart_interaction_scope.dart';
|
||||
import 'package:firka/routing/shell_with_nav_bar.dart';
|
||||
import 'package:firka/routing/swipable_navigator_container.dart';
|
||||
@@ -95,6 +98,23 @@ GoRouter createAppRouter() {
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/themes',
|
||||
builder: (context, state) => DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: ThemesScreen(initData, key: state.pageKey),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/theme',
|
||||
builder: (context, state) {
|
||||
final args = state.extra as ThemeScreenArgs;
|
||||
return DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: ThemeScreen(initData, args, key: state.pageKey),
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/message',
|
||||
builder: (context, state) {
|
||||
|
||||
@@ -5,8 +5,14 @@ import "package:firka/ui/theme/style.dart";
|
||||
class FirkaIconButton extends StatelessWidget {
|
||||
final Widget child;
|
||||
final VoidCallback? onTap;
|
||||
final Color? color;
|
||||
|
||||
const FirkaIconButton({required this.child, this.onTap, super.key});
|
||||
const FirkaIconButton({
|
||||
required this.child,
|
||||
this.onTap,
|
||||
this.color,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -16,7 +22,7 @@ class FirkaIconButton extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(6),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.buttonSecondaryFill,
|
||||
color: color ?? appStyle.colors.buttonSecondaryFill,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
|
||||
@@ -549,6 +549,7 @@ class _SettingsPersonalizationViewState
|
||||
title: _l10n.s_c_my_themes,
|
||||
iconType: FirkaIconType.majesticons,
|
||||
iconData: Majesticon.editPen4Solid,
|
||||
onTap: () => context.push("/themes"),
|
||||
),
|
||||
_shortcutRow(
|
||||
title: _l10n.s_c_manage_subjects,
|
||||
|
||||
44
firka/lib/ui/phone/screens/themes/builtin_theme_id.dart
Normal file
44
firka/lib/ui/phone/screens/themes/builtin_theme_id.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import "package:firka_common/ui/theme/core_theme.dart";
|
||||
import "package:firka_common/ui/theme/grade_theme.dart";
|
||||
|
||||
const defaultCoreThemeId = "firka";
|
||||
const defaultGradeThemeId = "firka";
|
||||
const defaultBuiltinThemeId = "builtin-firka-firka";
|
||||
|
||||
String composeBuiltinThemeId(String coreId, String gradeId) {
|
||||
return "builtin-$coreId-$gradeId";
|
||||
}
|
||||
|
||||
bool isBuiltinThemeId(String id) {
|
||||
return id == "builtin" || id.startsWith("builtin-");
|
||||
}
|
||||
|
||||
/// Parses `builtin-{core}-{grade}`. Legacy `builtin` and malformed ids
|
||||
/// fall back to firka / firka. Map lookup fallback happens at resolve sites.
|
||||
(String coreId, String gradeId) parseBuiltinThemeId(String id) {
|
||||
if (id == "builtin" || id == defaultBuiltinThemeId) {
|
||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
||||
}
|
||||
if (!id.startsWith("builtin-")) {
|
||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
||||
}
|
||||
final rest = id.substring("builtin-".length);
|
||||
final sep = rest.indexOf("-");
|
||||
if (sep <= 0 || sep >= rest.length - 1) {
|
||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
||||
}
|
||||
final coreId = rest.substring(0, sep);
|
||||
final gradeId = rest.substring(sep + 1);
|
||||
if (coreId.isEmpty || gradeId.isEmpty) {
|
||||
return (defaultCoreThemeId, defaultGradeThemeId);
|
||||
}
|
||||
return (
|
||||
coreThemes.containsKey(coreId) ? coreId : defaultCoreThemeId,
|
||||
gradeThemes.containsKey(gradeId) ? gradeId : defaultGradeThemeId,
|
||||
);
|
||||
}
|
||||
|
||||
String normalizeSelectedThemeId(String id) {
|
||||
if (id == "builtin") return defaultBuiltinThemeId;
|
||||
return id;
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
import "package:firka/app/app_state.dart";
|
||||
import "package:firka/core/firka_bundle.dart";
|
||||
import "package:firka/ui/phone/widgets/bottom_nav_icon.dart";
|
||||
import "package:firka/ui/theme/style.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:intl/intl.dart";
|
||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
||||
|
||||
/// Which bottom-nav tab is highlighted inside a theme page preview.
|
||||
enum ThemePreviewNavTab { home, grades, timetable, omissions, other }
|
||||
|
||||
/// Phone-shaped frame that downscales a full-size home page for the theme carousel.
|
||||
class ThemePagePreview extends StatelessWidget {
|
||||
static const double designWidth = 390;
|
||||
static const double designHeight = 844;
|
||||
|
||||
final Widget body;
|
||||
final ThemePreviewNavTab activeTab;
|
||||
final AppInitialization data;
|
||||
|
||||
const ThemePagePreview({
|
||||
super.key,
|
||||
required this.body,
|
||||
required this.activeTab,
|
||||
required this.data,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.background,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: appStyle.colors.shadowColor,
|
||||
offset: const Offset(0, 1),
|
||||
blurRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
alignment: Alignment.topCenter,
|
||||
child: SizedBox(
|
||||
width: designWidth,
|
||||
height: designHeight,
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
size: const Size(designWidth, designHeight),
|
||||
padding: EdgeInsets.zero,
|
||||
viewPadding: EdgeInsets.zero,
|
||||
viewInsets: EdgeInsets.zero,
|
||||
),
|
||||
child: IgnorePointer(
|
||||
child: DefaultAssetBundle(
|
||||
bundle: FirkaBundle(),
|
||||
child: ColoredBox(
|
||||
color: appStyle.colors.background,
|
||||
child: Column(
|
||||
children: [
|
||||
_PreviewStatusBar(),
|
||||
Expanded(child: body),
|
||||
_PreviewBottomNav(
|
||||
data: data,
|
||||
activeTab: activeTab,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PreviewStatusBar extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final time = DateFormat("H:mm").format(DateTime.now());
|
||||
return SizedBox(
|
||||
height: 28,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
time,
|
||||
style: appStyle.fonts.B_12SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Icon(
|
||||
Icons.signal_cellular_alt,
|
||||
size: 12,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.wifi,
|
||||
size: 12,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.battery_full,
|
||||
size: 12,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PreviewBottomNav extends StatelessWidget {
|
||||
final AppInitialization data;
|
||||
final ThemePreviewNavTab activeTab;
|
||||
|
||||
const _PreviewBottomNav({
|
||||
required this.data,
|
||||
required this.activeTab,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = data.l10n;
|
||||
final tabs = <(ThemePreviewNavTab, String, Object, Object)>[
|
||||
(
|
||||
ThemePreviewNavTab.home,
|
||||
l10n.home,
|
||||
Majesticon.homeSolid,
|
||||
Majesticon.homeLine,
|
||||
),
|
||||
(
|
||||
ThemePreviewNavTab.grades,
|
||||
l10n.grades,
|
||||
Majesticon.bookmarkSolid,
|
||||
Majesticon.bookmarkLine,
|
||||
),
|
||||
(
|
||||
ThemePreviewNavTab.timetable,
|
||||
l10n.timetable,
|
||||
Majesticon.calendarSolid,
|
||||
Majesticon.calendarLine,
|
||||
),
|
||||
(
|
||||
ThemePreviewNavTab.omissions,
|
||||
l10n.omissions,
|
||||
Majesticon.timerSolid,
|
||||
Majesticon.timerLine,
|
||||
),
|
||||
];
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.bottomCenter,
|
||||
end: Alignment.topCenter,
|
||||
colors: [
|
||||
appStyle.colors.background,
|
||||
appStyle.colors.background.withValues(alpha: 0.0),
|
||||
],
|
||||
stops: const [0.0, 1.0],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
...tabs.map((nav) {
|
||||
final active = activeTab == nav.$1;
|
||||
return BottomNavIconWidget(
|
||||
() {},
|
||||
active,
|
||||
active ? nav.$3 : nav.$4,
|
||||
nav.$2,
|
||||
);
|
||||
}),
|
||||
BottomNavIconWidget(
|
||||
() {},
|
||||
activeTab == ThemePreviewNavTab.other,
|
||||
data.profilePicture != null
|
||||
? data.profilePicture!
|
||||
: Majesticon.menuLine,
|
||||
l10n.other,
|
||||
isProfilePicture: data.profilePicture != null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
import "package:firka_common/core/debug_helper.dart";
|
||||
import "package:firka_common/data/models/grade_cache_model.dart";
|
||||
import "package:firka_common/data/models/lesson_cache_model.dart";
|
||||
import "package:firka_common/data/models/message_cache_model.dart";
|
||||
import "package:firka_common/data/models/omission_cache_model.dart";
|
||||
import "package:firka_common/data/models/student_cache_model.dart";
|
||||
import "package:firka_common/data/models/subject_cache_model.dart";
|
||||
import "package:firka_common/data/models/test_cache_model.dart";
|
||||
import "package:kreta_api/kreta_api.dart";
|
||||
|
||||
/// In-memory placeholder models for theme page previews (Figma sample content).
|
||||
class ThemePreviewData {
|
||||
ThemePreviewData._({
|
||||
required this.now,
|
||||
required this.student,
|
||||
required this.subjects,
|
||||
required this.homeLessons,
|
||||
required this.timetableLessons,
|
||||
required this.messages,
|
||||
required this.tests,
|
||||
required this.grades,
|
||||
required this.omissions,
|
||||
required this.omissionBarSegments,
|
||||
required this.omissionExcusedCount,
|
||||
required this.omissionPendingCount,
|
||||
required this.omissionUnexcusedCount,
|
||||
required this.monthDayMeta,
|
||||
required this.subjectDetailSubject,
|
||||
required this.subjectDetailGrades,
|
||||
required this.subjectDetailTeacher,
|
||||
});
|
||||
|
||||
final DateTime now;
|
||||
final StudentCacheModel student;
|
||||
final List<SubjectCacheModel> subjects;
|
||||
final List<LessonCacheModel> homeLessons;
|
||||
final List<LessonCacheModel> timetableLessons;
|
||||
final List<MessageCacheModel> messages;
|
||||
final List<TestCacheModel> tests;
|
||||
final List<GradeCacheModel> grades;
|
||||
final List<OmissionCacheModel> omissions;
|
||||
final List<OmissionState?> omissionBarSegments;
|
||||
final int omissionExcusedCount;
|
||||
final int omissionPendingCount;
|
||||
final int omissionUnexcusedCount;
|
||||
final Map<DateTime, ThemePreviewMonthDay> monthDayMeta;
|
||||
final SubjectCacheModel subjectDetailSubject;
|
||||
final List<GradeCacheModel> subjectDetailGrades;
|
||||
final String subjectDetailTeacher;
|
||||
|
||||
SubjectCacheModel get matematika => subjects[0];
|
||||
SubjectCacheModel get angol => subjects[1];
|
||||
SubjectCacheModel get tortenelem => subjects[2];
|
||||
SubjectCacheModel get nemet => subjects[3];
|
||||
SubjectCacheModel get informatika => subjects[4];
|
||||
SubjectCacheModel get fizika => subjects[5];
|
||||
|
||||
static ThemePreviewData build([DateTime? clock]) {
|
||||
final now = clock ?? timeNow();
|
||||
// Anchor to real time so LessonSlider / LessonBigWidget (which call
|
||||
// timeNow()) keep Matematika as the active lesson with ~35 min left.
|
||||
final midnight = DateTime(now.year, now.month, now.day);
|
||||
final day = now;
|
||||
|
||||
final subjects = [
|
||||
_subject(1, "Matematika"),
|
||||
_subject(2, "Angol nyelv"),
|
||||
_subject(3, "Történelem"),
|
||||
_subject(4, "Német"),
|
||||
_subject(5, "Informatika"),
|
||||
_subject(6, "Fizika"),
|
||||
];
|
||||
final matematika = subjects[0];
|
||||
final angol = subjects[1];
|
||||
final tortenelem = subjects[2];
|
||||
final nemet = subjects[3];
|
||||
final informatika = subjects[4];
|
||||
final fizika = subjects[5];
|
||||
|
||||
final student = StudentCacheModel()
|
||||
..cacheKey = 1
|
||||
..createdAt = midnight
|
||||
..name = "Kovács Ádám"
|
||||
..birthday = DateTime(2008, 3, 15);
|
||||
|
||||
// Active lesson: started 10 min ago, ends in 34 min => "35 perc" via timeLeft.
|
||||
final homeLessons = [
|
||||
_lesson(
|
||||
id: 101,
|
||||
subject: matematika,
|
||||
dailyNth: 1,
|
||||
start: now.subtract(const Duration(minutes: 10)),
|
||||
end: now.add(const Duration(minutes: 34)),
|
||||
roomName: "123",
|
||||
),
|
||||
_lesson(
|
||||
id: 102,
|
||||
subject: angol,
|
||||
dailyNth: 2,
|
||||
start: now.add(const Duration(minutes: 45)),
|
||||
end: now.add(const Duration(minutes: 90)),
|
||||
roomName: "123",
|
||||
),
|
||||
_lesson(
|
||||
id: 103,
|
||||
subject: tortenelem,
|
||||
dailyNth: 3,
|
||||
start: now.add(const Duration(minutes: 100)),
|
||||
end: now.add(const Duration(minutes: 145)),
|
||||
roomName: "201",
|
||||
),
|
||||
];
|
||||
|
||||
final testLektion = TestCacheModel()
|
||||
..cacheKey = 201
|
||||
..createdAt = midnight
|
||||
..topic = "Lektion 14"
|
||||
..method = "Írásbeli"
|
||||
..teacherName = "Müller Anna";
|
||||
|
||||
final testBinaris = TestCacheModel()
|
||||
..cacheKey = 202
|
||||
..createdAt = midnight
|
||||
..topic = "Bináris fák"
|
||||
..method = "Írásbeli"
|
||||
..teacherName = "Nagy Péter";
|
||||
|
||||
final ttBase = DateTime(day.year, day.month, day.day, 8, 0);
|
||||
final timetableLessons = [
|
||||
_lesson(
|
||||
id: 301,
|
||||
subject: nemet,
|
||||
dailyNth: 1,
|
||||
start: ttBase,
|
||||
end: ttBase.add(const Duration(minutes: 45)),
|
||||
roomName: "12",
|
||||
substituteTeacher: "Kiss Éva",
|
||||
),
|
||||
_lesson(
|
||||
id: 302,
|
||||
subject: matematika,
|
||||
dailyNth: 2,
|
||||
start: ttBase.add(const Duration(minutes: 55)),
|
||||
end: ttBase.add(const Duration(minutes: 100)),
|
||||
roomName: "123",
|
||||
test: testLektion,
|
||||
),
|
||||
_lesson(
|
||||
id: 303,
|
||||
subject: matematika,
|
||||
dailyNth: 3,
|
||||
start: ttBase.add(const Duration(minutes: 110)),
|
||||
end: ttBase.add(const Duration(minutes: 155)),
|
||||
roomName: "123",
|
||||
),
|
||||
_lesson(
|
||||
id: 304,
|
||||
subject: informatika,
|
||||
dailyNth: 4,
|
||||
start: ttBase.add(const Duration(minutes: 165)),
|
||||
end: ttBase.add(const Duration(minutes: 210)),
|
||||
roomName: "Inf1",
|
||||
test: testBinaris,
|
||||
),
|
||||
_lesson(
|
||||
id: 305,
|
||||
subject: informatika,
|
||||
dailyNth: 5,
|
||||
start: ttBase.add(const Duration(minutes: 220)),
|
||||
end: ttBase.add(const Duration(minutes: 265)),
|
||||
roomName: "Inf1",
|
||||
),
|
||||
];
|
||||
|
||||
final homeTest = TestCacheModel()
|
||||
..cacheKey = 203
|
||||
..createdAt = midnight.subtract(const Duration(days: 1))
|
||||
..topic = "Függvények"
|
||||
..method = "Írásbeli"
|
||||
..teacherName = "Szabó Gábor";
|
||||
homeTest.lesson.value = homeLessons[0];
|
||||
|
||||
final messages = [
|
||||
MessageCacheModel()
|
||||
..cacheKey = 401
|
||||
..createdAt = midnight.subtract(const Duration(days: 2))
|
||||
..author = "Pálfy Zoltán"
|
||||
..title = "2023 novemberi programok"
|
||||
..contentHtml = "",
|
||||
MessageCacheModel()
|
||||
..cacheKey = 402
|
||||
..createdAt = midnight.subtract(const Duration(days: 2))
|
||||
..author = ":3"
|
||||
..title = "Mrrp mrrp meow meow"
|
||||
..contentHtml = "",
|
||||
];
|
||||
|
||||
final grades = [
|
||||
_grade(501, matematika, 5, midnight.subtract(const Duration(days: 3))),
|
||||
_grade(502, matematika, 4, midnight.subtract(const Duration(days: 10))),
|
||||
_grade(503, angol, 5, midnight.subtract(const Duration(days: 4))),
|
||||
_grade(504, angol, 3, midnight.subtract(const Duration(days: 12))),
|
||||
_grade(505, tortenelem, 4, midnight.subtract(const Duration(days: 5))),
|
||||
_grade(506, nemet, 5, midnight.subtract(const Duration(days: 6))),
|
||||
_grade(507, informatika, 5, midnight.subtract(const Duration(days: 7))),
|
||||
_grade(508, fizika, 4, midnight.subtract(const Duration(days: 8))),
|
||||
_grade(509, matematika, 5, midnight.subtract(const Duration(days: 15))),
|
||||
];
|
||||
|
||||
final omissions = [
|
||||
_omission(
|
||||
601,
|
||||
homeLessons[1],
|
||||
OmissionState.excused,
|
||||
midnight.subtract(const Duration(days: 20)),
|
||||
),
|
||||
_omission(
|
||||
602,
|
||||
homeLessons[2],
|
||||
OmissionState.pending,
|
||||
midnight.subtract(const Duration(days: 14)),
|
||||
),
|
||||
_omission(
|
||||
603,
|
||||
timetableLessons[0],
|
||||
OmissionState.unexcused,
|
||||
midnight.subtract(const Duration(days: 9)),
|
||||
),
|
||||
_omission(
|
||||
604,
|
||||
timetableLessons[3],
|
||||
OmissionState.excused,
|
||||
midnight.subtract(const Duration(days: 3)),
|
||||
),
|
||||
];
|
||||
|
||||
// School-year style bar: mostly present days, sparse marks, a few clusters
|
||||
// for thicker ticks (matches the design "barcode" look).
|
||||
final omissionBarSegments = List<OmissionState?>.filled(132, null);
|
||||
const excusedClusters = <List<int>>[
|
||||
[2],
|
||||
[7, 8],
|
||||
[14],
|
||||
[19],
|
||||
[24, 25, 26],
|
||||
[33],
|
||||
[38],
|
||||
[44, 45],
|
||||
[52],
|
||||
[58],
|
||||
[64, 65],
|
||||
[71],
|
||||
[77],
|
||||
[83, 84, 85],
|
||||
[92],
|
||||
[104, 105],
|
||||
[112],
|
||||
[118],
|
||||
[124, 125],
|
||||
];
|
||||
for (final cluster in excusedClusters) {
|
||||
for (final i in cluster) {
|
||||
omissionBarSegments[i] = OmissionState.excused;
|
||||
}
|
||||
}
|
||||
// Pending (orange) ticks, including a short cluster.
|
||||
for (final i in [16, 48, 49, 88, 110]) {
|
||||
omissionBarSegments[i] = OmissionState.pending;
|
||||
}
|
||||
// Unexcused (red/pink) ticks.
|
||||
for (final i in [61, 96, 127]) {
|
||||
omissionBarSegments[i] = OmissionState.unexcused;
|
||||
}
|
||||
|
||||
final monthStart = DateTime(day.year, day.month, 1);
|
||||
final gridStart = monthStart
|
||||
.subtract(Duration(days: monthStart.weekday - 1))
|
||||
.subtract(const Duration(days: 7));
|
||||
final monthDayMeta = <DateTime, ThemePreviewMonthDay>{};
|
||||
for (var i = 0; i < 49; i++) {
|
||||
final d = DateTime(
|
||||
gridStart.year,
|
||||
gridStart.month,
|
||||
gridStart.day,
|
||||
).add(Duration(days: i));
|
||||
final key = DateTime(d.year, d.month, d.day);
|
||||
final inMonth = d.month == day.month;
|
||||
final weekday = d.weekday;
|
||||
final lessonCount = !inMonth
|
||||
? 0
|
||||
: weekday > 5
|
||||
? 0
|
||||
: 5 - ((d.day + weekday) % 3);
|
||||
OmissionState? omission;
|
||||
if (inMonth && weekday <= 5 && d.day % 9 == 0) {
|
||||
omission = OmissionState.pending;
|
||||
} else if (inMonth && weekday <= 5 && d.day % 13 == 0) {
|
||||
omission = OmissionState.unexcused;
|
||||
}
|
||||
monthDayMeta[key] = ThemePreviewMonthDay(
|
||||
lessonCount: lessonCount.clamp(0, 7),
|
||||
hasTest: inMonth && weekday <= 5 && d.day % 7 == 0,
|
||||
omission: omission,
|
||||
);
|
||||
}
|
||||
|
||||
final subjectDetailGrades = grades
|
||||
.where((g) => g.subject.value?.cacheKey == matematika.cacheKey)
|
||||
.toList();
|
||||
|
||||
return ThemePreviewData._(
|
||||
now: day,
|
||||
student: student,
|
||||
subjects: subjects,
|
||||
homeLessons: homeLessons,
|
||||
timetableLessons: timetableLessons,
|
||||
messages: messages,
|
||||
tests: [homeTest],
|
||||
grades: grades,
|
||||
omissions: omissions,
|
||||
omissionBarSegments: omissionBarSegments,
|
||||
omissionExcusedCount: 2,
|
||||
omissionPendingCount: 1,
|
||||
omissionUnexcusedCount: 1,
|
||||
monthDayMeta: monthDayMeta,
|
||||
subjectDetailSubject: matematika,
|
||||
subjectDetailGrades: subjectDetailGrades,
|
||||
subjectDetailTeacher: "Szabó Gábor (Osztály)",
|
||||
);
|
||||
}
|
||||
|
||||
static SubjectCacheModel _subject(int id, String name) {
|
||||
final subject = SubjectCacheModel()
|
||||
..cacheKey = id
|
||||
..createdAt = DateTime(2024, 9, 1)
|
||||
..name = name;
|
||||
subject.classAverage.value = null;
|
||||
return subject;
|
||||
}
|
||||
|
||||
static LessonCacheModel _lesson({
|
||||
required int id,
|
||||
required SubjectCacheModel subject,
|
||||
required int dailyNth,
|
||||
required DateTime start,
|
||||
required DateTime end,
|
||||
required String roomName,
|
||||
String? substituteTeacher,
|
||||
TestCacheModel? test,
|
||||
}) {
|
||||
final lesson = LessonCacheModel()
|
||||
..cacheKey = id
|
||||
..createdAt = start
|
||||
..start = start
|
||||
..end = end
|
||||
..dailyNth = dailyNth
|
||||
..yearlyNth = dailyNth
|
||||
..name = subject.name
|
||||
..roomName = roomName
|
||||
..state = "Naplozott"
|
||||
..type = "OrarendiOra"
|
||||
..teacher = "Tanár"
|
||||
..substituteTeacher = substituteTeacher;
|
||||
lesson.subject.value = subject;
|
||||
// Mark optional links loaded so loadAndGet() does not call loadSync on
|
||||
// unmanaged (non-Isar) preview objects.
|
||||
lesson.test.value = test;
|
||||
lesson.homework.value = null;
|
||||
lesson.classGroup.value = null;
|
||||
lesson.omission.value = null;
|
||||
if (test != null) {
|
||||
test.lesson.value = lesson;
|
||||
}
|
||||
return lesson;
|
||||
}
|
||||
|
||||
static GradeCacheModel _grade(
|
||||
int id,
|
||||
SubjectCacheModel subject,
|
||||
int value,
|
||||
DateTime at,
|
||||
) {
|
||||
final grade = GradeCacheModel()
|
||||
..cacheKey = id
|
||||
..createdAt = at
|
||||
..mode = "Írásbeli"
|
||||
..topic = subject.name
|
||||
..type = "Értékelés"
|
||||
..valueType = "Osztalyzat"
|
||||
..writtenAt = at
|
||||
..numericValue = value
|
||||
..weightPercentage = 100
|
||||
..textValue = value.toString()
|
||||
..teacherName = "Tanár";
|
||||
grade.subject.value = subject;
|
||||
grade.classGroup.value = null;
|
||||
return grade;
|
||||
}
|
||||
|
||||
static OmissionCacheModel _omission(
|
||||
int id,
|
||||
LessonCacheModel lesson,
|
||||
OmissionState state,
|
||||
DateTime at,
|
||||
) {
|
||||
final omission = OmissionCacheModel()
|
||||
..cacheKey = id
|
||||
..createdAt = at
|
||||
..state = state
|
||||
..teacherName = "Tanár";
|
||||
omission.lesson.value = lesson;
|
||||
return omission;
|
||||
}
|
||||
}
|
||||
|
||||
class ThemePreviewMonthDay {
|
||||
const ThemePreviewMonthDay({
|
||||
required this.lessonCount,
|
||||
required this.hasTest,
|
||||
this.omission,
|
||||
});
|
||||
|
||||
final int lessonCount;
|
||||
final bool hasTest;
|
||||
final OmissionState? omission;
|
||||
}
|
||||
1023
firka/lib/ui/phone/screens/themes/preview/theme_preview_pages.dart
Normal file
1023
firka/lib/ui/phone/screens/themes/preview/theme_preview_pages.dart
Normal file
File diff suppressed because it is too large
Load Diff
368
firka/lib/ui/phone/screens/themes/sheets/theme_sheets.dart
Normal file
368
firka/lib/ui/phone/screens/themes/sheets/theme_sheets.dart
Normal file
@@ -0,0 +1,368 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:go_router/go_router.dart";
|
||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
||||
|
||||
import "package:firka/l10n/app_localizations.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";
|
||||
|
||||
Future<String?> showThemeNameSheet(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
return _showCenteredInputSheet(
|
||||
context: context,
|
||||
l10n: l10n,
|
||||
icon: Majesticon.plusLine,
|
||||
title: l10n.s_c_themes_create_title,
|
||||
subtitle: l10n.s_c_themes_create_subtitle,
|
||||
placeholder: l10n.s_c_themes_create_placeholder,
|
||||
confirmLabel: l10n.s_c_themes_continue,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> showThemeDeleteSheet(
|
||||
BuildContext context,
|
||||
AppLocalizations l10n,
|
||||
) async {
|
||||
final result = await showModalBottomSheet<bool>(
|
||||
context: context,
|
||||
elevation: 100,
|
||||
isScrollControlled: true,
|
||||
enableDrag: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
barrierColor: appStyle.colors.a15p,
|
||||
builder: (context) {
|
||||
return _ThemeConfirmSheet(
|
||||
icon: Majesticon.deleteBinLine,
|
||||
title: l10n.s_c_themes_delete_title,
|
||||
subtitle: l10n.s_c_themes_delete_subtitle,
|
||||
confirmLabel: l10n.s_c_themes_delete_confirm,
|
||||
cancelLabel: l10n.cancel,
|
||||
confirmColor: appStyle.colors.accent,
|
||||
onConfirm: () => context.pop(true),
|
||||
onCancel: () => context.pop(false),
|
||||
);
|
||||
},
|
||||
);
|
||||
return result ?? false;
|
||||
}
|
||||
|
||||
Future<String?> _showCenteredInputSheet({
|
||||
required BuildContext context,
|
||||
required AppLocalizations l10n,
|
||||
required Object icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required String placeholder,
|
||||
required String confirmLabel,
|
||||
}) {
|
||||
return showModalBottomSheet<String>(
|
||||
context: context,
|
||||
elevation: 100,
|
||||
isScrollControlled: true,
|
||||
enableDrag: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
barrierColor: appStyle.colors.a15p,
|
||||
builder: (context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
||||
),
|
||||
child: _ThemeNameInputSheet(
|
||||
icon: icon,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
placeholder: placeholder,
|
||||
confirmLabel: confirmLabel,
|
||||
cancelLabel: l10n.cancel,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _ThemeNameInputSheet extends StatefulWidget {
|
||||
final Object icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final String placeholder;
|
||||
final String confirmLabel;
|
||||
final String cancelLabel;
|
||||
|
||||
const _ThemeNameInputSheet({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.placeholder,
|
||||
required this.confirmLabel,
|
||||
required this.cancelLabel,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_ThemeNameInputSheet> createState() => _ThemeNameInputSheetState();
|
||||
}
|
||||
|
||||
class _ThemeNameInputSheetState extends State<_ThemeNameInputSheet> {
|
||||
late final TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
final value = _controller.text.trim();
|
||||
if (value.isEmpty) return;
|
||||
context.pop(value);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _ThemeSheetShell(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_sheetIcon(widget.icon),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
widget.title,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
widget.subtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.card,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
autofocus: true,
|
||||
textAlign: TextAlign.center,
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) => _submit(),
|
||||
cursorColor: appStyle.colors.accent,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.placeholder,
|
||||
hintStyle: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_sheetButton(
|
||||
label: widget.confirmLabel,
|
||||
color: appStyle.colors.accent,
|
||||
onTap: _submit,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_sheetButton(
|
||||
label: widget.cancelLabel,
|
||||
color: appStyle.colors.buttonSecondaryFill,
|
||||
onTap: () => context.pop(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ThemeConfirmSheet extends StatelessWidget {
|
||||
final Object icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final String confirmLabel;
|
||||
final String cancelLabel;
|
||||
final Color confirmColor;
|
||||
final VoidCallback onConfirm;
|
||||
final VoidCallback onCancel;
|
||||
|
||||
const _ThemeConfirmSheet({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.confirmLabel,
|
||||
required this.cancelLabel,
|
||||
required this.confirmColor,
|
||||
required this.onConfirm,
|
||||
required this.onCancel,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _ThemeSheetShell(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_sheetIcon(icon),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
subtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_sheetButton(
|
||||
label: confirmLabel,
|
||||
color: confirmColor,
|
||||
onTap: onConfirm,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_sheetButton(
|
||||
label: cancelLabel,
|
||||
color: appStyle.colors.buttonSecondaryFill,
|
||||
onTap: onCancel,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ThemeSheetShell extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const _ThemeSheetShell({required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: GestureDetector(
|
||||
onTap: () => context.pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const ColoredBox(color: Colors.transparent),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.background,
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(24),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Align(
|
||||
heightFactor: 0,
|
||||
alignment: Alignment.topCenter,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(top: 18),
|
||||
width: 40,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.shadowColor,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _sheetIcon(Object icon) {
|
||||
return Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.accent.withValues(alpha: 0.25),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.accent,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
icon,
|
||||
size: 20,
|
||||
color: appStyle.colors.textPrimaryLight,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _sheetButton({
|
||||
required String label,
|
||||
required Color color,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: FirkaCard(
|
||||
color: color,
|
||||
left: const [],
|
||||
center: [
|
||||
Text(
|
||||
label,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
207
firka/lib/ui/phone/screens/themes/theme_screen.dart
Normal file
207
firka/lib/ui/phone/screens/themes/theme_screen.dart
Normal file
@@ -0,0 +1,207 @@
|
||||
import "package:carousel_slider/carousel_slider.dart";
|
||||
import "package:flutter/material.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/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";
|
||||
import "package:firka/ui/phone/screens/themes/sheets/theme_sheets.dart";
|
||||
import "package:firka/ui/phone/screens/themes/user_theme.dart";
|
||||
import "package:firka/ui/phone/screens/themes/widgets/theme_name_label.dart";
|
||||
import "package:firka/ui/phone/screens/themes/widgets/theme_swatch_icon.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";
|
||||
|
||||
class ThemeScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
final ThemeScreenArgs args;
|
||||
|
||||
const ThemeScreen(this.data, this.args, {super.key});
|
||||
|
||||
@override
|
||||
State<ThemeScreen> createState() => _ThemeScreenState();
|
||||
}
|
||||
|
||||
class _ThemeScreenState extends State<ThemeScreen> {
|
||||
late final ThemePreviewData _preview;
|
||||
|
||||
UserTheme get _theme => widget.args.theme;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_preview = ThemePreviewData.build();
|
||||
}
|
||||
|
||||
String get _originLabel {
|
||||
final l10n = widget.data.l10n;
|
||||
switch (_theme.origin) {
|
||||
case ThemeOrigin.builtin:
|
||||
return l10n.s_c_themes_builtin_label;
|
||||
case ThemeOrigin.own:
|
||||
return l10n.s_c_themes_own_label;
|
||||
case ThemeOrigin.downloaded:
|
||||
return l10n.s_c_themes_imported_label;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _delete() async {
|
||||
final confirmed = await showThemeDeleteSheet(context, widget.data.l10n);
|
||||
if (!confirmed || !mounted) return;
|
||||
await widget.args.onDelete(_theme.id);
|
||||
if (!mounted) return;
|
||||
context.pop();
|
||||
}
|
||||
|
||||
@override
|
||||
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(
|
||||
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(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
if (_theme.isOwn) ...[
|
||||
FirkaIconButton(
|
||||
onTap: () {},
|
||||
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,
|
||||
color: appStyle.colors.accent,
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.deleteBinLine,
|
||||
size: 18,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
Expanded(
|
||||
child: CarouselSlider(
|
||||
options: CarouselOptions(
|
||||
height: double.infinity,
|
||||
viewportFraction: 0.72,
|
||||
enableInfiniteScroll: false,
|
||||
enlargeCenterPage: false,
|
||||
padEnds: false,
|
||||
),
|
||||
items: buildThemePreviewCarouselItems(
|
||||
data: widget.data,
|
||||
preview: _preview,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await widget.args.onUse(_theme.id);
|
||||
if (!context.mounted) return;
|
||||
context.pop();
|
||||
},
|
||||
child: FirkaCard(
|
||||
color: appStyle.colors.accent,
|
||||
left: const [],
|
||||
center: [
|
||||
Text(
|
||||
l10n.s_c_themes_use,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
372
firka/lib/ui/phone/screens/themes/themes_screen.dart
Normal file
372
firka/lib/ui/phone/screens/themes/themes_screen.dart
Normal file
@@ -0,0 +1,372 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:go_router/go_router.dart";
|
||||
import "package:isar_community/isar.dart";
|
||||
import "package:majesticons_flutter/majesticons_flutter.dart";
|
||||
|
||||
import "package:firka/app/app_state.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/firka_icon_button.dart";
|
||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
||||
import "package:firka/ui/phone/screens/themes/sheets/theme_sheets.dart";
|
||||
import "package:firka/ui/phone/screens/themes/user_theme.dart";
|
||||
import "package:firka/ui/phone/screens/themes/widgets/theme_name_label.dart";
|
||||
import "package:firka/ui/phone/screens/themes/widgets/theme_swatch_icon.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";
|
||||
|
||||
class ThemesScreen extends StatefulWidget {
|
||||
final AppInitialization data;
|
||||
|
||||
const ThemesScreen(this.data, {super.key});
|
||||
|
||||
@override
|
||||
State<ThemesScreen> createState() => _ThemesScreenState();
|
||||
}
|
||||
|
||||
class _ThemesScreenState extends State<ThemesScreen> {
|
||||
late List<UserTheme> _storedThemes;
|
||||
late String _selectedId;
|
||||
bool _loading = true;
|
||||
|
||||
UserTheme get _builtin => UserTheme.builtin(
|
||||
widget.data.l10n.s_c_themes_builtin_name,
|
||||
coreId: Settings.selectedCoreThemeId.value,
|
||||
gradeId: Settings.selectedGradeThemeId.value,
|
||||
isLight: appStyle.isLight,
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_storedThemes = [];
|
||||
_selectedId = normalizeSelectedThemeId(Settings.selectedThemeId.value);
|
||||
_loadThemes();
|
||||
}
|
||||
|
||||
Future<void> _loadThemes() async {
|
||||
final stored = await isarInit.userThemeModels.where().findAll();
|
||||
if (!mounted) return;
|
||||
|
||||
final normalized = normalizeSelectedThemeId(Settings.selectedThemeId.value);
|
||||
if (normalized != Settings.selectedThemeId.value) {
|
||||
await Settings.selectedThemeId.set(normalized);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_storedThemes = stored.map(UserTheme.fromModel).toList();
|
||||
_selectedId = normalized;
|
||||
final knownIds = {
|
||||
_builtin.id,
|
||||
..._storedThemes.map((t) => t.id),
|
||||
};
|
||||
if (isBuiltinThemeId(_selectedId)) {
|
||||
// Always use the composed builtin id for the current core/grade.
|
||||
_selectedId = _builtin.id;
|
||||
} else if (!knownIds.contains(_selectedId)) {
|
||||
_selectedId = _builtin.id;
|
||||
}
|
||||
_loading = false;
|
||||
});
|
||||
|
||||
if (isBuiltinThemeId(_selectedId) &&
|
||||
Settings.selectedThemeId.value != _builtin.id) {
|
||||
await Settings.selectedThemeId.set(_builtin.id);
|
||||
}
|
||||
}
|
||||
|
||||
UserTheme get _selected {
|
||||
if (isBuiltinThemeId(_selectedId)) {
|
||||
return _builtin;
|
||||
}
|
||||
return _storedThemes.firstWhere(
|
||||
(t) => t.id == _selectedId,
|
||||
orElse: () => _builtin,
|
||||
);
|
||||
}
|
||||
|
||||
List<UserTheme> get _ownThemes =>
|
||||
_storedThemes.where((t) => t.isOwn).toList(growable: false);
|
||||
|
||||
List<UserTheme> get _downloadedThemes =>
|
||||
_storedThemes.where((t) => t.isDownloaded).toList(growable: false);
|
||||
|
||||
Future<void> _persistTheme(UserTheme theme) async {
|
||||
if (theme.isBuiltin) return;
|
||||
await isarInit.writeTxn(() async {
|
||||
await isarInit.userThemeModels.putByThemeId(theme.toModel());
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _deleteTheme(String id) async {
|
||||
await isarInit.writeTxn(() async {
|
||||
await isarInit.userThemeModels.deleteByThemeId(id);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _setSelected(String id) async {
|
||||
final next = isBuiltinThemeId(id) ? _builtin.id : id;
|
||||
if (isBuiltinThemeId(next)) {
|
||||
final (coreId, gradeId) = parseBuiltinThemeId(next);
|
||||
await Settings.selectedCoreThemeId.set(coreId);
|
||||
await Settings.selectedGradeThemeId.set(gradeId);
|
||||
}
|
||||
setState(() => _selectedId = next);
|
||||
await Settings.selectedThemeId.set(next);
|
||||
}
|
||||
|
||||
Future<void> _selectBuiltin() async {
|
||||
final id = composeBuiltinThemeId(
|
||||
Settings.selectedCoreThemeId.value,
|
||||
Settings.selectedGradeThemeId.value,
|
||||
);
|
||||
await _setSelected(id);
|
||||
}
|
||||
|
||||
Future<void> _createTheme() async {
|
||||
final name = await showThemeNameSheet(context, widget.data.l10n);
|
||||
if (name == null || !mounted) return;
|
||||
|
||||
final theme = UserTheme(
|
||||
id: Snowflake.nextId(),
|
||||
name: name,
|
||||
origin: ThemeOrigin.own,
|
||||
swatch: UserTheme.swatchFromAppStyle(),
|
||||
);
|
||||
await _persistTheme(theme);
|
||||
if (!mounted) return;
|
||||
setState(() => _storedThemes.add(theme));
|
||||
await _openTheme(theme);
|
||||
}
|
||||
|
||||
Future<void> _renameTheme(UserTheme theme, String name) async {
|
||||
setState(() => theme.name = name);
|
||||
await _persistTheme(theme);
|
||||
}
|
||||
|
||||
Future<void> _openTheme(UserTheme theme) async {
|
||||
final openTheme = theme.isBuiltin ? _builtin : theme;
|
||||
await context.push(
|
||||
"/theme",
|
||||
extra: ThemeScreenArgs(
|
||||
theme: openTheme,
|
||||
onUse: (id) => _setSelected(id),
|
||||
onDelete: (id) async {
|
||||
await _deleteTheme(id);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_storedThemes.removeWhere((t) => t.id == id);
|
||||
if (_selectedId == id) {
|
||||
_selectedId = _builtin.id;
|
||||
}
|
||||
});
|
||||
if (isBuiltinThemeId(_selectedId)) {
|
||||
await _selectBuiltin();
|
||||
}
|
||||
},
|
||||
onChanged: () {
|
||||
_persistTheme(theme);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
Widget _sectionLabel(String text) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 8, top: 16),
|
||||
child: Text(
|
||||
text,
|
||||
style: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _checkMark() {
|
||||
return SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: Checkbox(
|
||||
value: true,
|
||||
fillColor: WidgetStateProperty.resolveWith<Color>((_) {
|
||||
return appStyle.colors.secondary;
|
||||
}),
|
||||
onChanged: (_) {},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _themeRow(UserTheme theme, {required bool selected}) {
|
||||
return GestureDetector(
|
||||
onTap: () => _openTheme(theme),
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
ThemeSwatchIcon(swatch: theme.swatch, size: 36),
|
||||
const SizedBox(width: 10),
|
||||
ThemeNameLabel(
|
||||
name: theme.name,
|
||||
editable: theme.canRename,
|
||||
onChanged: (value) => _renameTheme(theme, value),
|
||||
),
|
||||
],
|
||||
right: selected
|
||||
? [_checkMark(), const SizedBox(width: 4)]
|
||||
: const [SizedBox(width: 20)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _actionRow({
|
||||
required Object icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: FirkaCard(
|
||||
left: [
|
||||
FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
icon,
|
||||
size: 20,
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
label,
|
||||
style: appStyle.fonts.B_16SB.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
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: [
|
||||
Expanded(
|
||||
child: 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_my_themes,
|
||||
style: appStyle.fonts.H_H2.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
FirkaIconButton(
|
||||
onTap: _createTheme,
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.plusLine,
|
||||
size: 20,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
),
|
||||
FirkaIconButton(
|
||||
onTap: () {},
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.shareLine,
|
||||
size: 20,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
),
|
||||
FirkaIconButton(
|
||||
onTap: () {},
|
||||
child: FirkaIconWidget(
|
||||
FirkaIconType.majesticons,
|
||||
Majesticon.arrowDownCircleLine,
|
||||
size: 20,
|
||||
color: appStyle.colors.accent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: _loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView(
|
||||
children: [
|
||||
_sectionLabel(l10n.s_c_themes_current),
|
||||
_themeRow(_selected, selected: true),
|
||||
if (!_selected.isBuiltin)
|
||||
_actionRow(
|
||||
icon: Majesticon.shareLine,
|
||||
label: l10n.s_c_themes_share_current,
|
||||
onTap: () {},
|
||||
),
|
||||
_sectionLabel(l10n.s_c_themes_own),
|
||||
for (final theme in _ownThemes)
|
||||
_themeRow(
|
||||
theme,
|
||||
selected: theme.id == _selectedId,
|
||||
),
|
||||
_actionRow(
|
||||
icon: Majesticon.plusLine,
|
||||
label: l10n.s_c_themes_create_new,
|
||||
onTap: _createTheme,
|
||||
),
|
||||
_sectionLabel(l10n.s_c_themes_downloaded),
|
||||
for (final theme in _downloadedThemes)
|
||||
_themeRow(
|
||||
theme,
|
||||
selected: theme.id == _selectedId,
|
||||
),
|
||||
_actionRow(
|
||||
icon: Majesticon.arrowDownCircleLine,
|
||||
label: l10n.s_c_themes_import,
|
||||
onTap: () {},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
97
firka/lib/ui/phone/screens/themes/user_theme.dart
Normal file
97
firka/lib/ui/phone/screens/themes/user_theme.dart
Normal file
@@ -0,0 +1,97 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
import "package:firka_common/data/models/user_theme_model.dart";
|
||||
import "package:firka_common/ui/theme/core_theme.dart";
|
||||
import "package:firka_common/ui/theme/grade_theme.dart";
|
||||
|
||||
import "package:firka/ui/phone/screens/themes/builtin_theme_id.dart";
|
||||
import "package:firka/ui/theme/style.dart";
|
||||
|
||||
enum ThemeOrigin { builtin, own, downloaded }
|
||||
|
||||
class UserTheme {
|
||||
final String id;
|
||||
String name;
|
||||
final ThemeOrigin origin;
|
||||
final List<Color> swatch;
|
||||
|
||||
UserTheme({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.origin,
|
||||
required this.swatch,
|
||||
});
|
||||
|
||||
bool get isBuiltin =>
|
||||
origin == ThemeOrigin.builtin || isBuiltinThemeId(id);
|
||||
bool get isOwn => origin == ThemeOrigin.own && !isBuiltinThemeId(id);
|
||||
bool get isDownloaded => origin == ThemeOrigin.downloaded;
|
||||
bool get canRename => isOwn;
|
||||
bool get canDelete => !isBuiltin;
|
||||
|
||||
static List<Color> swatchFromCore(CoreTheme core, {bool isLight = true}) {
|
||||
final colors = core.forBrightness(isLight);
|
||||
return [colors.accent, colors.textPrimary, colors.background];
|
||||
}
|
||||
|
||||
static List<Color> swatchFromAppStyle() {
|
||||
return [
|
||||
appStyle.colors.accent,
|
||||
appStyle.colors.textPrimary,
|
||||
appStyle.colors.background,
|
||||
];
|
||||
}
|
||||
|
||||
static UserTheme builtin(
|
||||
String displayName, {
|
||||
String coreId = defaultCoreThemeId,
|
||||
String gradeId = defaultGradeThemeId,
|
||||
bool isLight = true,
|
||||
}) {
|
||||
final core = resolveCore(coreId);
|
||||
final grade = resolveGrade(gradeId);
|
||||
return UserTheme(
|
||||
id: composeBuiltinThemeId(core.id, grade.id),
|
||||
name: displayName,
|
||||
origin: ThemeOrigin.builtin,
|
||||
swatch: swatchFromCore(core, isLight: isLight),
|
||||
);
|
||||
}
|
||||
|
||||
factory UserTheme.fromModel(UserThemeModel model) {
|
||||
return UserTheme(
|
||||
id: model.themeId,
|
||||
name: model.name,
|
||||
origin: switch (model.origin) {
|
||||
"downloaded" => ThemeOrigin.downloaded,
|
||||
_ => ThemeOrigin.own,
|
||||
},
|
||||
swatch: model.swatchArgb.map(Color.new).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
UserThemeModel toModel() {
|
||||
return UserThemeModel()
|
||||
..themeId = id
|
||||
..name = name
|
||||
..origin = switch (origin) {
|
||||
ThemeOrigin.downloaded => "downloaded",
|
||||
ThemeOrigin.own || ThemeOrigin.builtin => "own",
|
||||
}
|
||||
..swatchArgb = swatch.map((c) => c.toARGB32()).toList();
|
||||
}
|
||||
}
|
||||
|
||||
class ThemeScreenArgs {
|
||||
final UserTheme theme;
|
||||
final Future<void> Function(String id) onUse;
|
||||
final Future<void> Function(String id) onDelete;
|
||||
final VoidCallback onChanged;
|
||||
|
||||
const ThemeScreenArgs({
|
||||
required this.theme,
|
||||
required this.onUse,
|
||||
required this.onDelete,
|
||||
required this.onChanged,
|
||||
});
|
||||
}
|
||||
123
firka/lib/ui/phone/screens/themes/widgets/theme_name_label.dart
Normal file
123
firka/lib/ui/phone/screens/themes/widgets/theme_name_label.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
import "package:firka/ui/theme/style.dart";
|
||||
|
||||
/// Plain-looking theme name that becomes an undecorated text field when tapped
|
||||
/// (own themes only).
|
||||
class ThemeNameLabel extends StatefulWidget {
|
||||
final String name;
|
||||
final bool editable;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final TextStyle? style;
|
||||
|
||||
const ThemeNameLabel({
|
||||
required this.name,
|
||||
required this.editable,
|
||||
this.onChanged,
|
||||
this.style,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ThemeNameLabel> createState() => _ThemeNameLabelState();
|
||||
}
|
||||
|
||||
class _ThemeNameLabelState extends State<ThemeNameLabel> {
|
||||
late final TextEditingController _controller;
|
||||
late final FocusNode _focusNode;
|
||||
bool _editing = false;
|
||||
late String _committed;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_committed = widget.name;
|
||||
_controller = TextEditingController(text: widget.name);
|
||||
_focusNode = FocusNode();
|
||||
_focusNode.addListener(_onFocusChange);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ThemeNameLabel oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!_editing && widget.name != _committed) {
|
||||
_committed = widget.name;
|
||||
_controller.text = widget.name;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.removeListener(_onFocusChange);
|
||||
_focusNode.dispose();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
TextStyle get _style =>
|
||||
widget.style ??
|
||||
appStyle.fonts.B_16SB.apply(color: appStyle.colors.textPrimary);
|
||||
|
||||
void _onFocusChange() {
|
||||
if (!_focusNode.hasFocus && _editing) {
|
||||
_commit();
|
||||
}
|
||||
}
|
||||
|
||||
void _startEditing() {
|
||||
if (!widget.editable) return;
|
||||
setState(() {
|
||||
_editing = true;
|
||||
_controller.text = _committed;
|
||||
_controller.selection = TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: _controller.text.length,
|
||||
);
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_focusNode.requestFocus();
|
||||
});
|
||||
}
|
||||
|
||||
void _commit() {
|
||||
final next = _controller.text.trim();
|
||||
final value = next.isEmpty ? _committed : next;
|
||||
_controller.text = value;
|
||||
if (value != _committed) {
|
||||
_committed = value;
|
||||
widget.onChanged?.call(value);
|
||||
}
|
||||
setState(() => _editing = false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!widget.editable) {
|
||||
return Text(widget.name, style: _style);
|
||||
}
|
||||
|
||||
if (!_editing) {
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: _startEditing,
|
||||
child: Text(_committed, style: _style),
|
||||
);
|
||||
}
|
||||
|
||||
return TextField(
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
style: _style,
|
||||
cursorColor: appStyle.colors.accent,
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) => _commit(),
|
||||
decoration: const InputDecoration(
|
||||
isDense: true,
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
class ThemeSwatchIcon extends StatelessWidget {
|
||||
final List<Color> swatch;
|
||||
final double size;
|
||||
|
||||
const ThemeSwatchIcon({
|
||||
required this.swatch,
|
||||
this.size = 40,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = swatch.length >= 3
|
||||
? swatch.take(3).toList()
|
||||
: [
|
||||
...swatch,
|
||||
...List.filled(3 - swatch.length, Colors.grey),
|
||||
];
|
||||
|
||||
return SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: CustomPaint(
|
||||
painter: _SwatchPainter(colors: colors),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SwatchPainter extends CustomPainter {
|
||||
final List<Color> colors;
|
||||
|
||||
_SwatchPainter({required this.colors});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final r = size.shortestSide * 0.29;
|
||||
final cx = size.width / 2;
|
||||
final cy = size.height / 2;
|
||||
final d = r * 1.5;
|
||||
final left = Offset(cx - d / 2, cy - d * 0.29);
|
||||
final right = Offset(cx + d / 2, cy - d * 0.29);
|
||||
final bottom = Offset(cx, cy + d * 0.58);
|
||||
final centers = [left, right, bottom];
|
||||
|
||||
// Soft per-circle halo.
|
||||
for (var i = 0; i < 3; i++) {
|
||||
canvas.drawCircle(
|
||||
centers[i],
|
||||
r,
|
||||
Paint()
|
||||
..color = colors[i].withValues(alpha: 0.4)
|
||||
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 2.5),
|
||||
);
|
||||
}
|
||||
|
||||
// Union blend: no white backdrop (that was leaking). First SrcOver, then
|
||||
// Multiply so overlaps mix; bottom on top with opacity to lighten.
|
||||
final bounds = Offset.zero & size;
|
||||
canvas.saveLayer(bounds, Paint());
|
||||
canvas.drawCircle(left, r, Paint()..color = colors[0]);
|
||||
canvas.drawCircle(
|
||||
right,
|
||||
r,
|
||||
Paint()
|
||||
..color = colors[1]
|
||||
..blendMode = BlendMode.multiply,
|
||||
);
|
||||
canvas.restore();
|
||||
|
||||
canvas.drawCircle(
|
||||
bottom,
|
||||
r,
|
||||
Paint()..color = colors[2].withValues(alpha: 0.75),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _SwatchPainter oldDelegate) {
|
||||
return oldDelegate.colors != colors;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +1,113 @@
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka_common/core/debug_helper.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka_common/data/models/omission_cache_model.dart';
|
||||
import 'package:firka_common/data/util.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
class OmissionBar extends StatelessWidget {
|
||||
const OmissionBar({super.key});
|
||||
|
||||
static Color stateToColor(OmissionCacheModel? o) {
|
||||
if (o == null) {
|
||||
return appStyle.colors.a15p;
|
||||
}
|
||||
switch (o.state) {
|
||||
case OmissionState.excused:
|
||||
return appStyle.colors.accent;
|
||||
case OmissionState.unexcused:
|
||||
return appStyle.colors.errorAccent;
|
||||
default:
|
||||
return appStyle.colors.warningAccent;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
DateTime now = timeNow();
|
||||
DateTime startOfTheYear = now.getFirstSchoolDay();
|
||||
|
||||
final dates = initData.client!.cache
|
||||
.getTimeTable()
|
||||
.between(startOfTheYear, now)
|
||||
.findAllSync()
|
||||
.map((l) => l.start.getMidnight())
|
||||
.toSet();
|
||||
|
||||
final omittedDates = initData.client!.cache
|
||||
.getOmissions()
|
||||
.findAllSync()
|
||||
.groupList((o) => o.lesson.loadAndGet()!.start);
|
||||
|
||||
final bar = ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Row(
|
||||
children: dates
|
||||
.map(
|
||||
(i) => Expanded(
|
||||
child: Container(
|
||||
height: 12,
|
||||
color: stateToColor(omittedDates[i]?.firstOrNull),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
|
||||
return FirkaCard.single(
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 8,
|
||||
children: [
|
||||
bar,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
DateFormat.MMMM(
|
||||
initData.l10n.localeName,
|
||||
).format(startOfTheYear).firstUpper(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
initData.l10n.now,
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/extensions.dart';
|
||||
import 'package:firka_common/core/debug_helper.dart';
|
||||
import 'package:firka_common/data/models/lesson_cache_model.dart';
|
||||
import 'package:firka_common/ui/components/firka_card.dart';
|
||||
import 'package:firka_common/data/models/omission_cache_model.dart';
|
||||
import 'package:firka_common/data/util.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
class OmissionBar extends StatelessWidget {
|
||||
/// When set, draws these segments instead of reading the Isar cache.
|
||||
final List<OmissionState?>? previewSegments;
|
||||
|
||||
const OmissionBar({super.key, this.previewSegments});
|
||||
|
||||
static Color stateToColor(OmissionCacheModel? o) {
|
||||
return stateColor(o?.state);
|
||||
}
|
||||
|
||||
static Color stateColor(OmissionState? state) {
|
||||
if (state == null) {
|
||||
return appStyle.colors.a15p;
|
||||
}
|
||||
switch (state) {
|
||||
case OmissionState.excused:
|
||||
return appStyle.colors.accent;
|
||||
case OmissionState.unexcused:
|
||||
return appStyle.colors.errorAccent;
|
||||
default:
|
||||
return appStyle.colors.warningAccent;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
DateTime now = timeNow();
|
||||
DateTime startOfTheYear = now.getFirstSchoolDay();
|
||||
|
||||
late final List<Color> segmentColors;
|
||||
if (previewSegments != null) {
|
||||
segmentColors = previewSegments!.map(stateColor).toList();
|
||||
} else {
|
||||
final dates = initData.client!.cache
|
||||
.getTimeTable()
|
||||
.between(startOfTheYear, now)
|
||||
.findAllSync()
|
||||
.map((l) => l.start.getMidnight())
|
||||
.toSet();
|
||||
|
||||
final omittedDates = initData.client!.cache
|
||||
.getOmissions()
|
||||
.findAllSync()
|
||||
.groupList((o) => o.lesson.loadAndGet()!.start);
|
||||
|
||||
segmentColors = dates
|
||||
.map((i) => stateToColor(omittedDates[i]?.firstOrNull))
|
||||
.toList();
|
||||
}
|
||||
|
||||
final bar = ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Row(
|
||||
children: segmentColors
|
||||
.map(
|
||||
(color) => Expanded(
|
||||
child: Container(
|
||||
height: 12,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
|
||||
return FirkaCard.single(
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 8),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 8,
|
||||
children: [
|
||||
bar,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
DateFormat.MMMM(
|
||||
initData.l10n.localeName,
|
||||
).format(startOfTheYear).firstUpper(),
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
initData.l10n.now,
|
||||
style: appStyle.fonts.B_14R.copyWith(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:firka_common/data/models/subject_cache_model.dart';
|
||||
import 'package:firka_common/data/models/teacher_model.dart';
|
||||
import 'package:firka_common/data/models/test_cache_model.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
import 'package:firka_common/data/models/user_theme_model.dart';
|
||||
import 'package:isar_community/isar.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
@@ -34,6 +35,7 @@ Future<Isar> initDB() async {
|
||||
AppSettingsModelSchema,
|
||||
SubjectCacheModelSchema,
|
||||
StudentCacheModelSchema,
|
||||
UserThemeModelSchema,
|
||||
],
|
||||
inspector: true,
|
||||
directory: dir.path,
|
||||
|
||||
20
firka_common/lib/data/models/user_theme_model.dart
Normal file
20
firka_common/lib/data/models/user_theme_model.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import "package:isar_community/isar.dart";
|
||||
|
||||
part "user_theme_model.g.dart";
|
||||
|
||||
@collection
|
||||
class UserThemeModel {
|
||||
Id id = Isar.autoIncrement;
|
||||
|
||||
@Index(unique: true, replace: true)
|
||||
late String themeId;
|
||||
|
||||
late String name;
|
||||
|
||||
/// `own` or `downloaded`. Built-in is not persisted.
|
||||
late String origin;
|
||||
|
||||
late List<int> swatchArgb;
|
||||
|
||||
UserThemeModel();
|
||||
}
|
||||
159
firka_common/lib/ui/theme/core_theme.dart
Normal file
159
firka_common/lib/ui/theme/core_theme.dart
Normal file
@@ -0,0 +1,159 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
const Map<String, CoreTheme> coreThemes = {
|
||||
"firka": firkaCore,
|
||||
};
|
||||
|
||||
const firkaCore = CoreTheme(
|
||||
id: "firka",
|
||||
light: CoreThemeColors(
|
||||
background: Color(0xFFFAFFF0),
|
||||
backgroundAmoled: Colors.black,
|
||||
background0p: Color(0x00fafff0),
|
||||
success: Color(0xFF92EA3B),
|
||||
shadowBlur: 2,
|
||||
textPrimary: Color(0xFF394C0A),
|
||||
textSecondary: Color(0xCC394C0A),
|
||||
textTertiary: Color(0x80394C0A),
|
||||
textTeritary: Color(0xFF97A474),
|
||||
textPrimaryLight: Color(0xFF394C0A),
|
||||
textSecondaryLight: Color(0xCC394C0A),
|
||||
textTertiaryLight: Color(0x80394C0A),
|
||||
card: Color(0xFFF3FBDE),
|
||||
cardTranslucent: Color(0x80F3FBDE),
|
||||
buttonSecondaryFill: Color(0xFFFEFFFD),
|
||||
buttonDisabledIcon: Color(0xFFCDD9B3),
|
||||
accent: Color(0xFFA7DC22),
|
||||
secondary: Color(0xFF6E8F1B),
|
||||
shadowColor: Color(0x33647e22),
|
||||
a10p: Color(0x1aa7dc22),
|
||||
a15p: Color(0x26a7dc22),
|
||||
warningAccent: Color(0xFFFFA046),
|
||||
warningText: Color(0xFF8F531B),
|
||||
warning15p: Color(0x26FFA046),
|
||||
warningCard: Color(0xFFFAEBDC),
|
||||
errorAccent: Color(0xFFFF54A1),
|
||||
errorText: Color(0xFF8F1B4F),
|
||||
error15p: Color(0x26FF54A1),
|
||||
errorCard: Color(0xFFFADCE9),
|
||||
),
|
||||
dark: CoreThemeColors(
|
||||
background: Color(0xFF0D1202),
|
||||
backgroundAmoled: Colors.black,
|
||||
background0p: Color(0x00fafff0),
|
||||
success: Color(0xFF92EA3B),
|
||||
shadowBlur: 0,
|
||||
textPrimary: Color(0xFFEAF7CC),
|
||||
textSecondary: Color(0xB3EAF7CC),
|
||||
textTertiary: Color(0x80EAF7CC),
|
||||
textTeritary: Color(0xFF97A474),
|
||||
textPrimaryLight: Color(0xFF394C0A),
|
||||
textSecondaryLight: Color(0xCC394C0A),
|
||||
textTertiaryLight: Color(0x80394C0A),
|
||||
card: Color(0xFF141905),
|
||||
cardTranslucent: Color(0x80141905),
|
||||
buttonSecondaryFill: Color(0xFF20290B),
|
||||
buttonDisabledIcon: Color(0xFF465422),
|
||||
accent: Color(0xFFA7DC22),
|
||||
secondary: Color(0xFFCBEE71),
|
||||
shadowColor: Color(0x26CBEE71),
|
||||
a10p: Color(0x1AA7DC22),
|
||||
a15p: Color(0x26A7DC22),
|
||||
warningAccent: Color(0xFFFFA046),
|
||||
warningText: Color(0xFFF0B37A),
|
||||
warning15p: Color(0x26FFA046),
|
||||
warningCard: Color(0xFF201203),
|
||||
errorAccent: Color(0xFFFF54A1),
|
||||
errorText: Color(0xFFF59EC5),
|
||||
error15p: Color(0x26FF54A1),
|
||||
errorCard: Color(0xFF1E030F),
|
||||
),
|
||||
);
|
||||
|
||||
/// App chrome colors (everything except grade colors)
|
||||
class CoreThemeColors {
|
||||
final Color background;
|
||||
final Color backgroundAmoled;
|
||||
final Color background0p;
|
||||
final Color success;
|
||||
final int shadowBlur;
|
||||
|
||||
final Color textPrimary;
|
||||
final Color textSecondary;
|
||||
final Color textTertiary;
|
||||
final Color? textTeritary;
|
||||
|
||||
final Color textPrimaryLight;
|
||||
final Color textSecondaryLight;
|
||||
final Color textTertiaryLight;
|
||||
|
||||
final Color card;
|
||||
final Color cardTranslucent;
|
||||
|
||||
final Color buttonSecondaryFill;
|
||||
final Color buttonDisabledIcon;
|
||||
|
||||
final Color accent;
|
||||
final Color secondary;
|
||||
final Color shadowColor;
|
||||
final Color a10p;
|
||||
final Color a15p;
|
||||
|
||||
final Color warningAccent;
|
||||
final Color warningText;
|
||||
final Color warning15p;
|
||||
final Color warningCard;
|
||||
|
||||
final Color errorAccent;
|
||||
final Color errorText;
|
||||
final Color error15p;
|
||||
final Color errorCard;
|
||||
|
||||
const CoreThemeColors({
|
||||
required this.background,
|
||||
required this.backgroundAmoled,
|
||||
required this.background0p,
|
||||
required this.success,
|
||||
required this.shadowBlur,
|
||||
required this.textPrimary,
|
||||
required this.textSecondary,
|
||||
required this.textTertiary,
|
||||
this.textTeritary,
|
||||
required this.textPrimaryLight,
|
||||
required this.textSecondaryLight,
|
||||
required this.textTertiaryLight,
|
||||
required this.card,
|
||||
required this.cardTranslucent,
|
||||
required this.buttonSecondaryFill,
|
||||
required this.buttonDisabledIcon,
|
||||
required this.accent,
|
||||
required this.secondary,
|
||||
required this.shadowColor,
|
||||
required this.a10p,
|
||||
required this.a15p,
|
||||
required this.warningAccent,
|
||||
required this.warningText,
|
||||
required this.warning15p,
|
||||
required this.warningCard,
|
||||
required this.errorAccent,
|
||||
required this.errorText,
|
||||
required this.error15p,
|
||||
required this.errorCard,
|
||||
});
|
||||
}
|
||||
|
||||
class CoreTheme {
|
||||
final String id;
|
||||
final CoreThemeColors light;
|
||||
final CoreThemeColors dark;
|
||||
|
||||
const CoreTheme({
|
||||
required this.id,
|
||||
required this.light,
|
||||
required this.dark,
|
||||
});
|
||||
|
||||
CoreThemeColors forBrightness(bool isLight) => isLight ? light : dark;
|
||||
}
|
||||
|
||||
CoreTheme resolveCore(String id) => coreThemes[id] ?? firkaCore;
|
||||
51
firka_common/lib/ui/theme/grade_theme.dart
Normal file
51
firka_common/lib/ui/theme/grade_theme.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
const Map<String, GradeTheme> gradeThemes = {
|
||||
"firka": firkaGrade,
|
||||
};
|
||||
|
||||
const _firkaGradeColors = GradeThemeColors(
|
||||
grade5: Color(0xFF22CCAD),
|
||||
grade4: Color(0xFF92EA3B),
|
||||
grade3: Color(0xFFF9CF00),
|
||||
grade2: Color(0xFFFFA046),
|
||||
grade1: Color(0xFFFF54A1),
|
||||
);
|
||||
|
||||
const firkaGrade = GradeTheme(
|
||||
id: "firka",
|
||||
light: _firkaGradeColors,
|
||||
dark: _firkaGradeColors,
|
||||
);
|
||||
|
||||
class GradeThemeColors {
|
||||
final Color grade5;
|
||||
final Color grade4;
|
||||
final Color grade3;
|
||||
final Color grade2;
|
||||
final Color grade1;
|
||||
|
||||
const GradeThemeColors({
|
||||
required this.grade5,
|
||||
required this.grade4,
|
||||
required this.grade3,
|
||||
required this.grade2,
|
||||
required this.grade1,
|
||||
});
|
||||
}
|
||||
|
||||
class GradeTheme {
|
||||
final String id;
|
||||
final GradeThemeColors light;
|
||||
final GradeThemeColors dark;
|
||||
|
||||
const GradeTheme({
|
||||
required this.id,
|
||||
required this.light,
|
||||
required this.dark,
|
||||
});
|
||||
|
||||
GradeThemeColors forBrightness(bool isLight) => isLight ? light : dark;
|
||||
}
|
||||
|
||||
GradeTheme resolveGrade(String id) => gradeThemes[id] ?? firkaGrade;
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:firka_common/ui/theme/core_theme.dart';
|
||||
import 'package:firka_common/ui/theme/grade_theme.dart';
|
||||
|
||||
// Design system token names; ignore non_constant_identifier_names for consistency with design specs
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
@@ -264,85 +266,71 @@ FirkaFonts buildAppFonts({
|
||||
|
||||
final _defaultFonts = buildAppFonts();
|
||||
|
||||
final FirkaStyle lightStyle = FirkaStyle(
|
||||
FirkaColors mergeColors(CoreThemeColors core, GradeThemeColors grades) {
|
||||
return FirkaColors(
|
||||
background: core.background,
|
||||
backgroundAmoled: core.backgroundAmoled,
|
||||
background0p: core.background0p,
|
||||
success: core.success,
|
||||
shadowBlur: core.shadowBlur,
|
||||
textPrimary: core.textPrimary,
|
||||
textSecondary: core.textSecondary,
|
||||
textTertiary: core.textTertiary,
|
||||
textTeritary: core.textTeritary,
|
||||
textPrimaryLight: core.textPrimaryLight,
|
||||
textSecondaryLight: core.textSecondaryLight,
|
||||
textTertiaryLight: core.textTertiaryLight,
|
||||
card: core.card,
|
||||
cardTranslucent: core.cardTranslucent,
|
||||
buttonSecondaryFill: core.buttonSecondaryFill,
|
||||
buttonDisabledIcon: core.buttonDisabledIcon,
|
||||
accent: core.accent,
|
||||
secondary: core.secondary,
|
||||
shadowColor: core.shadowColor,
|
||||
a10p: core.a10p,
|
||||
a15p: core.a15p,
|
||||
warningAccent: core.warningAccent,
|
||||
warningText: core.warningText,
|
||||
warning15p: core.warning15p,
|
||||
warningCard: core.warningCard,
|
||||
errorAccent: core.errorAccent,
|
||||
errorText: core.errorText,
|
||||
error15p: core.error15p,
|
||||
errorCard: core.errorCard,
|
||||
grade5: grades.grade5,
|
||||
grade4: grades.grade4,
|
||||
grade3: grades.grade3,
|
||||
grade2: grades.grade2,
|
||||
grade1: grades.grade1,
|
||||
);
|
||||
}
|
||||
|
||||
FirkaStyle styleFor({
|
||||
required String coreId,
|
||||
required String gradeId,
|
||||
required bool isLight,
|
||||
required FirkaFonts fonts,
|
||||
}) {
|
||||
final core = resolveCore(coreId).forBrightness(isLight);
|
||||
final grades = resolveGrade(gradeId).forBrightness(isLight);
|
||||
return FirkaStyle(
|
||||
isLight: isLight,
|
||||
colors: mergeColors(core, grades),
|
||||
fonts: fonts,
|
||||
);
|
||||
}
|
||||
|
||||
FirkaStyle get lightStyle => styleFor(
|
||||
coreId: "firka",
|
||||
gradeId: "firka",
|
||||
isLight: true,
|
||||
colors: FirkaColors(
|
||||
background: Color(0xFFFAFFF0),
|
||||
backgroundAmoled: Colors.black,
|
||||
background0p: Color(0x00fafff0),
|
||||
success: Color(0xFF92EA3B),
|
||||
shadowBlur: 2,
|
||||
textPrimary: Color(0xFF394C0A),
|
||||
textSecondary: Color(0xCC394C0A),
|
||||
textTertiary: Color(0x80394C0A),
|
||||
textTeritary: Color(0xFF97A474),
|
||||
textPrimaryLight: Color(0xFF394C0A),
|
||||
textSecondaryLight: Color(0xCC394C0A),
|
||||
textTertiaryLight: Color(0x80394C0A),
|
||||
card: Color(0xFFF3FBDE),
|
||||
cardTranslucent: Color(0x80F3FBDE),
|
||||
buttonSecondaryFill: Color(0xFFFEFFFD),
|
||||
buttonDisabledIcon: Color(0xFFCDD9B3),
|
||||
accent: Color(0xFFA7DC22),
|
||||
secondary: Color(0xFF6E8F1B),
|
||||
shadowColor: Color(0x33647e22),
|
||||
a10p: Color(0x1aa7dc22),
|
||||
a15p: Color(0x26a7dc22),
|
||||
warningAccent: Color(0xFFFFA046),
|
||||
warningText: Color(0xFF8F531B),
|
||||
warning15p: Color(0x26FFA046),
|
||||
warningCard: Color(0xFFFAEBDC),
|
||||
errorAccent: Color(0xFFFF54A1),
|
||||
errorText: Color(0xFF8F1B4F),
|
||||
error15p: Color(0x26FF54A1),
|
||||
errorCard: Color(0xFFFADCE9),
|
||||
grade5: Color(0xFF22CCAD),
|
||||
grade4: Color(0xFF92EA3B),
|
||||
grade3: Color(0xFFF9CF00),
|
||||
grade2: Color(0xFFFFA046),
|
||||
grade1: Color(0xFFFF54A1),
|
||||
),
|
||||
fonts: _defaultFonts,
|
||||
);
|
||||
|
||||
final FirkaStyle darkStyle = FirkaStyle(
|
||||
FirkaStyle get darkStyle => styleFor(
|
||||
coreId: "firka",
|
||||
gradeId: "firka",
|
||||
isLight: false,
|
||||
colors: FirkaColors(
|
||||
background: Color(0xFF0D1202),
|
||||
backgroundAmoled: Colors.black,
|
||||
background0p: Color(0x00fafff0),
|
||||
success: Color(0xFF92EA3B),
|
||||
shadowBlur: 0,
|
||||
textPrimary: Color(0xFFEAF7CC),
|
||||
textSecondary: Color(0xB3EAF7CC),
|
||||
textTertiary: Color(0x80EAF7CC),
|
||||
textTeritary: Color(0xFF97A474),
|
||||
textPrimaryLight: Color(0xFF394C0A),
|
||||
textSecondaryLight: Color(0xCC394C0A),
|
||||
textTertiaryLight: Color(0x80394C0A),
|
||||
card: Color(0xFF141905),
|
||||
cardTranslucent: Color(0x80141905),
|
||||
buttonSecondaryFill: Color(0xFF20290B),
|
||||
buttonDisabledIcon: Color(0xFF465422),
|
||||
accent: Color(0xFFA7DC22),
|
||||
secondary: Color(0xFFCBEE71),
|
||||
shadowColor: Color(0x26CBEE71),
|
||||
a10p: Color(0x1AA7DC22),
|
||||
a15p: Color(0x26A7DC22),
|
||||
warningAccent: Color(0xFFFFA046),
|
||||
warningText: Color(0xFFF0B37A),
|
||||
warning15p: Color(0x26FFA046),
|
||||
warningCard: Color(0xFF201203),
|
||||
errorAccent: Color(0xFFFF54A1),
|
||||
errorText: Color(0xFFF59EC5),
|
||||
error15p: Color(0x26FF54A1),
|
||||
errorCard: Color(0xFF1E030F),
|
||||
grade5: Color(0xFF22CCAD),
|
||||
grade4: Color(0xFF92EA3B),
|
||||
grade3: Color(0xFFF9CF00),
|
||||
grade2: Color(0xFFFFA046),
|
||||
grade1: Color(0xFFFF54A1),
|
||||
),
|
||||
fonts: _defaultFonts,
|
||||
);
|
||||
|
||||
|
||||
Submodule firka_wear/lib/l10n updated: 2dd94691b7...f4812ec3b3
Reference in New Issue
Block a user