|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +import '../features/community_collections/models/community_collection_models.dart'; |
| 4 | +import '../features/community_collections/widgets/community_difficulty_badge.dart'; |
| 5 | +import '../l10n/app_localizations.dart'; |
| 6 | +import '../models/audio_item.dart'; |
| 7 | +import '../services/subtitle_parser.dart'; |
| 8 | +import '../theme/app_theme.dart'; |
| 9 | +import '../widgets/audio_info_chip.dart'; |
| 10 | + |
| 11 | +/// 音频详情页:展示单个音频的完整描述、难度与基础元信息。 |
| 12 | +/// |
| 13 | +/// 从学习计划页的进度卡片进入(嵌套子路由 `audio-detail`)。 |
| 14 | +/// 后续会追加关键点等内容,因此按分区组织 ListView。 |
| 15 | +class AudioDetailScreen extends StatelessWidget { |
| 16 | + /// 要展示的音频条目。 |
| 17 | + final AudioItem audioItem; |
| 18 | + |
| 19 | + const AudioDetailScreen({super.key, required this.audioItem}); |
| 20 | + |
| 21 | + @override |
| 22 | + Widget build(BuildContext context) { |
| 23 | + final l10n = AppLocalizations.of(context)!; |
| 24 | + final theme = Theme.of(context); |
| 25 | + final difficulty = CommunityDifficulty.fromCode( |
| 26 | + audioItem.communityDifficulty, |
| 27 | + ); |
| 28 | + final description = audioItem.description?.trim(); |
| 29 | + final metaChips = _buildMetaChips(l10n); |
| 30 | + |
| 31 | + return Scaffold( |
| 32 | + appBar: AppBar(title: Text(l10n.audioDetailTitle)), |
| 33 | + body: ListView( |
| 34 | + padding: const EdgeInsets.all(AppSpacing.l), |
| 35 | + children: [ |
| 36 | + Text( |
| 37 | + audioItem.name, |
| 38 | + style: theme.textTheme.headlineSmall?.copyWith( |
| 39 | + fontWeight: FontWeight.bold, |
| 40 | + ), |
| 41 | + ), |
| 42 | + if (metaChips.isNotEmpty) ...[ |
| 43 | + const SizedBox(height: AppSpacing.s), |
| 44 | + Wrap( |
| 45 | + spacing: AppSpacing.m, |
| 46 | + runSpacing: AppSpacing.xs, |
| 47 | + children: metaChips, |
| 48 | + ), |
| 49 | + ], |
| 50 | + if (difficulty != null) ...[ |
| 51 | + const SizedBox(height: AppSpacing.l), |
| 52 | + Row( |
| 53 | + key: const Key('audio_detail_difficulty'), |
| 54 | + children: [ |
| 55 | + Text( |
| 56 | + l10n.audioDetailDifficulty, |
| 57 | + style: theme.textTheme.titleSmall?.copyWith( |
| 58 | + fontWeight: FontWeight.w600, |
| 59 | + ), |
| 60 | + ), |
| 61 | + const SizedBox(width: AppSpacing.s), |
| 62 | + CommunityDifficultyBadge(difficulty: difficulty), |
| 63 | + ], |
| 64 | + ), |
| 65 | + ], |
| 66 | + const SizedBox(height: AppSpacing.l), |
| 67 | + Text( |
| 68 | + l10n.audioDetailDescription, |
| 69 | + style: theme.textTheme.titleSmall?.copyWith( |
| 70 | + fontWeight: FontWeight.w600, |
| 71 | + ), |
| 72 | + ), |
| 73 | + const SizedBox(height: AppSpacing.s), |
| 74 | + Text( |
| 75 | + description == null || description.isEmpty |
| 76 | + ? l10n.audioDetailNoDescription |
| 77 | + : description, |
| 78 | + key: const Key('audio_detail_description'), |
| 79 | + style: theme.textTheme.bodyLarge?.copyWith( |
| 80 | + color: description == null || description.isEmpty |
| 81 | + ? theme.colorScheme.onSurfaceVariant |
| 82 | + : theme.colorScheme.onSurface, |
| 83 | + ), |
| 84 | + ), |
| 85 | + ], |
| 86 | + ), |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + /// 时长 / 句数 / 词数标签,与学习计划页卡片的图标样式一致;没有数据时返回空列表。 |
| 91 | + List<Widget> _buildMetaChips(AppLocalizations l10n) { |
| 92 | + return [ |
| 93 | + if (audioItem.totalDuration > 0) |
| 94 | + AudioInfoChip( |
| 95 | + icon: Icons.timer_outlined, |
| 96 | + label: SubtitleParser.formatDuration( |
| 97 | + Duration(seconds: audioItem.totalDuration), |
| 98 | + ), |
| 99 | + ), |
| 100 | + if (audioItem.sentenceCount > 0) |
| 101 | + AudioInfoChip( |
| 102 | + icon: Icons.format_list_numbered, |
| 103 | + label: l10n.sentenceCountLabel(audioItem.sentenceCount), |
| 104 | + ), |
| 105 | + if (audioItem.wordCount > 0) |
| 106 | + AudioInfoChip( |
| 107 | + icon: Icons.text_fields, |
| 108 | + label: l10n.wordCountLabel(audioItem.wordCount), |
| 109 | + ), |
| 110 | + ]; |
| 111 | + } |
| 112 | +} |
0 commit comments