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:
1 parent
2dc484154d
commit
67ba7d2c83
8 files changed
+1115
-299
No files matched your search
@@ -4,7 +4,6 @@ import 'package:image_picker/image_picker.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'dart:io';
|
||||
import '../../providers/wallpaper_provider.dart';
|
||||
import '../../app.dart';
|
||||
|
||||
class WallpaperSettings extends StatelessWidget {
|
||||
const WallpaperSettings({super.key});
|
||||
@@ -73,9 +72,10 @@ class WallpaperSettings extends StatelessWidget {
|
||||
if (image != null && context.mounted) {
|
||||
final savedPath = await _saveFileToAssets(context, image.path);
|
||||
if (savedPath != null && context.mounted) {
|
||||
// Provider 变更会同步到 BackgroundWidget.spec,
|
||||
// 背景层自己完成交叉淡入,这里不再需要手动刷新
|
||||
await provider.setCustomWallpaper(savedPath);
|
||||
if (context.mounted) {
|
||||
_refreshBackground(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('壁纸已更新'), backgroundColor: Colors.green),
|
||||
);
|
||||
@@ -124,6 +124,9 @@ class WallpaperSettings extends StatelessWidget {
|
||||
final file = File(sourcePath);
|
||||
await file.copy(destPath);
|
||||
|
||||
// 清理旧壁纸,避免每次换图都在应用目录留一份副本
|
||||
await _cleanupOldWallpapers(dir.path, keep: destPath);
|
||||
|
||||
return destPath;
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
@@ -135,9 +138,21 @@ class WallpaperSettings extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
void _refreshBackground(BuildContext context) {
|
||||
final appState = context.findAncestorStateOfType<ZVManagerAppState>();
|
||||
appState?.refreshBackground();
|
||||
/// 删除应用目录下除 [keep] 之外的壁纸文件。
|
||||
Future<void> _cleanupOldWallpapers(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_image_')) continue;
|
||||
if (entity.path == keep) continue;
|
||||
await entity.delete();
|
||||
}
|
||||
} catch (_) {
|
||||
// 清理失败不影响主流程
|
||||
}
|
||||
}
|
||||
|
||||
void _showResetDialog(BuildContext context, WallpaperProvider provider) {
|
||||
@@ -155,7 +170,6 @@ class WallpaperSettings extends StatelessWidget {
|
||||
onPressed: () async {
|
||||
await provider.resetWallpaper();
|
||||
if (context.mounted) {
|
||||
_refreshBackground(context);
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('已恢复默认壁纸'), backgroundColor: Colors.green),
|
||||
|
||||
Reference in new issue
Block a user