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:
@@ -0,0 +1,139 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../ui/theme/app_font.dart';
|
||||
import '../../ui/theme/app_font_controller.dart';
|
||||
import 'settings_group.dart';
|
||||
import 'settings_row.dart';
|
||||
import 'settings_theme.dart';
|
||||
|
||||
const fontSectionTitle = 'Font';
|
||||
const fontSectionFooter =
|
||||
'Saved on this device only. Code keeps its monospace font.';
|
||||
const fontLoadingText = 'Loading…';
|
||||
const fontLoadFailedText = 'Could not load this font.';
|
||||
const fontSaveFailedText = 'Not saved on this device; it applies until reload.';
|
||||
|
||||
ValueKey<String> settingsFontKey(AppFont font) =>
|
||||
ValueKey<String>('settings-font-${font.id}');
|
||||
|
||||
/// The device's interface font: one row per option, each named in its own
|
||||
/// face. Material rows are radio tiles, Cupertino rows carry the checkmark.
|
||||
/// A choice is stored locally and applies as soon as its files load.
|
||||
class SettingsFontSection extends StatefulWidget {
|
||||
const SettingsFontSection({super.key, required this.controller});
|
||||
|
||||
final AppFontController controller;
|
||||
|
||||
@override
|
||||
State<SettingsFontSection> createState() => _SettingsFontSectionState();
|
||||
}
|
||||
|
||||
class _SettingsFontSectionState extends State<SettingsFontSection> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_preview();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SettingsFontSection oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.controller != widget.controller) _preview();
|
||||
}
|
||||
|
||||
/// Only the regular weight of each option, only once Settings is shown.
|
||||
void _preview() {
|
||||
for (final font in AppFont.values) {
|
||||
unawaited(widget.controller.preview(font));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListenableBuilder(
|
||||
listenable: widget.controller,
|
||||
builder: (context, _) => _group(context),
|
||||
);
|
||||
|
||||
Widget _group(BuildContext context) {
|
||||
final controller = widget.controller;
|
||||
final cupertino = usesCupertinoControls(context);
|
||||
final group = SettingsGroup(
|
||||
title: fontSectionTitle,
|
||||
footer: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
const Text(fontSectionFooter),
|
||||
if (controller.saveFailed)
|
||||
Text(
|
||||
fontSaveFailedText,
|
||||
style: TextStyle(color: settingsErrorColor(context)),
|
||||
),
|
||||
],
|
||||
),
|
||||
children: <Widget>[
|
||||
for (final font in AppFont.values)
|
||||
cupertino
|
||||
? _cupertinoRow(context, font)
|
||||
: RadioListTile<AppFont>(
|
||||
key: settingsFontKey(font),
|
||||
value: font,
|
||||
title: _name(context, font),
|
||||
subtitle: _status(context, font),
|
||||
),
|
||||
],
|
||||
);
|
||||
if (cupertino) return group;
|
||||
return RadioGroup<AppFont>(
|
||||
groupValue: controller.selected,
|
||||
onChanged: (font) {
|
||||
if (font != null) unawaited(controller.select(font));
|
||||
},
|
||||
child: group,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoRow(BuildContext context, AppFont font) => SettingsRow(
|
||||
key: settingsFontKey(font),
|
||||
title: _name(context, font),
|
||||
subtitle: _status(context, font),
|
||||
trailing: widget.controller.selected == font
|
||||
? Icon(
|
||||
CupertinoIcons.check_mark,
|
||||
color: CupertinoTheme.of(context).primaryColor,
|
||||
)
|
||||
: null,
|
||||
onTap: () => unawaited(widget.controller.select(font)),
|
||||
);
|
||||
|
||||
/// The option's name in its own face once its regular weight has loaded;
|
||||
/// the system face until then (and always for the system option).
|
||||
Widget _name(BuildContext context, AppFont font) {
|
||||
final family = widget.controller.canPreview(font)
|
||||
? font.family ?? _systemFamily(context)
|
||||
: _systemFamily(context);
|
||||
return Text(font.label, style: TextStyle(fontFamily: family));
|
||||
}
|
||||
|
||||
Widget? _status(BuildContext context, AppFont font) {
|
||||
final controller = widget.controller;
|
||||
if (controller.selected != font) return null;
|
||||
if (controller.loadFailed == font) {
|
||||
return Text(
|
||||
fontLoadFailedText,
|
||||
style: TextStyle(color: settingsErrorColor(context)),
|
||||
);
|
||||
}
|
||||
return controller.loading ? const Text(fontLoadingText) : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// The platform's own interface family (Roboto, or the Cupertino system
|
||||
/// face), independent of the font the theme currently applies.
|
||||
String? _systemFamily(BuildContext context) => usesCupertinoControls(context)
|
||||
? const CupertinoTextThemeData().textStyle.fontFamily
|
||||
: Typography.material2021(
|
||||
platform: Theme.of(context).platform,
|
||||
).black.bodyLarge?.fontFamily;
|
||||
@@ -10,6 +10,8 @@ import '../attention/notify/notification_controller.dart';
|
||||
import 'default_endpoint.dart';
|
||||
import 'settings_controller.dart';
|
||||
import 'settings_controls.dart';
|
||||
import 'settings_font_section.dart';
|
||||
import '../../ui/theme/app_font_controller.dart';
|
||||
import 'settings_group.dart';
|
||||
import 'settings_page_body.dart';
|
||||
import 'settings_notifications_section.dart';
|
||||
@@ -53,8 +55,12 @@ class SettingsScreen extends StatefulWidget {
|
||||
this.servers,
|
||||
this.deliveryService,
|
||||
this.deliveryServiceController,
|
||||
this.fonts,
|
||||
});
|
||||
|
||||
/// The device's interface font; defaults to the app's shared controller.
|
||||
final AppFontController? fonts;
|
||||
|
||||
/// Android background delivery; hidden when absent or unsupported.
|
||||
final NotificationServiceBridge? deliveryService;
|
||||
final NotificationServiceController? deliveryServiceController;
|
||||
@@ -190,6 +196,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
controller: _controller,
|
||||
workspaceField: _workspaceField,
|
||||
),
|
||||
// A device-local choice: a browser and a phone keep their own.
|
||||
SettingsFontSection(
|
||||
controller: widget.fonts ?? AppFontController.instance,
|
||||
),
|
||||
if (widget.notifications case final notifications?)
|
||||
SettingsNotificationsSection(controller: notifications),
|
||||
if (widget.deliveryService case final service? when service.supported)
|
||||
|
||||
Reference in New Issue
Block a user