ver1.00.00

update
This commit is contained in:
spasolreisa
2026-04-21 00:28:41 +08:00
parent b985cd1f9e
commit f5f62c828d
13 changed files with 1496 additions and 175 deletions

View File

@@ -9,6 +9,8 @@ import 'package:share_plus/share_plus.dart';
import 'package:dio/dio.dart';
import 'package:path_provider/path_provider.dart';
import '../../tool/cacheImage.dart';
class ScorePage extends StatefulWidget {
const ScorePage({Key? key}) : super(key: key);
@@ -150,6 +152,7 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
}
Future<void> _loadData({bool isInitialLoad = false}) async {
// 首次加载才显示加载圈
if (isInitialLoad) {
setState(() { _isLoading = true; });
} else {
@@ -158,10 +161,30 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
try {
final userProvider = UserProvider.instance;
final token = userProvider.token;
if (token == null) throw "未登录,请先登录";
// ==============================================
// 【关键优化】等待 UserProvider 真正初始化完成
// 避免刚进页面就判断 token 导致的“太快报错”
// ==============================================
await userProvider.waitInit(); // 你需要在 UserProvider 里加这个方法(我下面会给你代码)
// 现在再获取 token此时状态已经稳定
final token = userProvider.token;
if (token == null || token.isEmpty) {
debugPrint(" 用户未登录,清空用户数据");
// setState(() {
// _userMusicList = [];
// _errorMessage = '';
// });
return; // 温和退出,不弹错误
}
debugPrint("✅ 用户已登录,开始加载数据");
// 只有首次加载 / 数据为空时才拉全量歌曲列表
if (_allSongs.isEmpty || isInitialLoad) {
debugPrint(" 加载全量歌曲列表");
final songs = await SongService.getAllSongs();
_allSongs = songs;
_songMap = {for (var song in songs) song.id: song};
@@ -174,6 +197,7 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
if (segaId == null || segaId.isEmpty) {
throw "请选择一个有效的 Sega ID";
}
debugPrint(" 加载 Sega 评分数据");
final rawData = await UserService.getSegaRatingData(token, segaId);
final segaId2chartlist = rawData['segaId2chartlist'] as Map<String, dynamic>?;
@@ -204,7 +228,8 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
}).toList();
} else {
final scoreData = await SongService.getUserAllScores(token,name: _currentCnUserName);
debugPrint(" 加载用户评分数据");
final scoreData = await SongService.getUserAllScores(token, name: _currentCnUserName);
if (scoreData.containsKey('userScoreAll_')) {
_userMusicList = scoreData['userScoreAll_']['userMusicList'] ?? [];
@@ -216,6 +241,7 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
}
setState(() { _errorMessage = ''; });
debugPrint("✅ 数据加载完成");
} catch (e) {
debugPrint("❌ Load Data Error: $e");
@@ -237,7 +263,6 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
}
}
}
List<dynamic> get _filteredMusicList {
bool isNoFilter = _searchQuery.isEmpty &&
_filterLevelType == null &&
@@ -421,6 +446,16 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
final segaCards = userProvider.availableSegaCards;
final currentSegaId = userProvider.selectedSegaId;
// 安全处理:确保 value 一定存在于 items 中
String? safeValue;
if (isSegaMode) {
// 检查 segaId 是否真的在列表里
safeValue = segaCards.any((card) => card.segaId == currentSegaId) ? currentSegaId : null;
} else {
// 检查用户名是否真的在列表里
safeValue = (currentCnUserName != null && cnUserNames.contains(currentCnUserName)) ? currentCnUserName : null;
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
color: Theme.of(context).cardColor,
@@ -452,9 +487,7 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
flex: 1,
child: DropdownButtonHideUnderline(
child: DropdownButtonFormField<String>(
value: isSegaMode
? currentSegaId
: (currentCnUserName != null && currentCnUserName.isNotEmpty ? currentCnUserName : null),
value: safeValue, // <--- 这里用安全值,修复报错
decoration: InputDecoration(
hintText: isSegaMode ? "选择卡片" : "选择账号",
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
@@ -1110,7 +1143,7 @@ class _ScorePageState extends State<ScorePage> with SingleTickerProviderStateMix
borderRadius: BorderRadius.circular(4),
child: Stack(
children: [
Image.network(
CacheImage.network(
coverUrl,
width: 50,
height: 50,