Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat: system fonts switch

Prediditc4501fa4a2f7
diff --git a/lib/app_widget.dart b/lib/app_widget.dart
index 3f134d13..35e91bbb 100644
--- a/lib/app_widget.dart
+++ b/lib/app_widget.dart
@@ -231,6 +231,8 @@ class _AppWidgetState extends State<AppWidget>
}
bool oledEnhance =
setting.get(SettingBoxKey.oledEnhance, defaultValue: false);
+ bool useSystemFont =
+ setting.get(SettingBoxKey.useSystemFont, defaultValue: false);
final defaultThemeMode =
setting.get(SettingBoxKey.themeMode, defaultValue: 'system');
if (defaultThemeMode == 'dark') {
@@ -242,9 +244,10 @@ class _AppWidgetState extends State<AppWidget>
if (defaultThemeMode == 'system') {
themeProvider.setThemeMode(ThemeMode.system, notify: false);
}
+ themeProvider.setFontFamily(useSystemFont, notify: false);
var defaultDarkTheme = ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
brightness: Brightness.dark,
colorSchemeSeed: color,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -254,7 +257,7 @@ class _AppWidgetState extends State<AppWidget>
themeProvider.setTheme(
ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
brightness: Brightness.light,
colorSchemeSeed: color,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -269,7 +272,7 @@ class _AppWidgetState extends State<AppWidget>
themeProvider.setTheme(
ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
colorScheme: theme,
brightness: Brightness.light,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -278,7 +281,7 @@ class _AppWidgetState extends State<AppWidget>
oledEnhance
? Utils.oledDarkTheme(ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
colorScheme: darkTheme,
brightness: Brightness.dark,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -286,7 +289,7 @@ class _AppWidgetState extends State<AppWidget>
pageTransitionsTheme: pageTransitionsTheme2024))
: ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
colorScheme: darkTheme,
brightness: Brightness.dark,
progressIndicatorTheme: progressIndicatorTheme2024,
diff --git a/lib/bean/settings/theme_provider.dart b/lib/bean/settings/theme_provider.dart
index 118128ef..70fb8cbc 100644
--- a/lib/bean/settings/theme_provider.dart
+++ b/lib/bean/settings/theme_provider.dart
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
+import 'package:kazumi/utils/constants.dart';
class ThemeProvider extends ChangeNotifier {
ThemeMode themeMode = ThemeMode.system;
bool useDynamicColor = false;
late ThemeData light;
late ThemeData dark;
+ String? currentFontFamily = customAppFontFamily;
void setTheme(ThemeData light, ThemeData dark, {bool notify = true}) {
this.light = light;
@@ -21,4 +23,9 @@ class ThemeProvider extends ChangeNotifier {
this.useDynamicColor = useDynamicColor;
if (notify) notifyListeners();
}
+
+ void setFontFamily(bool useSystemFont, {bool notify = true}) {
+ currentFontFamily = useSystemFont ? null : customAppFontFamily;
+ if (notify) notifyListeners();
+ }
}
diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dart
index 58efa05c..4bd0b686 100644
--- a/lib/pages/player/player_item.dart
+++ b/lib/pages/player/player_item.dart
@@ -1288,7 +1288,7 @@ class _PlayerItemState extends State<PlayerItem>
strokeWidth: _border ? 1.5 : 0.0,
fontWeight: _danmakuFontWeight,
massiveMode: _massiveMode,
- fontFamily: defaultAppFontFamily,
+ fontFamily: customAppFontFamily,
),
),
),
diff --git a/lib/pages/settings/theme_settings_page.dart b/lib/pages/settings/theme_settings_page.dart
index 675bdbf3..a2596465 100644
--- a/lib/pages/settings/theme_settings_page.dart
+++ b/lib/pages/settings/theme_settings_page.dart
@@ -29,6 +29,7 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
late bool oledEnhance;
late bool useDynamicColor;
late bool showWindowButton;
+ late bool useSystemFont;
final PopularController popularController = Modular.get<PopularController>();
late final ThemeProvider themeProvider;
final MenuController menuController = MenuController();
@@ -45,6 +46,8 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
setting.get(SettingBoxKey.useDynamicColor, defaultValue: false);
showWindowButton =
setting.get(SettingBoxKey.showWindowButton, defaultValue: false);
+ useSystemFont =
+ setting.get(SettingBoxKey.useSystemFont, defaultValue: false);
themeProvider = Provider.of<ThemeProvider>(context, listen: false);
}
@@ -58,7 +61,7 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
void setTheme(Color? color) {
var defaultDarkTheme = ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
brightness: Brightness.dark,
colorSchemeSeed: color,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -68,7 +71,7 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
themeProvider.setTheme(
ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
brightness: Brightness.light,
colorSchemeSeed: color,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -83,7 +86,7 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
void resetTheme() {
var defaultDarkTheme = ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
brightness: Brightness.dark,
colorSchemeSeed: Colors.green,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -93,7 +96,7 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
themeProvider.setTheme(
ThemeData(
useMaterial3: true,
- fontFamily: defaultAppFontFamily,
+ fontFamily: themeProvider.currentFontFamily,
brightness: Brightness.light,
colorSchemeSeed: Colors.green,
progressIndicatorTheme: progressIndicatorTheme2024,
@@ -327,6 +330,24 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
title: Text('动态配色', style: TextStyle(fontFamily: fontFamily)),
initialValue: useDynamicColor,
),
+ SettingsTile.switchTile(
+ onToggle: (value) async {
+ useSystemFont = value ?? !useSystemFont;
+ await setting.put(SettingBoxKey.useSystemFont, useSystemFont);
+ themeProvider.setFontFamily(useSystemFont);
+ dynamic color;
+ if (defaultThemeColor == 'default') {
+ color = Colors.green;
+ } else {
+ color = Color(int.parse(defaultThemeColor, radix: 16));
+ }
+ setTheme(color);
+ setState(() {});
+ },
+ title: Text('使用系统字体', style: TextStyle(fontFamily: fontFamily)),
+ description: Text('关闭后使用 MI Sans 字体', style: TextStyle(fontFamily: fontFamily)),
+ initialValue: useSystemFont,
+ ),
],
bottomInfo: Text('动态配色仅支持安卓12及以上和桌面平台', style: TextStyle(fontFamily: fontFamily)),
),
diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart
index 277f32d6..97912cf8 100644
--- a/lib/utils/constants.dart
+++ b/lib/utils/constants.dart
@@ -9,7 +9,7 @@ class StyleString {
static const double aspectRatio = 16 / 10;
}
-String? defaultAppFontFamily = "MI_Sans_Regular";
+const String customAppFontFamily = "MI_Sans_Regular";
/// `year2023` flag is deprecated since 3.29 but not default to false yet. Keep
/// it to false so we have the latest M3 style process indicator.
diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart
index 85ea6bad..b50b8bee 100644
--- a/lib/utils/storage.dart
+++ b/lib/utils/storage.dart
@@ -263,5 +263,6 @@ class SettingBoxKey {
searchNotShowWatchedBangumis = 'searchNotShowWatchedBangumis',
searchNotShowAbandonedBangumis = 'searchNotShowAbandonedBangumis',
timelineNotShowAbandonedBangumis = 'timelineNotShowAbandonedBangumis',
- timelineNotShowWatchedBangumis = 'timelineNotShowWatchedBangumis';
+ timelineNotShowWatchedBangumis = 'timelineNotShowWatchedBangumis',
+ useSystemFont = 'useSystemFont';
}