0419 0318
更新4
This commit is contained in:
@@ -24,8 +24,11 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
// 筛选
|
||||
String _searchQuery = '';
|
||||
int? _filterLevelType;
|
||||
String? _filterFromVersion;
|
||||
String? _filterGenre;
|
||||
|
||||
// --- 修改点 1: 将单选 String? 改为多选 Set<String> ---
|
||||
Set<String> _filterVersions = {};
|
||||
Set<String> _filterGenres = {};
|
||||
|
||||
double? _selectedMinLevel;
|
||||
double? _selectedMaxLevel;
|
||||
bool _isAdvancedFilterExpanded = false;
|
||||
@@ -99,6 +102,8 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
_allSongs = uniqueSongs.values.toList();
|
||||
_allSongs.sort((a, b) => (b.players ?? 0).compareTo(a.players ?? 0));
|
||||
_displaySongs = List.from(_allSongs);
|
||||
|
||||
// 更新可用选项
|
||||
_availableVersions = songs.map((s) => s.from).where((v) => v.isNotEmpty).toSet();
|
||||
_availableGenres = songs.map((s) => s.genre).where((g) => g.isNotEmpty).toSet();
|
||||
|
||||
@@ -110,7 +115,7 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
}
|
||||
}
|
||||
|
||||
// 加载用户成绩 —— ✅ 修复 1:直接用完整ID存储
|
||||
// 加载用户成绩
|
||||
Future<void> _loadUserScores() async {
|
||||
try {
|
||||
final userProvider = UserProvider.instance;
|
||||
@@ -171,8 +176,12 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
if (!match) return false;
|
||||
}
|
||||
|
||||
if (_filterFromVersion != null && song.from != _filterFromVersion) return false;
|
||||
if (_filterGenre != null && song.genre != _filterGenre) return false;
|
||||
// --- 修改点 2: 多选过滤逻辑 ---
|
||||
// 如果选择了版本,歌曲版本必须在选中集合中
|
||||
if (_filterVersions.isNotEmpty && !_filterVersions.contains(song.from)) return false;
|
||||
|
||||
// 如果选择了流派,歌曲流派必须在选中集合中
|
||||
if (_filterGenres.isNotEmpty && !_filterGenres.contains(song.genre)) return false;
|
||||
|
||||
if (_filterLevelType != null) {
|
||||
bool hasLevel = false;
|
||||
@@ -248,8 +257,8 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
setState(() {
|
||||
_searchQuery = '';
|
||||
_filterLevelType = null;
|
||||
_filterFromVersion = null;
|
||||
_filterGenre = null;
|
||||
_filterVersions.clear(); // 清空集合
|
||||
_filterGenres.clear(); // 清空集合
|
||||
_selectedMinLevel = null;
|
||||
_selectedMaxLevel = null;
|
||||
});
|
||||
@@ -359,6 +368,123 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
);
|
||||
}
|
||||
|
||||
// --- 新增:多选 Chip 构建器 ---
|
||||
Widget _buildMultiSelectChip({
|
||||
required String label,
|
||||
required Set<String> selectedValues,
|
||||
required Set<String> allOptions,
|
||||
required Function(Set<String>) onSelectionChanged,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
_showMultiSelectDialog(
|
||||
context,
|
||||
title: label,
|
||||
allOptions: allOptions.toList()..sort(),
|
||||
selectedValues: selectedValues,
|
||||
onConfirm: (newSelection) {
|
||||
setState(() {
|
||||
onSelectionChanged(newSelection);
|
||||
});
|
||||
_applyFilters();
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey.shade400),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
Flexible(
|
||||
child: Text(
|
||||
selectedValues.isEmpty ? "全部" : "已选 ${selectedValues.length}",
|
||||
style: TextStyle(color: Colors.grey[600], fontSize: 12),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(Icons.arrow_drop_down, color: Colors.grey),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showMultiSelectDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required List<String> allOptions,
|
||||
required Set<String> selectedValues,
|
||||
required Function(Set<String>) onConfirm,
|
||||
}) {
|
||||
// 临时存储选择状态
|
||||
final tempSelection = Set<String>.from(selectedValues);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setDialogState) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: allOptions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final option = allOptions[index];
|
||||
final isSelected = tempSelection.contains(option);
|
||||
return CheckboxListTile(
|
||||
title: Text(option),
|
||||
value: isSelected,
|
||||
onChanged: (bool? value) {
|
||||
setDialogState(() {
|
||||
if (value == true) {
|
||||
tempSelection.add(option);
|
||||
} else {
|
||||
tempSelection.remove(option);
|
||||
}
|
||||
});
|
||||
},
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
dense: true,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setDialogState(() {
|
||||
tempSelection.clear();
|
||||
});
|
||||
},
|
||||
child: const Text("清空"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text("取消"),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
onConfirm(tempSelection);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
child: const Text("确定"),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -460,34 +586,27 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
decoration: BoxDecoration(color: Colors.grey.withAlpha(20), border: Border(top: BorderSide(color: Colors.grey.shade300))),
|
||||
child: Column(
|
||||
children: [
|
||||
// --- 修改点 3: UI 替换为多选 Chip ---
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildDropdown(
|
||||
child: _buildMultiSelectChip(
|
||||
label: "版本",
|
||||
value: _filterFromVersion,
|
||||
items: [
|
||||
const DropdownMenuItem(value: null, child: Text("全部")),
|
||||
..._availableVersions.map((v) => DropdownMenuItem(value: v, child: Text(v))).toList()
|
||||
],
|
||||
onChanged: (v) {
|
||||
setState(() => _filterFromVersion = v);
|
||||
_applyFilters();
|
||||
selectedValues: _filterVersions,
|
||||
allOptions: _availableVersions,
|
||||
onSelectionChanged: (newSet) {
|
||||
_filterVersions = newSet;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildDropdown(
|
||||
child: _buildMultiSelectChip(
|
||||
label: "流派",
|
||||
value: _filterGenre,
|
||||
items: [
|
||||
const DropdownMenuItem(value: null, child: Text("全部")),
|
||||
..._availableGenres.map((g) => DropdownMenuItem(value: g, child: Text(g))).toList()
|
||||
],
|
||||
onChanged: (v) {
|
||||
setState(() => _filterGenre = v);
|
||||
_applyFilters();
|
||||
selectedValues: _filterGenres,
|
||||
allOptions: _availableGenres,
|
||||
onSelectionChanged: (newSet) {
|
||||
_filterGenres = newSet;
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -517,10 +636,12 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String getLeftEllipsisText(String text, int maxLength) {
|
||||
if (text.length <= maxLength) return text;
|
||||
return '...${text.substring(text.length - maxLength + 3)}'; // +3 是因为 "..." 占3个字符
|
||||
}
|
||||
|
||||
Widget _buildDropdown({required String label, required dynamic value, required List<DropdownMenuItem> items, required ValueChanged onChanged}) {
|
||||
return DropdownButtonFormField(
|
||||
value: value,
|
||||
@@ -531,7 +652,13 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
);
|
||||
}
|
||||
|
||||
bool _hasFilters() => _searchQuery.isNotEmpty || _filterLevelType != null || _filterFromVersion != null || _filterGenre != null || _selectedMinLevel != null || _selectedMaxLevel != null;
|
||||
bool _hasFilters() =>
|
||||
_searchQuery.isNotEmpty ||
|
||||
_filterLevelType != null ||
|
||||
_filterVersions.isNotEmpty || // 修改判断逻辑
|
||||
_filterGenres.isNotEmpty || // 修改判断逻辑
|
||||
_selectedMinLevel != null ||
|
||||
_selectedMaxLevel != null;
|
||||
|
||||
Widget _buildBody() {
|
||||
if (_isLoading) return const Center(child: CircularProgressIndicator());
|
||||
@@ -558,33 +685,19 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
if (song.ut != null && _userScoreCache.containsKey(100000 + song.id)) hasScore = true;
|
||||
|
||||
// --- 新增:处理别名逻辑 ---
|
||||
// 1. 获取原始列表
|
||||
List<String> rawAliases = song.albums ?? [];
|
||||
|
||||
// 2. 去重 (保留插入顺序可以使用 LinkedHashSet,或者简单转为 Set 再转 List)
|
||||
// 注意:Set.from 可能会打乱顺序,如果顺序不重要可以直接用。
|
||||
// 如果希望保持原顺序去重:
|
||||
final seen = <String>{};
|
||||
final uniqueAliases = rawAliases.where((alias) => seen.add(alias)).toList();
|
||||
|
||||
// 3. 过滤掉与标题或艺术家完全相同的重复项(可选,为了更整洁)
|
||||
final filteredAliases = uniqueAliases.where((alias) =>
|
||||
alias != song.title &&
|
||||
alias != song.artist
|
||||
).toList();
|
||||
|
||||
// 4. 拼接字符串,如果太长则截断
|
||||
// 我们设定一个最大显示长度或者最大行数,这里采用“尝试放入尽可能多的词,直到超过一定长度”的策略
|
||||
String aliasDisplayText = "";
|
||||
if (filteredAliases.isNotEmpty) {
|
||||
// 尝试加入前 N 个别名,总长度控制在合理范围,例如 60-80 个字符,或者固定个数如 5-8 个
|
||||
// 这里采用固定个数策略,因为每个词长度不一,固定个数更容易预测高度
|
||||
int maxAliasCount = 6;
|
||||
List<String> displayList = filteredAliases.take(maxAliasCount).toList();
|
||||
|
||||
aliasDisplayText = displayList.join(" · ");
|
||||
|
||||
// 如果还有更多未显示的,加上省略提示
|
||||
if (filteredAliases.length > maxAliasCount) {
|
||||
aliasDisplayText += " ...";
|
||||
}
|
||||
@@ -632,12 +745,10 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
// 这一行:id + 左侧标签
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// 标签区域(cn / jp / m2l / long)
|
||||
if (song.cn == true)
|
||||
_buildTag(
|
||||
"CN",
|
||||
@@ -669,8 +780,6 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
// id 文本
|
||||
Text(
|
||||
" ${song.id}",
|
||||
style: const TextStyle(
|
||||
@@ -703,7 +812,6 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// 关键:让内容在垂直方向上尽量分布,或者使用 MainAxisSize.min 配合 Spacer
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
@@ -725,13 +833,12 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
const SizedBox(height: 6),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// 可选:根据剩余宽度动态决定显示多少行,这里简单处理为最多2行
|
||||
return Text(
|
||||
aliasDisplayText,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.grey[500],
|
||||
height: 1.2, // 紧凑行高
|
||||
height: 1.2,
|
||||
),
|
||||
maxLines: 5,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -757,16 +864,11 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
}
|
||||
Widget _buildTag(
|
||||
String text, {
|
||||
// 背景:纯色 或 渐变 二选一
|
||||
Color? backgroundColor,
|
||||
Gradient? gradient,
|
||||
|
||||
// 阴影配置
|
||||
Color? shadowColor,
|
||||
double shadowBlurRadius = 2,
|
||||
Offset shadowOffset = const Offset(0, 1),
|
||||
|
||||
// 可选样式扩展
|
||||
double borderRadius = 2,
|
||||
double fontSize = 8,
|
||||
Color textColor = Colors.white,
|
||||
@@ -775,11 +877,9 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
margin: const EdgeInsets.only(right: 3),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
// 优先使用渐变,没有渐变则使用纯色
|
||||
color: gradient == null ? (backgroundColor ?? Colors.blueAccent) : null,
|
||||
gradient: gradient,
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
// 阴影:只有传入 shadowColor 才显示
|
||||
boxShadow: shadowColor != null
|
||||
? [
|
||||
BoxShadow(
|
||||
@@ -802,8 +902,6 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
}
|
||||
List<Widget> _getDifficultyChipsByType(SongModel song) {
|
||||
final diffs = _getAllDifficultiesWithType(song);
|
||||
|
||||
// 按 type 分组:SD / DX / UT
|
||||
final Map<String, List<dynamic>> typeGroups = {};
|
||||
for (var item in diffs) {
|
||||
final type = item['type'] as String;
|
||||
@@ -811,7 +909,6 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
typeGroups[type]!.add(item);
|
||||
}
|
||||
|
||||
// 固定顺序:SD → DX → UT
|
||||
final order = ['SD', 'DX', 'UT'];
|
||||
List<Widget> rows = [];
|
||||
|
||||
@@ -819,7 +916,6 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
final items = typeGroups[type];
|
||||
if (items == null || items.isEmpty) continue;
|
||||
|
||||
// 每一个类型 = 一行 Wrap
|
||||
final row = Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 4,
|
||||
@@ -837,8 +933,6 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
|
||||
if (isBanquet) {
|
||||
color = Colors.pinkAccent;
|
||||
|
||||
// 多UT按ID显示对应名称
|
||||
if (type == 'UT') {
|
||||
final utTitleMap = song.utTitle as Map?;
|
||||
if (utTitleMap != null && utTitleMap.isNotEmpty) {
|
||||
@@ -882,7 +976,7 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(hasScore ? 0.25 : 0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
@@ -892,7 +986,7 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
isBanquet ? label : "$label ${lvValue.toStringAsFixed(1)}",
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 10,
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@@ -916,4 +1010,4 @@ class _MusicPageState extends State<MusicPage> with SingleTickerProviderStateMix
|
||||
return "https://cdn.godserver.cn/resource/static/mai/cover/$displayId.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user