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.
This commit is contained in:
2026-11-04 02:01:49 +00:00
parent fa6c0864db
commit 2853b18b9e
38 changed files with 1486 additions and 26 deletions
+59 -6
View File
@@ -26,11 +26,20 @@ abstract final class AppColors {
const _seed = Color(0xFF6750A4);
ThemeData appLightTheme() => ThemeData(
platform: kIsWeb ? TargetPlatform.android : null,
colorScheme: ColorScheme.fromSeed(seedColor: _seed),
pageTransitionsTheme: appPageTransitions,
);
/// [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.
@@ -80,7 +89,7 @@ class FastSlidePageTransitionsBuilder extends PageTransitionsBuilder {
}
/// Material's dark scheme with gray surfaces stepping up from the page.
ThemeData appDarkTheme() {
ThemeData appDarkTheme({String? fontFamily}) {
final scheme =
ColorScheme.fromSeed(
seedColor: _seed,
@@ -100,6 +109,8 @@ ThemeData appDarkTheme() {
colorScheme: scheme,
scaffoldBackgroundColor: scheme.surface,
pageTransitionsTheme: appPageTransitions,
fontFamily: fontFamily,
cupertinoOverrideTheme: _cupertinoOverride(fontFamily, scheme),
);
}
@@ -107,3 +118,45 @@ 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,
),
);