Files
pipelines/app/lib/ui/theme/app_theme.dart
T
alan 2853b18b9e Settings: per-device interface font choice
System default plus Inter, IBM Plex Sans, Source Sans 3 and Atkinson
Hyperlegible Next (OFL 1.1, bundled as on-demand assets and loaded with
FontLoader, so the web fetches only the previewed/chosen files). Stored in
shared_preferences, applied live to Material and Cupertino text themes;
RobotoMono styles unchanged. Licences registered with LicenseRegistry.
2026-11-04 02:01:49 +00:00

163 lines
5.6 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// The app's backgrounds. Dark mode uses a near-black gray rather than pure
/// black, so cards, sections and bars read as layers above the page.
abstract final class AppColors {
/// A page.
static const background = CupertinoDynamicColor.withBrightness(
color: Color(0xFFFFFFFF),
darkColor: Color(0xFF141416),
);
/// Behind grouped sections (Settings-style lists).
static const groupedBackground = CupertinoDynamicColor.withBrightness(
color: Color(0xFFF2F2F7),
darkColor: Color(0xFF141416),
);
/// Bars over the page.
static const bar = CupertinoDynamicColor.withBrightness(
color: Color(0xF0F9F9F9),
darkColor: Color(0xF01C1C1F),
);
}
const _seed = Color(0xFF6750A4);
/// [fontFamily] replaces the platform family throughout the text themes
/// (Material's, and Cupertino's for Cupertino widgets on a Material host),
/// keeping every size, weight and the text scaling; null keeps the system
/// typography.
ThemeData appLightTheme({String? fontFamily}) {
final scheme = ColorScheme.fromSeed(seedColor: _seed);
return ThemeData(
platform: kIsWeb ? TargetPlatform.android : null,
colorScheme: scheme,
pageTransitionsTheme: appPageTransitions,
fontFamily: fontFamily,
cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme),
);
}
/// Android and iOS keep their native transitions and interactive back gestures.
/// Desktop hosts use the short horizontal slide.
const appPageTransitions = PageTransitionsTheme(
builders: {
TargetPlatform.android: PredictiveBackPageTransitionsBuilder(),
TargetPlatform.fuchsia: FastSlidePageTransitionsBuilder(),
TargetPlatform.linux: FastSlidePageTransitionsBuilder(),
TargetPlatform.windows: FastSlidePageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
},
);
/// A 200 ms horizontal slide with no fade: only the page moves, so nothing
/// has to be redrawn into an offscreen layer.
class FastSlidePageTransitionsBuilder extends PageTransitionsBuilder {
const FastSlidePageTransitionsBuilder();
@override
Duration get transitionDuration => const Duration(milliseconds: 200);
@override
Duration get reverseTransitionDuration => const Duration(milliseconds: 180);
@override
Widget buildTransitions<T>(
PageRoute<T> route,
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) {
final curved = CurvedAnimation(
parent: animation,
curve: Curves.easeOutCubic,
reverseCurve: Curves.easeInCubic,
);
return SlideTransition(
position: Tween<Offset>(
begin: const Offset(1, 0),
end: Offset.zero,
).animate(curved),
child: child,
);
}
}
/// Material's dark scheme with gray surfaces stepping up from the page.
ThemeData appDarkTheme({String? fontFamily}) {
final scheme =
ColorScheme.fromSeed(
seedColor: _seed,
brightness: Brightness.dark,
).copyWith(
surface: const Color(0xFF141416),
surfaceDim: const Color(0xFF141416),
surfaceBright: const Color(0xFF3A3B40),
surfaceContainerLowest: const Color(0xFF0F0F11),
surfaceContainerLow: const Color(0xFF1B1C1F),
surfaceContainer: const Color(0xFF202125),
surfaceContainerHigh: const Color(0xFF27282C),
surfaceContainerHighest: const Color(0xFF303136),
);
return ThemeData(
platform: kIsWeb ? TargetPlatform.android : null,
colorScheme: scheme,
scaffoldBackgroundColor: scheme.surface,
pageTransitionsTheme: appPageTransitions,
fontFamily: fontFamily,
cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme),
);
}
const appCupertinoTheme = CupertinoThemeData(
scaffoldBackgroundColor: AppColors.background,
barBackgroundColor: AppColors.bar,
);
/// [appCupertinoTheme] with every Cupertino text role in [fontFamily]; null
/// keeps the system typography.
CupertinoThemeData appCupertinoThemeWith({String? fontFamily}) =>
fontFamily == null
? appCupertinoTheme
: appCupertinoTheme.copyWith(textTheme: appCupertinoTextTheme(fontFamily));
/// The stock Cupertino text roles (sizes, weights, colours) in [fontFamily].
/// Action roles take [primaryColor], as the stock roles do.
CupertinoTextThemeData appCupertinoTextTheme(
String fontFamily, {
Color primaryColor = CupertinoColors.systemBlue,
}) {
final base = CupertinoTextThemeData(primaryColor: primaryColor);
TextStyle face(TextStyle style) => style.copyWith(fontFamily: fontFamily);
return CupertinoTextThemeData(
textStyle: face(base.textStyle),
actionTextStyle: face(base.actionTextStyle),
actionSmallTextStyle: face(base.actionSmallTextStyle),
tabLabelTextStyle: face(base.tabLabelTextStyle),
navTitleTextStyle: face(base.navTitleTextStyle),
navLargeTitleTextStyle: face(base.navLargeTitleTextStyle),
navActionTextStyle: face(base.navActionTextStyle),
pickerTextStyle: face(base.pickerTextStyle),
dateTimePickerTextStyle: face(base.dateTimePickerTextStyle),
);
}
/// Cupertino widgets on a Material host derive their theme from Material's;
/// only the family is overridden, with Material's primary for actions.
NoDefaultCupertinoThemeData? _cupertinoOverride(
String? fontFamily,
ColorScheme scheme,
) => fontFamily == null
? null
: CupertinoThemeData(
textTheme: appCupertinoTextTheme(
fontFamily,
primaryColor: scheme.primary,
),
);