feat(缓存): 添加本地缓存功能并优化网络状态提示
实现本地缓存管理器,支持预加载开关和排行榜数据缓存 优化网络状态提示文案和错误处理 移除调试日志打印,改进用户体验
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../constants/app_constants.dart';
|
||||
import './widgets.dart';
|
||||
import '../../home/home-load.dart';
|
||||
import '../../../controllers/load/locally.dart';
|
||||
|
||||
/// 时间: 2026-03-26
|
||||
/// 功能: 功能设置页面
|
||||
@@ -22,6 +23,7 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
bool _soundEnabled = true;
|
||||
bool _vibrationEnabled = true;
|
||||
bool _darkModeEnabled = false;
|
||||
bool _preloadEnabled = true;
|
||||
bool _notificationEnabled = true;
|
||||
int _cacheSize = 128;
|
||||
|
||||
@@ -40,6 +42,7 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
setState(() {
|
||||
_autoRefreshEnabled = prefs.getBool(_autoRefreshKey) ?? false;
|
||||
_debugInfoEnabled = prefs.getBool(_debugInfoKey) ?? false;
|
||||
_preloadEnabled = prefs.getBool('preload_enabled') ?? true;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -66,6 +69,15 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _setPreload(bool value) async {
|
||||
await LocalCacheManager().setPreloadEnabled(value);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_preloadEnabled = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -106,11 +118,12 @@ class _AppFunSettingsPageState extends State<AppFunSettingsPage> {
|
||||
),
|
||||
_buildSwitchItem(
|
||||
'预加载',
|
||||
'开启后优先使用本地缓存,\n减少与服务器的通信次数',
|
||||
//关闭后,优先使用云端数据,无延迟,但刷新缓慢
|
||||
Icons.notifications_active,
|
||||
_notificationEnabled,
|
||||
(value) => setState(() => _notificationEnabled = value),
|
||||
_preloadEnabled
|
||||
? '开启后 部分数据优先使用本地缓存,减少与服务器的通信次数'
|
||||
: '关闭后,优先使用云端数据,无延迟,但刷新缓慢',
|
||||
Icons.storage,
|
||||
_preloadEnabled,
|
||||
_setPreload,
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
@@ -445,7 +445,7 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(width: 16),
|
||||
Text('正在获取服务器信息...'),
|
||||
Text('正在检测网络状态...'),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user