Files
SDKmuta/lib/theme/app_theme.dart
T
2026-11-27 14:37:44 +01:00

428 lines
17 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../services/app_settings.dart';
/// Colour tokens of the V2 design (shooting-app-design/v2/gen_design.py).
///
/// The bullet colour the user picks (Nastavitve → Videz → Barva zadetkov) is
/// the accent of the whole interface. Real green ([pos]) stays only for
/// meaning: improvements, unlocked. Gold is the colour of a 10 everywhere.
class Palette {
final bool isDark;
final Color bg; // page
final Color card; // cards, sheets
final Color card2; // raised card inside a sheet
final Color field; // text fields
final Color tile; // buttons, chips, segmented selection
final Color line; // borders and dividers
final Color line2; // faint dividers inside cards
final Color ink; // main text
final Color ink2; // body text
final Color muted; // secondary text
final Color faint; // disabled
final Color pos; // improvement / unlocked
final Color posSoft;
final Color gold; // a 10
final Color goldSoft;
final Color goldInk;
final Color red;
final Color redSoft;
final Color amberSoft;
final Color amberInk;
final Color blue; // duty
final Color purple; // meeting
final Color nav; // bottom navigation
final Color accent; // the bullet colour
final List<BoxShadow> shadow; // cards (light only)
final List<BoxShadow> shadowLg; // dialogs
const Palette._({
required this.isDark,
required this.bg,
required this.card,
required this.card2,
required this.field,
required this.tile,
required this.line,
required this.line2,
required this.ink,
required this.ink2,
required this.muted,
required this.faint,
required this.pos,
required this.posSoft,
required this.gold,
required this.goldSoft,
required this.goldInk,
required this.red,
required this.redSoft,
required this.amberSoft,
required this.amberInk,
required this.blue,
required this.purple,
required this.nav,
required this.accent,
required this.shadow,
required this.shadowLg,
});
factory Palette.dark(Color accent) => Palette._(
isDark: true,
bg: const Color(0xFF0E1012),
card: const Color(0xFF171A1D),
card2: const Color(0xFF1E2226),
field: const Color(0xFF1B1F22),
tile: const Color(0xFF23282C),
line: const Color(0xFF2A2F34),
line2: const Color(0xFF22272B),
ink: const Color(0xFFF2F3F0),
ink2: const Color(0xFFC6CBD0),
muted: const Color(0xFF8A9198),
faint: const Color(0xFF5B636A),
pos: const Color(0xFF34CF8E),
posSoft: const Color(0x1F34CF8E),
gold: const Color(0xFFF2C12E),
goldSoft: const Color(0x26F2C12E),
goldInk: const Color(0xFFF6D366),
red: const Color(0xFFF2706A),
redSoft: const Color(0x1FF2706A),
amberSoft: const Color(0x1FF5B33B),
amberInk: const Color(0xFFF7C66A),
blue: const Color(0xFF6EA8FF),
purple: const Color(0xFFB28CFF),
nav: const Color(0xFF121417),
accent: accent,
shadow: const [],
shadowLg: const [BoxShadow(color: Color(0x66000000), offset: Offset(0, 16), blurRadius: 40)],
);
factory Palette.light(Color accent) => Palette._(
isDark: false,
bg: const Color(0xFFF4F4F0),
card: const Color(0xFFFFFFFF),
card2: const Color(0xFFFAFAF7),
field: const Color(0xFFF7F7F4),
tile: const Color(0xFFEFF0EB),
line: const Color(0xFFE3E4DE),
line2: const Color(0xFFECEDE8),
ink: const Color(0xFF16181B),
ink2: const Color(0xFF3B4046),
muted: const Color(0xFF6F757C),
faint: const Color(0xFFA3A8AD),
pos: const Color(0xFF12855C),
posSoft: const Color(0xFFE2F2EA),
gold: const Color(0xFFF2C12E),
goldSoft: const Color(0xFFFDF3CF),
goldInk: const Color(0xFF7A5A00),
red: const Color(0xFFD0443E),
redSoft: const Color(0xFFFBEBEA),
amberSoft: const Color(0xFFFFF3DC),
amberInk: const Color(0xFF8A5A00),
blue: const Color(0xFF2D6BD8),
purple: const Color(0xFF7A4FD0),
nav: const Color(0xFFFFFFFF),
accent: accent,
shadow: const [
BoxShadow(color: Color(0x0A1A1D1F), offset: Offset(0, 1), blurRadius: 2),
BoxShadow(color: Color(0x0D1A1D1F), offset: Offset(0, 8), blurRadius: 24),
],
shadowLg: const [BoxShadow(color: Color(0x241A1D1F), offset: Offset(0, 18), blurRadius: 40)],
);
/// The palette for the current theme and bullet colour.
static Palette get current => AppSettings.instance.palette;
/// Accent with low alpha: selected chips, icon badges.
Color get accentSoft => accent.withValues(alpha: isDark ? 0.13 : 0.12);
/// Accent as text on [card]: lighter on dark, deeper on light.
Color get accentInk =>
isDark ? Color.lerp(accent, Colors.white, 0.45)! : Color.lerp(accent, Colors.black, 0.32)!;
/// Text and icons on an accent fill.
Color get onAccent => onColor(accent);
/// Readable text colour on [fill].
static Color onColor(Color fill) =>
fill.computeLuminance() > 0.36 ? const Color(0xFF0B0D0F) : Colors.white;
/// Up = green, down = red.
Color delta(double v) => v >= 0 ? pos : red;
}
/// Spacing, radii and text styles of the design, plus the ThemeData.
class AppTheme {
AppTheme._();
static const String font = 'Inter';
static const String mono = 'JetBrains Mono';
static const double edge = 20; // page edge
static const double radius = 16; // cards
static const List<FontFeature> tnum = [FontFeature.tabularFigures()];
/// Uppercase label above a group: "POVPREČJE NA STREL".
static TextStyle kicker(Palette c) =>
TextStyle(fontSize: 11, fontWeight: FontWeight.w700, letterSpacing: 1.1, color: c.muted);
static ThemeData theme(Palette c) {
final base = ThemeData(
useMaterial3: true,
brightness: c.isDark ? Brightness.dark : Brightness.light,
fontFamily: font,
);
final scheme = ColorScheme(
brightness: c.isDark ? Brightness.dark : Brightness.light,
primary: c.accent,
onPrimary: c.onAccent,
secondary: c.accent,
onSecondary: c.onAccent,
error: c.red,
onError: Colors.white,
surface: c.card,
onSurface: c.ink,
onSurfaceVariant: c.muted,
outline: c.line,
outlineVariant: c.line2,
surfaceContainerHighest: c.tile,
surfaceContainerHigh: c.card2,
surfaceContainer: c.card,
surfaceContainerLow: c.card,
surfaceContainerLowest: c.bg,
);
return base.copyWith(
colorScheme: scheme,
// Pages are see-through: every route is drawn on the app background
// (see _BackgroundTransitions), the everyday one or a holiday's
scaffoldBackgroundColor: Colors.transparent,
canvasColor: c.bg,
dividerColor: c.line,
splashFactory: InkSparkle.splashFactory,
textTheme: base.textTheme.apply(bodyColor: c.ink, displayColor: c.ink, fontFamily: font),
iconTheme: IconThemeData(color: c.ink),
dividerTheme: DividerThemeData(color: c.line2, thickness: 1, space: 1),
appBarTheme: AppBarTheme(
backgroundColor: c.bg,
foregroundColor: c.ink,
elevation: 0,
scrolledUnderElevation: 0,
titleTextStyle: TextStyle(fontFamily: font, fontSize: 17, fontWeight: FontWeight.w700, color: c.ink),
systemOverlayStyle: overlay(c),
),
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: c.card,
modalBackgroundColor: c.card,
surfaceTintColor: Colors.transparent,
showDragHandle: true,
dragHandleColor: c.line,
dragHandleSize: const Size(40, 4),
modalBarrierColor: Colors.black.withValues(alpha: c.isDark ? 0.55 : 0.35),
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(24))),
),
dialogTheme: DialogThemeData(
backgroundColor: c.card,
surfaceTintColor: Colors.transparent,
barrierColor: Colors.black.withValues(alpha: c.isDark ? 0.6 : 0.35),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
side: c.isDark ? BorderSide(color: c.line) : BorderSide.none,
),
titleTextStyle: TextStyle(fontFamily: font, color: c.ink, fontSize: 20, fontWeight: FontWeight.w700),
contentTextStyle: TextStyle(fontFamily: font, color: c.muted, fontSize: 14, height: 1.35),
),
switchTheme: SwitchThemeData(
thumbColor: WidgetStateProperty.resolveWith(
(s) => s.contains(WidgetState.selected) ? (c.isDark ? const Color(0xFF0B0D0F) : Colors.white) : c.muted),
trackColor: WidgetStateProperty.resolveWith((s) => s.contains(WidgetState.selected) ? c.accent : c.tile),
trackOutlineColor: WidgetStateProperty.resolveWith(
(s) => s.contains(WidgetState.selected) ? c.accent : (c.isDark ? c.tile : c.line)),
thumbIcon: const WidgetStatePropertyAll(null),
),
sliderTheme: SliderThemeData(
activeTrackColor: c.accent,
inactiveTrackColor: c.tile,
thumbColor: c.accent,
overlayColor: c.accent.withValues(alpha: 0.16),
trackHeight: 4,
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 8),
),
checkboxTheme: CheckboxThemeData(
fillColor: WidgetStateProperty.resolveWith((s) => s.contains(WidgetState.selected) ? c.accent : Colors.transparent),
checkColor: WidgetStatePropertyAll(c.onAccent),
side: BorderSide(color: c.faint, width: 1.5),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
),
progressIndicatorTheme: ProgressIndicatorThemeData(color: c.accent, circularTrackColor: c.tile, linearTrackColor: c.tile),
textSelectionTheme: TextSelectionThemeData(
cursorColor: c.accent,
selectionColor: c.accent.withValues(alpha: 0.3),
selectionHandleColor: c.accent,
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: c.field,
hintStyle: TextStyle(color: c.faint),
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 14),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: c.line)),
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: c.line)),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide(color: c.accent, width: 2)),
),
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
backgroundColor: c.isDark ? c.tile : c.ink,
contentTextStyle: TextStyle(fontFamily: font, color: c.isDark ? c.ink : Colors.white, fontSize: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: c.ink,
textStyle: const TextStyle(fontFamily: font, fontSize: 15, fontWeight: FontWeight.w600),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
),
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(
backgroundColor: c.accent,
foregroundColor: c.onAccent,
minimumSize: const Size(0, 48),
textStyle: const TextStyle(fontFamily: font, fontSize: 15, fontWeight: FontWeight.w600),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
),
datePickerTheme: DatePickerThemeData(
backgroundColor: c.card,
surfaceTintColor: Colors.transparent,
headerBackgroundColor: c.card,
headerForegroundColor: c.ink,
rangeSelectionBackgroundColor: c.accent.withValues(alpha: 0.18),
rangePickerBackgroundColor: c.bg,
rangePickerHeaderBackgroundColor: c.bg,
rangePickerHeaderForegroundColor: c.ink,
dayForegroundColor: WidgetStateProperty.resolveWith((s) => s.contains(WidgetState.selected) ? c.onAccent : c.ink),
dayBackgroundColor: WidgetStateProperty.resolveWith((s) => s.contains(WidgetState.selected) ? c.accent : null),
todayForegroundColor: WidgetStatePropertyAll(c.accent),
todayBorder: BorderSide(color: c.accent),
),
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.android: _BackgroundTransitions(FadeForwardsPageTransitionsBuilder(backgroundColor: c.bg)),
TargetPlatform.iOS: const _BackgroundTransitions(ZoomPageTransitionsBuilder()),
TargetPlatform.linux: const _BackgroundTransitions(ZoomPageTransitionsBuilder()),
}),
);
}
/// Status and navigation bar for [c]: transparent status bar, nav bar in the nav colour.
static SystemUiOverlayStyle overlay(Palette c) => SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: c.isDark ? Brightness.light : Brightness.dark,
statusBarBrightness: c.isDark ? Brightness.dark : Brightness.light,
systemNavigationBarColor: c.nav,
systemNavigationBarIconBrightness: c.isDark ? Brightness.light : Brightness.dark,
systemNavigationBarContrastEnforced: false,
);
}
/// The screen background of the design (holiday-themes/v2, "ozadje"): the
/// everyday one in dark or light, or the current holiday's.
class AppBackground extends StatelessWidget {
final Widget child;
const AppBackground({super.key, required this.child});
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: AppSettings.instance,
builder: (context, child) {
final s = AppSettings.instance;
return Stack(
fit: StackFit.expand,
children: [
ColoredBox(color: s.palette.bg),
// Holidays have their drawn backgrounds; the everyday one is
// painted here, cleaner than the design's busier image
if (s.holiday != null)
Image.asset(s.background, fit: BoxFit.cover, gaplessPlayback: true, filterQuality: FilterQuality.medium)
else
CustomPaint(painter: _EverydayBackground(dark: s.isDark)),
child!,
],
);
},
child: child,
);
}
}
/// [inner]'s transitions, with every page drawn on [AppBackground], so a page
/// stays opaque while it slides and fades.
class _BackgroundTransitions extends PageTransitionsBuilder {
final PageTransitionsBuilder inner;
const _BackgroundTransitions(this.inner);
@override
Duration get transitionDuration => inner.transitionDuration;
@override
Duration get reverseTransitionDuration => inner.reverseTransitionDuration;
@override
DelegatedTransitionBuilder? get delegatedTransition => inner.delegatedTransition;
@override
Widget buildTransitions<T>(PageRoute<T> route, BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) =>
inner.buildTransitions(route, context, animation, secondaryAnimation, AppBackground(child: child));
}
/// The everyday background ("00 Privzeto", holiday-themes/v2) in a calmer
/// version: the same gradient and two corners of target rings, but three
/// widely spaced, faint rings per corner and a few fine dots.
class _EverydayBackground extends CustomPainter {
final bool dark;
const _EverydayBackground({required this.dark});
@override
void paint(Canvas canvas, Size size) {
final rect = Offset.zero & size;
canvas.drawRect(
rect,
Paint()
..shader = LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: dark ? const [Color(0xFF15191C), Color(0xFF0B0D0F)] : const [Color(0xFFFAFAF7), Color(0xFFECEDE7)],
).createShader(rect),
);
// Design units: a 390 × 844 screen
final k = size.width / 390;
final ink = dark ? Colors.white : const Color(0xFF16181B);
final ring = Paint()
..style = PaintingStyle.stroke
..isAntiAlias = true;
void rings(Offset c, List<double> radii) {
for (int i = 0; i < radii.length; i++) {
ring
..strokeWidth = (i == radii.length - 1 ? 1.6 : 1.1) * k
..color = ink.withValues(alpha: dark ? (i == radii.length - 1 ? 0.09 : 0.06) : (i == radii.length - 1 ? 0.08 : 0.05));
canvas.drawCircle(c, radii[i] * k, ring);
}
}
rings(Offset(size.width + 40 * k, -30 * k), const [150, 260, 380]);
rings(Offset(-60 * k, size.height + 40 * k), const [140, 250]);
// A few fine dots, always in the same places
final dot = Paint()..color = ink.withValues(alpha: dark ? 0.16 : 0.12);
const spots = [
(0.12, 0.08), (0.78, 0.18), (0.34, 0.31), (0.88, 0.44), (0.07, 0.52),
(0.62, 0.61), (0.25, 0.74), (0.91, 0.83), (0.48, 0.92), (0.70, 0.36),
];
for (int i = 0; i < spots.length; i++) {
final (x, y) = spots[i];
canvas.drawCircle(Offset(x * size.width, y * size.height), (i.isEven ? 1.4 : 1.0) * k, dot);
}
}
@override
bool shouldRepaint(_EverydayBackground old) => old.dark != dark;
}