Files
Developer f91be94e9c refactor: 完成项目架构重构,统一模块导入路径
- 清理大量废弃的 barrel 导出文件,移除冗余的中间导出层
- 修复所有相对路径导入错误,统一调整为扁平化模块引用
- 更新多平台 pubspec 版本号与依赖库版本
- 补充后端功能问题管理后台与脚本工具
- 调整部分页面的快捷方式文案适配新功能
- 更新部分翻译覆盖率与API文档
2026-06-12 08:53:57 +08:00

153 lines
3.8 KiB
Dart

// ============================================================
// 闲言APP — 勋章图标组件
// 创建时间: 2026-05-14
// 更新时间: 2026-05-14
// 作用: 勋章图标展示,支持稀有度边框/锁定状态
// 上次更新: 初始创建
// ============================================================
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart' show Theme;
import '../../../../../core/theme/app_theme.dart';
// ============================================================
// 稀有度颜色映射
// ============================================================
class BadgeRarityColors {
BadgeRarityColors._();
static const Map<String, int> _colorValues = {
'common': 0xFF8B8B8B,
'rare': 0xFF5B9BD5,
'epic': 0xFF9B59B6,
'legendary': 0xFFF39C12,
};
static Color getColor(String rarity) {
final value = _colorValues[rarity] ?? _colorValues['common']!;
return Color(value);
}
static String getLabel(String rarity) {
return switch (rarity) {
'common' => '普通',
'rare' => '稀有',
'epic' => '史诗',
'legendary' => '传说',
_ => '普通',
};
}
static String getEmoji(String rarity) {
return switch (rarity) {
'common' => '',
'rare' => '🔵',
'epic' => '🟣',
'legendary' => '🟡',
_ => '',
};
}
}
// ============================================================
// BadgeIcon 组件
// ============================================================
class BadgeIcon extends StatelessWidget {
const BadgeIcon({
super.key,
required this.icon,
required this.rarity,
this.size = 48.0,
this.isUnlocked = true,
this.showBorder = true,
});
final String icon;
final String rarity;
final double size;
final bool isUnlocked;
final bool showBorder;
@override
Widget build(BuildContext context) {
final rarityColor = BadgeRarityColors.getColor(rarity);
final ext = Theme.of(context).extension<AppThemeExtension>()!;
if (!isUnlocked) {
return _buildLocked(ext);
}
return _buildUnlocked(rarityColor, ext);
}
/// 已解锁状态
Widget _buildUnlocked(Color rarityColor, AppThemeExtension ext) {
final iconSize = size * 0.5;
return Container(
width: size,
height: size,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
rarityColor.withValues(alpha: 0.15),
rarityColor.withValues(alpha: 0.05),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
border: showBorder
? Border.all(
color: rarityColor.withValues(alpha: 0.6),
width: 2.5,
)
: null,
boxShadow: [
BoxShadow(
color: rarityColor.withValues(alpha: 0.2),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Center(
child: Text(
icon,
style: TextStyle(fontSize: iconSize),
textAlign: TextAlign.center,
),
),
);
}
/// 未解锁状态
Widget _buildLocked(AppThemeExtension ext) {
final iconSize = size * 0.35;
return Container(
width: size,
height: size,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: ext.bgSecondary.withValues(alpha: 0.5),
border: showBorder
? Border.all(
color: ext.textHint.withValues(alpha: 0.3),
width: 1.5,
)
: null,
),
child: Center(
child: Text(
'🔒',
style: TextStyle(fontSize: iconSize),
textAlign: TextAlign.center,
),
),
);
}
}