feat(app): 多页面动态化 — 搜索/资料/教师/贴纸库/模板/日历

- SearchPage: 热搜词从日记标签频率动态生成 + 模板搜索网格
- ProfilePage: 成就徽章从 AchievementBloc 动态加载 + 头像首字母
- TeacherPage: 班级码改为对话框展示 (班级名+码+人数)
- StickerLibraryPage: 分类从 API 动态合并 + 精选包卡片动态化
- TemplateGalleryPage: 适配动态数据
- ClassPage: 微调
- HomePage: 路由适配
- CalendarBloc: 新增测试
- AppRouter: 路由更新
This commit is contained in:
iven
2026-06-07 10:44:04 +08:00
parent a05374e8d1
commit d67eedf7de
8 changed files with 334 additions and 124 deletions

View File

@@ -19,10 +19,19 @@ class _StickerLibraryPageState extends State<StickerLibraryPage> {
late final StickerBloc _bloc;
final _searchController = TextEditingController();
/// 设计规格中的 8 个分类
static const _specCategories = [
'推荐', '可爱', '植物', '手绘', '校园', '节日', '文字', '和纸胶带',
];
/// 默认分类 — 从 API 数据动态补充
static const _defaultCategories = ['推荐', '可爱', '植物', '手绘', '校园', '节日', '文字', '和纸胶带'];
List<String> get _categories {
final apiCategories = _bloc.state.packs
.map((p) => p.category)
.whereType<String>()
.toSet()
.toList();
if (apiCategories.isEmpty) return _defaultCategories;
// 合并:推荐 + API 返回的分类
return ['推荐', ...apiCategories];
}
@override
void initState() {
@@ -120,7 +129,7 @@ class _StickerLibraryPageState extends State<StickerLibraryPage> {
child: ListView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 16),
children: _specCategories.map((cat) {
children: _categories.map((cat) {
final isSelected = cat == state.selectedCategory ||
(cat == '推荐' && state.selectedCategory == '全部');
return Padding(
@@ -148,13 +157,13 @@ class _StickerLibraryPageState extends State<StickerLibraryPage> {
),
const SizedBox(height: 12),
// ---- 精选贴纸包卡片 ----
if (state.selectedCategory == '全部')
// ---- 精选贴纸包卡片(动态数据) ----
if (state.selectedCategory == '全部' && state.filteredPacks.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: const _FeaturedPackCard(),
child: _FeaturedPackCard(pack: state.filteredPacks.first),
),
if (state.selectedCategory == '全部')
if (state.selectedCategory == '全部' && state.filteredPacks.isNotEmpty)
const SizedBox(height: 16),
// ---- 贴纸包网格 ----
@@ -188,9 +197,10 @@ class _StickerLibraryPageState extends State<StickerLibraryPage> {
}
}
/// 精选贴纸包卡片 — 渐变背景 + 限时免费标签
/// 精选贴纸包卡片 — 渐变背景 + 动态数据
class _FeaturedPackCard extends StatelessWidget {
const _FeaturedPackCard();
const _FeaturedPackCard({required this.pack});
final StickerPack pack;
@override
Widget build(BuildContext context) {
@@ -198,7 +208,7 @@ class _FeaturedPackCard extends StatelessWidget {
return GestureDetector(
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('打开精选贴纸包: 治愈小动物')),
SnackBar(content: Text('打开精选贴纸包: ${pack.name}')),
);
},
child: Container(
@@ -214,7 +224,6 @@ class _FeaturedPackCard extends StatelessWidget {
),
child: Row(
children: [
// emoji 图标区域
Container(
width: 64,
height: 64,
@@ -223,30 +232,38 @@ class _FeaturedPackCard extends StatelessWidget {
borderRadius: AppRadius.mdBorder,
),
alignment: Alignment.center,
child: const Text('🧸', style: TextStyle(fontSize: 36)),
child: Text(pack.displayCover, style: const TextStyle(fontSize: 36)),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('治愈小动物', style: theme.textTheme.titleMedium?.copyWith(
Text(pack.name, style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w700, color: Colors.white,
)),
const SizedBox(height: 4),
Text('超可爱的手绘小动物贴纸', style: theme.textTheme.bodySmall?.copyWith(
color: Colors.white.withValues(alpha: 0.85),
)),
Text(
pack.description ?? '${pack.stickerCount} 张精选贴纸',
style: theme.textTheme.bodySmall?.copyWith(
color: Colors.white.withValues(alpha: 0.85),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: AppColors.secondary,
color: pack.isFree ? AppColors.secondary : AppColors.rose,
borderRadius: AppRadius.pillBorder,
),
child: const Text('限时免费', style: TextStyle(
fontSize: 11, fontWeight: FontWeight.w600, color: Colors.white,
)),
child: Text(
pack.isFree ? '免费' : '精品',
style: const TextStyle(
fontSize: 11, fontWeight: FontWeight.w600, color: Colors.white,
),
),
),
],
),