2853b18b9e
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.
83 lines
2.5 KiB
Dart
83 lines
2.5 KiB
Dart
/// The interface typefaces a device can choose. [AppFont.system] keeps the
|
|
/// platform's own typography (Roboto on Android and the web, SF on iOS); every
|
|
/// other option is an open-licence (SIL OFL 1.1) family bundled under
|
|
/// `fonts/<directory>/` as plain assets, not under pubspec `fonts:`, so a web
|
|
/// page downloads only the family it actually shows.
|
|
enum AppFont {
|
|
system('system', 'System default', null, null, <String>[]),
|
|
inter('inter', 'Inter', 'Inter', 'inter', <String>[
|
|
'Inter-Regular.ttf',
|
|
'Inter-Medium.ttf',
|
|
'Inter-SemiBold.ttf',
|
|
'Inter-Bold.ttf',
|
|
]),
|
|
ibmPlexSans(
|
|
'ibm-plex-sans',
|
|
'IBM Plex Sans',
|
|
'IBM Plex Sans',
|
|
'ibm-plex-sans',
|
|
<String>[
|
|
'IBMPlexSans-Regular.ttf',
|
|
'IBMPlexSans-Medium.ttf',
|
|
'IBMPlexSans-SemiBold.ttf',
|
|
'IBMPlexSans-Bold.ttf',
|
|
],
|
|
),
|
|
sourceSans3(
|
|
'source-sans-3',
|
|
'Source Sans 3',
|
|
'Source Sans 3',
|
|
'source-sans-3',
|
|
<String>[
|
|
'SourceSans3-Regular.ttf',
|
|
'SourceSans3-Medium.ttf',
|
|
'SourceSans3-Semibold.ttf',
|
|
'SourceSans3-Bold.ttf',
|
|
],
|
|
),
|
|
atkinsonHyperlegible(
|
|
'atkinson-hyperlegible-next',
|
|
'Atkinson Hyperlegible Next',
|
|
'Atkinson Hyperlegible Next',
|
|
'atkinson-hyperlegible-next',
|
|
<String>[
|
|
'AtkinsonHyperlegibleNext-Regular.ttf',
|
|
'AtkinsonHyperlegibleNext-Medium.ttf',
|
|
'AtkinsonHyperlegibleNext-SemiBold.ttf',
|
|
'AtkinsonHyperlegibleNext-Bold.ttf',
|
|
],
|
|
);
|
|
|
|
const AppFont(this.id, this.label, this.family, this._directory, this._files);
|
|
|
|
/// The stored value. Stable across releases; never the display label.
|
|
final String id;
|
|
|
|
/// The picker's name for the option.
|
|
final String label;
|
|
|
|
/// The registered family name; null keeps the platform typography.
|
|
final String? family;
|
|
|
|
final String? _directory;
|
|
final List<String> _files;
|
|
|
|
/// Every weight's asset (400, 500, 600 and 700, in that order).
|
|
List<String> get assets => <String>[
|
|
for (final file in _files) 'fonts/$_directory/$file',
|
|
];
|
|
|
|
/// The regular weight alone: enough to preview the option's name.
|
|
String? get previewAsset => _files.isEmpty ? null : assets.first;
|
|
|
|
/// The licence shipped beside the files.
|
|
String? get licenseAsset =>
|
|
_directory == null ? null : 'fonts/$_directory/OFL.txt';
|
|
|
|
/// The option a stored id names; an unknown or missing id is the default.
|
|
static AppFont fromId(String? id) => AppFont.values.firstWhere(
|
|
(font) => font.id == id,
|
|
orElse: () => AppFont.system,
|
|
);
|
|
}
|