148 lines
4.8 KiB
Dart
148 lines
4.8 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||
import 'package:maibu_satabot_v2/core/theme/AppTheme.dart';
|
||
import 'package:maibu_satabot_v2/features/v2/my/domain/entities/my_entities.dart';
|
||
|
||
/// 菜单项卡片组件(100% 还原设计稿)
|
||
class MenuItemCard extends StatelessWidget {
|
||
const MenuItemCard({
|
||
super.key,
|
||
required this.item,
|
||
this.onTap,
|
||
this.onSwitchChanged,
|
||
});
|
||
|
||
final MenuItemEntity item;
|
||
final VoidCallback? onTap;
|
||
final ValueChanged<bool>? onSwitchChanged;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Column(
|
||
children: [
|
||
SizedBox(
|
||
height: 56,
|
||
child: GestureDetector(
|
||
onTap: onTap,
|
||
behavior: HitTestBehavior.opaque,
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||
child: Row(
|
||
children: [
|
||
// 图标
|
||
Icon(
|
||
_getIconData(item.icon),
|
||
size: 20,
|
||
color: context.appColors.textSecondary,
|
||
),
|
||
const SizedBox(width: 12),
|
||
// 标题
|
||
Expanded(
|
||
child: Text(
|
||
_getLocalizedTitle(context, item),
|
||
style: TextStyle(
|
||
fontSize: 15,
|
||
fontWeight: FontWeight.w500,
|
||
color: context.appColors.textPrimary,
|
||
),
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
// 副标题或开关
|
||
if (item.subTitle != null) ...[
|
||
Flexible(
|
||
child: Text(
|
||
item.subTitle!,
|
||
style: TextStyle(
|
||
fontSize: 13,
|
||
color: context.appColors.textTertiary,
|
||
),
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
const SizedBox(width: 6),
|
||
],
|
||
if (item.hasSwitch) ...[
|
||
Transform.scale(
|
||
scale: 0.85,
|
||
child: Switch(
|
||
value: item.switchValue,
|
||
onChanged: onSwitchChanged,
|
||
activeColor: const Color(0xFF165DFF),
|
||
activeTrackColor: const Color(
|
||
0xFF165DFF,
|
||
).withOpacity(0.3),
|
||
inactiveThumbColor: context.appColors.textTertiary,
|
||
inactiveTrackColor: context.appColors.divider,
|
||
),
|
||
),
|
||
],
|
||
Icon(
|
||
Icons.chevron_right,
|
||
color: context.appColors.textTertiary,
|
||
size: 20,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
// 分割线
|
||
Padding(
|
||
padding: const EdgeInsets.only(left: 48),
|
||
child: Divider(
|
||
height: 1,
|
||
thickness: 0.5,
|
||
color: context.appColors.divider,
|
||
),
|
||
),
|
||
],
|
||
);
|
||
}
|
||
|
||
/// 根据字符串获取 IconData
|
||
IconData _getIconData(String iconName) {
|
||
switch (iconName) {
|
||
case 'person':
|
||
return Icons.person_outline;
|
||
case 'notifications':
|
||
return Icons.notifications_outlined;
|
||
case 'cloud_download':
|
||
return Icons.cloud_download_outlined;
|
||
case 'dark_mode':
|
||
return Icons.dark_mode_outlined;
|
||
case 'settings':
|
||
return Icons.settings_outlined;
|
||
case 'help':
|
||
return Icons.help_outline;
|
||
case 'info':
|
||
return Icons.info_outline;
|
||
default:
|
||
return Icons.label_outline;
|
||
}
|
||
}
|
||
|
||
String _getLocalizedTitle(BuildContext context, MenuItemEntity item) {
|
||
switch (item.id) {
|
||
case 'personal_info':
|
||
return AppLocalizations.of(context).translate('my_v2.personal_info');
|
||
case 'message_settings':
|
||
return AppLocalizations.of(context).translate('my_v2.message_settings');
|
||
case 'offline_cache':
|
||
return AppLocalizations.of(context).translate('my_v2.offline_cache');
|
||
case 'night_mode':
|
||
return AppLocalizations.of(context).translate('my_v2.night_mode');
|
||
case 'system_settings':
|
||
return AppLocalizations.of(context).translate('my_v2.system_settings');
|
||
case 'help_feedback':
|
||
return AppLocalizations.of(context).translate('my_v2.help_feedback');
|
||
case 'about_us':
|
||
return AppLocalizations.of(context).translate('my_v2.about_us');
|
||
default:
|
||
return item.title;
|
||
}
|
||
}
|
||
}
|