From 098f5764d4b5d39e62d21ff12e4f9893a4a6cf7f Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sun, 1 Sep 2024 10:12:15 +0800 Subject: [PATCH] mod: show text scale subtitle --- lib/pages/about/index.dart | 13 ++++++++----- lib/pages/setting/pages/color_select.dart | 3 +++ lib/pages/setting/pages/font_size_select.dart | 4 ++-- lib/pages/setting/style_setting.dart | 13 ++++++++++++- lib/utils/cache_manage.dart | 15 +++++---------- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/pages/about/index.dart b/lib/pages/about/index.dart index 5ec14333..8627e514 100644 --- a/lib/pages/about/index.dart +++ b/lib/pages/about/index.dart @@ -23,7 +23,6 @@ class AboutPage extends StatefulWidget { class _AboutPageState extends State { final AboutController _aboutController = Get.put(AboutController()); - String cacheSize = ''; @override void initState() { @@ -34,9 +33,7 @@ class _AboutPageState extends State { Future getCacheSize() async { final res = await CacheManage().loadApplicationCache(); - cacheSize = res; - if (!mounted) return; - setState(() => {}); + _aboutController.cacheSize.value = res; } @override @@ -170,7 +167,12 @@ class _AboutPageState extends State { }, leading: const Icon(Icons.delete_outline), title: const Text('清除缓存'), - subtitle: Text('图片及网络缓存 $cacheSize', style: subTitleStyle), + subtitle: Obx( + () => Text( + '图片及网络缓存 ${_aboutController.cacheSize.value}', + style: subTitleStyle, + ), + ), ), ListTile( title: const Text('导入/导出设置'), @@ -303,6 +305,7 @@ class AboutController extends GetxController { RxBool isLoading = true.obs; LatestDataModel? data; RxInt count = 0.obs; + RxString cacheSize = ''.obs; @override void onInit() { diff --git a/lib/pages/setting/pages/color_select.dart b/lib/pages/setting/pages/color_select.dart index 29712730..499875eb 100644 --- a/lib/pages/setting/pages/color_select.dart +++ b/lib/pages/setting/pages/color_select.dart @@ -149,6 +149,7 @@ class ColorSelectController extends GetxController { RxInt type = 0.obs; late final List> colorThemes; RxInt currentColor = 0.obs; + RxDouble currentTextScale = 1.0.obs; @override void onInit() { @@ -159,6 +160,8 @@ class ColorSelectController extends GetxController { type.value = dynamicColor.value ? 0 : 1; currentColor.value = setting.get(SettingBoxKey.customColor, defaultValue: 0); + currentTextScale.value = + setting.get(SettingBoxKey.defaultTextScale, defaultValue: 1.0); super.onInit(); } } diff --git a/lib/pages/setting/pages/font_size_select.dart b/lib/pages/setting/pages/font_size_select.dart index 123208ae..cb52f3ca 100644 --- a/lib/pages/setting/pages/font_size_select.dart +++ b/lib/pages/setting/pages/font_size_select.dart @@ -30,7 +30,7 @@ class _FontSizeSelectPageState extends State { setFontSize() { setting.put(SettingBoxKey.defaultTextScale, currentSize); Get.forceAppUpdate(); - Get.back(); + Get.back(result: currentSize); } @override @@ -67,7 +67,7 @@ class _FontSizeSelectPageState extends State { .colorScheme .primary .withOpacity(0.3))), - color: Theme.of(context).colorScheme.background, + color: Theme.of(context).colorScheme.surface, ), child: Row( children: [ diff --git a/lib/pages/setting/style_setting.dart b/lib/pages/setting/style_setting.dart index 700fc02b..d9f96772 100644 --- a/lib/pages/setting/style_setting.dart +++ b/lib/pages/setting/style_setting.dart @@ -359,9 +359,20 @@ class _StyleSettingState extends State { ), ListTile( dense: false, - onTap: () => Get.toNamed('/fontSizeSetting'), + onTap: () async { + dynamic result = await Get.toNamed('/fontSizeSetting'); + if (result != null) { + colorSelectController.currentTextScale.value = result; + } + }, title: Text('字体大小', style: titleStyle), leading: const Icon(Icons.format_size_outlined), + subtitle: Obx(() => Text( + colorSelectController.currentTextScale.value == 1.0 + ? '默认' + : colorSelectController.currentTextScale.value.toString(), + style: subTitleStyle, + )), ), ListTile( dense: false, diff --git a/lib/utils/cache_manage.dart b/lib/utils/cache_manage.dart index eed2e7af..6be7e6f1 100644 --- a/lib/utils/cache_manage.dart +++ b/lib/utils/cache_manage.dart @@ -77,8 +77,8 @@ class CacheManage { } // 清除缓存 - Future clearCacheAll(BuildContext context) async { - bool cleanStatus = await showDialog( + Future clearCacheAll(BuildContext context) async { + await showDialog( context: context, builder: (context) { return AlertDialog( @@ -99,10 +99,8 @@ class CacheManage { try { // 清除缓存 图片缓存 await clearLibraryCache(); - Timer(const Duration(milliseconds: 500), () { - SmartDialog.dismiss().then((res) { - SmartDialog.showToast('清除成功'); - }); + SmartDialog.dismiss().then((res) { + SmartDialog.showToast('清除成功'); }); } catch (err) { SmartDialog.dismiss(); @@ -114,10 +112,7 @@ class CacheManage { ], ); }, - ).then((res) { - return true; - }); - return cleanStatus; + ); } /// 清除 Documents 目录下的 DioCache.db