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 shadow; // cards (light only) final List 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 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, in dark or light: the current holiday's /// (holiday-themes/v3) for the whole app, otherwise the everyday "00 Privzeto". /// [target]: the target screens' background instead, the picked target's own /// (target-backgrounds/v2) unless a holiday is on; those screens wrap /// themselves in it, over the page's everyday one. /// The target's window on a target screen: the band the target backgrounds /// (target-backgrounds/v3, drawn for a 390 × 844 screen and shown with /// BoxFit.cover, see [AppBackground]) leave for it, between the line under /// the header and the line over the tiles and buttons. Put it in a [Stack] /// that fills the screen; the page's other parts go above and below it. class TargetWindow extends StatelessWidget { final Widget child; const TargetWindow({super.key, required this.child}); static const double _bgWidth = 390, _bgHeight = 844; static const double _top = 186.5, _bottom = 659; /// Where the two lines are on a screen of [size]: (y of the upper, y of the lower). static (double, double) lines(Size size) { final k = size.width / _bgWidth > size.height / _bgHeight ? size.width / _bgWidth : size.height / _bgHeight; final dy = (size.height - _bgHeight * k) / 2; return (dy + _top * k, dy + _bottom * k); } @override Widget build(BuildContext context) { return Positioned.fill( child: LayoutBuilder(builder: (context, box) { final (top, bottom) = lines(box.biggest); return Stack(children: [ Positioned(left: 0, right: 0, top: top, height: bottom - top, child: child), ]); }), ); } } class AppBackground extends StatelessWidget { final Widget child; final bool target; const AppBackground({super.key, required this.child, this.target = false}); @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), Image.asset(target ? s.targetBackground : s.background, fit: BoxFit.cover, gaplessPlayback: true, filterQuality: FilterQuality.medium), 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(PageRoute route, BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) => inner.buildTransitions(route, context, animation, secondaryAnimation, AppBackground(child: child)); }