From 5d0b2dc8e366789f8ece65648a1a1aa62e900813 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Wed, 26 Mar 2025 21:39:58 +0800 Subject: [PATCH] feat: custom app font weight Closes #533 Signed-off-by: bggRGjQaUbCoE --- lib/pages/dynamics/view.dart | 6 ++-- .../member_contribute/member_contribute.dart | 5 ++- lib/pages/search_result/view.dart | 5 ++- lib/pages/setting/widgets/model.dart | 31 +++++++++++++++++ lib/pages/setting/widgets/switch_item.dart | 26 +++++++++++---- lib/pages/video/detail/view.dart | 4 ++- lib/pages/video/detail/view_v.dart | 4 ++- lib/utils/storage.dart | 4 +++ lib/utils/utils.dart | 33 ++++++++++++++++++- 9 files changed, 103 insertions(+), 15 deletions(-) diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index 2709193f..b9bf5f2c 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -154,9 +154,9 @@ class _DynamicsPageState extends State indicatorColor: Theme.of(context).colorScheme.primary, labelColor: Theme.of(context).colorScheme.primary, unselectedLabelColor: Theme.of(context).colorScheme.onSurface, - labelStyle: TextStyle( - fontSize: Theme.of(context).textTheme.labelMedium!.fontSize, - ), + labelStyle: + TabBarTheme.of(context).labelStyle?.copyWith(fontSize: 13) ?? + const TextStyle(fontSize: 13), tabs: DynamicsType.values.map((e) => Tab(text: e.labels)).toList(), onTap: (index) { diff --git a/lib/pages/member/new/content/member_contribute/member_contribute.dart b/lib/pages/member/new/content/member_contribute/member_contribute.dart index 4383f71d..46ca872f 100644 --- a/lib/pages/member/new/content/member_contribute/member_contribute.dart +++ b/lib/pages/member/new/content/member_contribute/member_contribute.dart @@ -66,7 +66,10 @@ class _MemberContributeState extends State borderRadius: BorderRadius.circular(20), ), indicatorSize: TabBarIndicatorSize.tab, - labelStyle: const TextStyle(fontSize: 14), + labelStyle: TabBarTheme.of(context) + .labelStyle + ?.copyWith(fontSize: 14) ?? + const TextStyle(fontSize: 14), labelColor: Theme.of(context).colorScheme.onSecondaryContainer, unselectedLabelColor: Theme.of(context).colorScheme.outline, diff --git a/lib/pages/search_result/view.dart b/lib/pages/search_result/view.dart index 2247c338..e11abd29 100644 --- a/lib/pages/search_result/view.dart +++ b/lib/pages/search_result/view.dart @@ -120,7 +120,10 @@ class _SearchResultPageState extends State ), indicatorSize: TabBarIndicatorSize.tab, labelColor: Theme.of(context).colorScheme.onSecondaryContainer, - labelStyle: const TextStyle(fontSize: 13), + labelStyle: TabBarTheme.of(context) + .labelStyle + ?.copyWith(fontSize: 13) ?? + const TextStyle(fontSize: 13), dividerColor: Colors.transparent, dividerHeight: 0, unselectedLabelColor: Theme.of(context).colorScheme.outline, diff --git a/lib/pages/setting/widgets/model.dart b/lib/pages/setting/widgets/model.dart index 6140e6ee..310643a2 100644 --- a/lib/pages/setting/widgets/model.dart +++ b/lib/pages/setting/widgets/model.dart @@ -146,6 +146,37 @@ List get styleSettings => [ defaultVal: false, needReboot: true, ), + SettingsModel( + settingsType: SettingsType.sw1tch, + title: 'App字体字重', + subtitle: '点击设置', + setKey: SettingBoxKey.appFontWeight, + defaultVal: false, + onTap: () { + showDialog( + context: Get.context!, + builder: (context) { + return SlideDialog( + title: 'App字体字重', + value: GStorage.appFontWeight.toDouble() + 1, + min: 1, + max: FontWeight.values.length.toDouble(), + divisions: FontWeight.values.length - 1, + ); + }, + ).then((res) async { + if (res != null) { + await GStorage.setting + .put(SettingBoxKey.appFontWeight, res.toInt() - 1); + Get.forceAppUpdate(); + } + }); + }, + leading: const Icon(Icons.text_fields), + onChanged: (value) { + Get.forceAppUpdate(); + }, + ), SettingsModel( settingsType: SettingsType.sw1tch, title: 'MD3样式底栏', diff --git a/lib/pages/setting/widgets/switch_item.dart b/lib/pages/setting/widgets/switch_item.dart index f8aa4bb3..4d7c263d 100644 --- a/lib/pages/setting/widgets/switch_item.dart +++ b/lib/pages/setting/widgets/switch_item.dart @@ -36,20 +36,27 @@ class SetSwitchItem extends StatefulWidget { class _SetSwitchItemState extends State { late bool val; - @override - void didUpdateWidget(SetSwitchItem oldWidget) { - super.didUpdateWidget(oldWidget); - if (oldWidget.setKey != widget.setKey) { + void setVal() { + if (widget.setKey == SettingBoxKey.appFontWeight) { + val = GStorage.appFontWeight != -1; + } else { val = GStorage.setting .get(widget.setKey, defaultValue: widget.defaultVal ?? false); } } + @override + void didUpdateWidget(SetSwitchItem oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.setKey != widget.setKey) { + setVal(); + } + } + @override void initState() { super.initState(); - val = GStorage.setting - .get(widget.setKey, defaultValue: widget.defaultVal ?? false); + setVal(); } void switchChange(value) async { @@ -89,7 +96,12 @@ class _SetSwitchItemState extends State { val = value ?? !val; - await GStorage.setting.put(widget.setKey, val); + if (widget.setKey == SettingBoxKey.appFontWeight) { + await GStorage.setting.put(SettingBoxKey.appFontWeight, val ? 4 : -1); + } else { + await GStorage.setting.put(widget.setKey, val); + } + widget.onChanged?.call(val); if (widget.needReboot == true) { SmartDialog.showToast('重启生效'); diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 120d443e..d5e7c544 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -1231,7 +1231,9 @@ class _VideoDetailPageState extends State : null, padding: EdgeInsets.zero, controller: videoDetailController.tabCtr, - labelStyle: const TextStyle(fontSize: 13), + labelStyle: + TabBarTheme.of(context).labelStyle?.copyWith(fontSize: 13) ?? + const TextStyle(fontSize: 13), labelPadding: const EdgeInsets.symmetric(horizontal: 10.0), // 设置每个标签的宽度 dividerColor: Colors.transparent, diff --git a/lib/pages/video/detail/view_v.dart b/lib/pages/video/detail/view_v.dart index baa68147..0c755a37 100644 --- a/lib/pages/video/detail/view_v.dart +++ b/lib/pages/video/detail/view_v.dart @@ -1610,7 +1610,9 @@ class _VideoDetailPageVState extends State : null, padding: EdgeInsets.zero, controller: videoDetailController.tabCtr, - labelStyle: const TextStyle(fontSize: 13), + labelStyle: + TabBarTheme.of(context).labelStyle?.copyWith(fontSize: 13) ?? + const TextStyle(fontSize: 13), labelPadding: const EdgeInsets.symmetric(horizontal: 10.0), // 设置每个标签的宽度 dividerColor: Colors.transparent, diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 5b9c5323..51821ed7 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -436,6 +436,9 @@ class GStorage { GStorage.setting.get(SettingBoxKey.liveQualityCellular, defaultValue: LiveQuality.superHD.code); + static int get appFontWeight => + GStorage.setting.get(SettingBoxKey.appFontWeight, defaultValue: -1); + static List get dynamicDetailRatio => List.from(setting .get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0])); @@ -717,6 +720,7 @@ class SettingBoxKey { retryDelay = 'retryDelay', liveQuality = 'liveQuality', liveQualityCellular = 'liveQualityCellular', + appFontWeight = 'appFontWeight', // Sponsor Block enableSponsorBlock = 'enableSponsorBlock', diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 2eefe980..a90d8adf 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -64,16 +64,46 @@ class Utils { bool isDark = false, required FlexSchemeVariant variant, }) { + final appFontWeight = + GStorage.appFontWeight.clamp(-1, FontWeight.values.length - 1); + final fontWeight = + appFontWeight == -1 ? null : FontWeight.values[appFontWeight]; + late final textStyle = TextStyle(fontWeight: fontWeight); ThemeData themeData = ThemeData( colorScheme: colorScheme, useMaterial3: true, + textTheme: fontWeight == null + ? null + : TextTheme( + displayLarge: textStyle, + displayMedium: textStyle, + displaySmall: textStyle, + headlineLarge: textStyle, + headlineMedium: textStyle, + headlineSmall: textStyle, + titleLarge: textStyle, + titleMedium: textStyle, + titleSmall: textStyle, + bodyLarge: textStyle, + bodyMedium: textStyle, + bodySmall: textStyle, + labelLarge: textStyle, + labelMedium: textStyle, + labelSmall: textStyle, + ), + tabBarTheme: + fontWeight == null ? null : TabBarTheme(labelStyle: textStyle), appBarTheme: AppBarTheme( elevation: 0, titleSpacing: 0, centerTitle: false, scrolledUnderElevation: 0, backgroundColor: isDynamic ? null : colorScheme.surface, - titleTextStyle: TextStyle(fontSize: 16, color: colorScheme.onSurface), + titleTextStyle: TextStyle( + fontSize: 16, + color: colorScheme.onSurface, + fontWeight: fontWeight, + ), ), navigationBarTheme: NavigationBarThemeData( surfaceTintColor: isDynamic ? colorScheme.onSurfaceVariant : null, @@ -114,6 +144,7 @@ class Utils { titleTextStyle: TextStyle( fontSize: 18, color: colorScheme.onSurface, + fontWeight: fontWeight, ), ), );