feat: 卡片式服务器列表 + 壁纸切换闪屏修复

- 新增 ServerCard 卡片组件:三层信息结构、在线呼吸状态点、指标胶囊、
  编辑/删除收进 PopupMenu,窄屏 ellipsis 防溢出
- 列表状态轮询改为渐进式刷新:仅首次探测显示 loading,之后静默替换,
  消除每 5 秒整片跳动的现象
- 背景改为双层交叉淡入:旧图层常驻,新图层 precache 后淡入,
  淡入结束才释放旧 VideoPlayerController
- 修复 WallpaperProvider 在 app.dart 与 main.dart 中存在两个实例、
  hasWallpaper 不同步导致 AppBar 跳色的问题
- 启动时由 main() 预加载结果直接写入 BackgroundWidget.spec,首帧即带壁纸
- 换壁纸时清理旧文件,避免应用目录无限增长
- 新增 test/server_card_test.dart
This commit is contained in:
DriftinBlock committed 2026-10-17 19:43:24 +08:00
1 parent 2dc484154d
commit 67ba7d2c83
8 files changed
+1115 -299

No files matched your search

+27 -10
View File
@@ -9,7 +9,7 @@ import '../../core/theme/app_theme.dart';
import '../../core/utils/update_service.dart';
import '../../core/utils/background_service.dart';
import '../../providers/theme_provider.dart';
import '../../app.dart';
import '../../providers/wallpaper_provider.dart';
class SettingsPage extends StatefulWidget {
const SettingsPage({super.key});
@@ -125,7 +125,9 @@ class _SettingsPageState extends State<SettingsPage> {
final path = await _saveFileToAssets(result.path, 'image');
if (path == null) return;
await BackgroundService.setBackground('image', path);
if (!mounted) return;
// 通过 Provider 落盘并通知,背景层随之交叉淡入
await context.read<WallpaperProvider>().setCustomWallpaper(path, type: 'image');
_refreshUI();
}
@@ -139,7 +141,8 @@ class _SettingsPageState extends State<SettingsPage> {
final path = await _saveFileToAssets(filePath, 'video');
if (path == null) return;
await BackgroundService.setBackground('video', path);
if (!mounted) return;
await context.read<WallpaperProvider>().setCustomWallpaper(path, type: 'video');
_refreshUI();
}
@@ -153,6 +156,9 @@ class _SettingsPageState extends State<SettingsPage> {
final file = File(sourcePath);
await file.copy(destPath);
// 换壁纸时清掉上一份(图片与视频都清),否则应用目录会无限膨胀
await _cleanupOldBackgrounds(dir.path, keep: destPath);
return destPath;
} catch (e) {
print('保存失败: $e');
@@ -165,14 +171,30 @@ class _SettingsPageState extends State<SettingsPage> {
}
}
/// 删除应用目录下除 [keep] 之外的旧壁纸文件。
Future<void> _cleanupOldBackgrounds(String dirPath, {required String keep}) async {
try {
final dir = Directory(dirPath);
if (!dir.existsSync()) return;
await for (final entity in dir.list()) {
if (entity is! File) continue;
final name = entity.path.split(Platform.pathSeparator).last;
if (!name.startsWith('background_')) continue;
if (entity.path == keep) continue;
await entity.delete();
}
} catch (_) {
// 清理失败不影响主流程
}
}
Future<void> _clearBackground() async {
await BackgroundService.clearBackground();
await context.read<WallpaperProvider>().resetWallpaper();
_refreshUI();
}
void _refreshUI() {
_loadCurrentBg();
_refreshBackground();
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
@@ -184,11 +206,6 @@ class _SettingsPageState extends State<SettingsPage> {
}
}
void _refreshBackground() {
final appState = context.findAncestorStateOfType<ZVManagerAppState>();
appState?.refreshBackground();
}
// ==================== build ====================
@override