refactor: 替换硬编码的AppTypography为基于context的动态获取

1. 批量修改所有直接调用AppTypography静态方法的地方,改为使用AppTypography.of(context)获取主题文本样式,适配不同主题上下文
2. 新增channelOrder存储键,支持频道排序持久化
3. 修复笔记删除全部功能未重置total字段的bug
4. 调整build.yaml配置,扩展freezed和json_serializable的生成范围
5. 优化底部弹窗默认样式,使用主题色替代硬编码颜色
6. 调整主题设置中的卡片样式默认文案
This commit is contained in:
Developer
2026-05-24 09:26:55 +08:00
parent 794da27193
commit 09d68cd6aa
265 changed files with 5197 additions and 3981 deletions

View File

@@ -0,0 +1,616 @@
# 闲言APP 架构重构与功能增强 实施计划
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** 解决7大架构问题 + 实现4大功能增强全面提升项目质量
**Architecture:** 分7个阶段执行每阶段独立可交付。优先修复架构问题类型安全、状态管理、路由追踪、主题适配、组件拆分再增强功能下拉手势、空状态、最近面板、标签/精灵/引导页)
**Tech Stack:** Flutter/Dart, freezed + json_serializable, Riverpod, GoRouter, KvStorage
---
## 阶段总览
| 阶段 | 名称 | 预估任务数 | 优先级 |
|------|------|-----------|--------|
| P1 | API类型安全 (freezed + json_serializable) | 8 | ⭐⭐⭐⭐⭐ |
| P2 | 状态管理统一 + 路由追踪合并 | 4 | ⭐⭐⭐⭐⭐ |
| P3 | 主题适配全量修复 | 6 | ⭐⭐⭐⭐ |
| P4 | 组件拆分 | 5 | ⭐⭐⭐ |
| P5 | 下拉手势 + 空状态优化 | 3 | ⭐⭐⭐⭐ |
| P6 | 最近打开面板增强 | 5 | ⭐⭐⭐⭐⭐ |
| P7 | 标签/精灵/引导页增强 | 6 | ⭐⭐⭐ |
---
## P1: API类型安全 (freezed + json_serializable)
### Task P1.1: 为阅读报告模型引入 freezed
**Files:**
- Modify: `lib/features/reading_report/models/reading_report_models.dart`
- Create: (auto-generated .freezed.dart, .g.dart)
- [ ] **Step 1: 添加 freezed 注解到 ReportSummary**
```dart
@freezed
class ReportSummary with _$ReportSummary {
const factory ReportSummary({
required int totalSentences,
required int totalFavorites,
required int totalLikes,
required int streakDays,
required int longestStreak,
required DateTime? lastReadAt,
}) = _ReportSummary;
factory ReportSummary.fromJson(Map<String, dynamic> json) =>
_$ReportSummaryFromJson(json);
}
```
- [ ] **Step 2: 添加 freezed 注解到 ReportTrend / HeatmapDay 等模型**
- [ ] **Step 3: 运行 build_runner 生成代码**
Run: `dart run build_runner build --delete-conflicting-outputs`
- [ ] **Step 4: 更新 reading_report_service.dart 使用生成的 fromJson**
- [ ] **Step 5: 运行 flutter analyze 验证**
### Task P1.2: 为排行榜模型引入 freezed
**Files:**
- Modify: `lib/features/rank/providers/rank_provider.dart` (将 RankSeason/RankItem 移到独立模型文件)
- Create: `lib/features/rank/models/rank_models.dart`
- [ ] **Step 1: 创建 rank_models.dart用 freezed 定义 RankSeason 和 RankItem**
- [ ] **Step 2: 运行 build_runner 生成代码**
- [ ] **Step 3: 更新 rank_provider.dart 使用新模型**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P1.3: 为用户中心模型引入 freezed
**Files:**
- Modify: `lib/features/mine/user_center/models/user_center_models.dart`
- Modify: `lib/features/mine/user_center/models/account_insight_model.dart`
- [ ] **Step 1: 为 DashboardData / UserStats / AccountInsight 等添加 freezed 注解**
- [ ] **Step 2: 运行 build_runner 生成代码**
- [ ] **Step 3: 更新 service/provider 使用新模型**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P1.4: 为 Feed 模型引入 freezed
**Files:**
- Modify: `lib/features/home/models/feed_model.dart`
- Modify: `lib/features/home/providers/home_sentence_model.dart`
- [ ] **Step 1: 为 FeedItem / SentenceData 等添加 freezed 注解**
- [ ] **Step 2: 运行 build_runner 生成代码**
- [ ] **Step 3: 更新 service/provider 使用新模型**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P1.5: 为学习计划模型引入 freezed
**Files:**
- Modify: `lib/features/study_plan/models/study_plan_models.dart`
- [ ] **Step 1: 为 StudyPlan / ReadingGoal 等添加 freezed 注解**
- [ ] **Step 2: 运行 build_runner 生成代码**
- [ ] **Step 3: 更新 service/provider 使用新模型**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P1.6: 为工具中心模型引入 freezed
**Files:**
- Modify: `lib/features/tool_center/inspiration/models/tool_item.dart`
- [ ] **Step 1: 为 ToolItem 添加 freezed 注解**
- [ ] **Step 2: 运行 build_runner 生成代码**
- [ ] **Step 3: 更新 service/provider 使用新模型**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P1.7: 为发现页模型引入 freezed
**Files:**
- Modify: `lib/features/discover/services/discover_service.dart` (内联模型提取)
- Create: `lib/features/discover/models/discover_models.dart`
- [ ] **Step 1: 提取内联模型到 discover_models.dart添加 freezed 注解**
- [ ] **Step 2: 运行 build_runner 生成代码**
- [ ] **Step 3: 更新 service/provider 使用新模型**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P1.8: 全量 build_runner + 验证
- [ ] **Step 1: 运行全量 build_runner**
Run: `dart run build_runner build --delete-conflicting-outputs`
- [ ] **Step 2: 运行 flutter analyze 验证零 error**
- [ ] **Step 3: 提交 P1 阶段代码**
---
## P2: 状态管理统一 + 路由追踪合并
### Task P2.1: 创建统一的最近路由 Provider
**Files:**
- Create: `lib/core/services/navigation/recent_route_service.dart`
- Modify: `lib/core/router/app_nav_extension.dart`
- Modify: `lib/features/home/providers/tool_center_recent_provider.dart`
- [ ] **Step 1: 创建 RecentRouteService — 单一数据源**
```dart
class RecentRouteService {
static const _kRecentRoutes = 'tool_center_recent_routes';
static const _kCustomRoute = 'tool_center_custom_route';
static const _maxRecentCount = 10;
static List<String> getRecentRoutes() { ... }
static Future<void> addRecentRoute(String route) { ... }
static String? getCustomRoute() { ... }
static Future<void> setCustomRoute(String route) { ... }
}
```
- [ ] **Step 2: 更新 app_nav_extension.dart — 调用 RecentRouteService 而非直接写 KvStorage**
- [ ] **Step 3: 更新 tool_center_recent_provider.dart — 从 RecentRouteService 读取**
- [ ] **Step 4: 删除 app_nav_extension.dart 中的 _recordRecentRoute 和 KvStorage 直接操作**
- [ ] **Step 5: 运行 flutter analyze 验证**
### Task P2.2: Provider 缓存同步机制
**Files:**
- Modify: `lib/features/home/providers/tool_center_recent_provider.dart`
- [ ] **Step 1: 在 ToolCenterRecentNotifier 中添加 refreshFromStorage 方法**
- [ ] **Step 2: 在面板打开时调用 ref.invalidate(toolCenterRecentProvider) 确保最新数据**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P2.3: 删除冗余的 KvStorage 直接操作
**Files:**
- Modify: `lib/features/home/providers/tool_center_recent_provider.dart`
- [ ] **Step 1: 将 provider 内部的 KvStorage 操作全部迁移到 RecentRouteService**
- [ ] **Step 2: 运行 flutter analyze 验证**
### Task P2.4: 提交 P2 阶段代码
- [ ] **Step 1: 运行 flutter analyze 验证零 error**
- [ ] **Step 2: 更新 CHANGELOG.md**
---
## P3: 主题适配全量修复
### Task P3.1: 扩展 AppThemeExtension — 新增缺失的语义色
**Files:**
- Modify: `lib/core/theme/app_theme.dart`
- Modify: `lib/core/theme/app_colors.dart`
- [ ] **Step 1: 在 AppThemeExtension 新增属性**
```dart
final Color iconTintBlue; // 0xFF007AFF
final Color iconTintPurple; // 0xFF5856D6
final Color iconTintViolet; // 0xFFAF52DE
final Color iconTintCyan; // 0xFF5AC8FA
final Color iconTintMint; // 0xFF30D158
final Color iconTintYellow; // 0xFFFFCC00
final Color iconTintGrey; // 0xFF8E8E93
```
- [ ] **Step 2: 在 light/dark 主题中定义这些颜色值**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P3.2: 修复高优先级硬编码色 — CupertinoColors.systemBackground + label
**Files:**
- Modify: ~29 个文件 (16处 systemBackground + 23处 label)
- [ ] **Step 1: 批量替换 CupertinoColors.systemBackground → ext.bgPrimary**
- [ ] **Step 2: 批量替换 CupertinoColors.label → ext.textPrimary**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P3.3: 修复高优先级硬编码色 — CupertinoColors.white 在按钮文字上
**Files:**
- Modify: ~80 个文件
- [ ] **Step 1: 在强调色按钮/图标上的 CupertinoColors.white → ext.textOnAccent**
- [ ] **Step 2: 在深色背景上的 CupertinoColors.white → ext.textInverse**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P3.4: 修复中优先级硬编码色 — Colors.black 遮罩
**Files:**
- Modify: ~39 个文件
- [ ] **Step 1: Colors.black.withValues(alpha: 0.04-0.1) → ext.overlaySubtle**
- [ ] **Step 2: Colors.black.withValues(alpha: 0.1-0.4) / Colors.black54 → ext.overlayMedium**
- [ ] **Step 3: Colors.black.withValues(alpha: 0.4+) / Colors.black87 → ext.overlayStrong**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P3.5: 修复中优先级硬编码色 — Color(0xFF...) 十六进制色
**Files:**
- Modify: ~100 个文件
- [ ] **Step 1: Color(0xFF007AFF) → ext.accent / ext.infoColor**
- [ ] **Step 2: Color(0xFFFF3B30) → ext.errorColor / ext.destructiveColor**
- [ ] **Step 3: Color(0xFF34C759) → ext.successColor**
- [ ] **Step 4: Color(0xFFFF9500) → ext.warningColor**
- [ ] **Step 5: Color(0xFF6C63FF) → ext.accent**
- [ ] **Step 6: Color(0xFF8E8E93) → ext.iconSecondary**
- [ ] **Step 7: 其他十六进制色 → 对应 ext.xxx 属性**
- [ ] **Step 8: 运行 flutter analyze 验证**
### Task P3.6: 提交 P3 阶段代码
- [ ] **Step 1: 全量 flutter analyze**
- [ ] **Step 2: 更新 CHANGELOG.md**
---
## P4: 组件拆分
### Task P4.1: 拆分 home_daily_card.dart (841行)
**Files:**
- Create: `lib/features/home/presentation/widgets/daily_card_swiper.dart`
- Create: `lib/features/home/presentation/widgets/daily_card_actions.dart`
- Create: `lib/features/home/presentation/widgets/daily_card_loading.dart`
- Modify: `lib/features/home/presentation/home_daily_card.dart`
- [ ] **Step 1: 提取 _buildLoadingCard → daily_card_loading.dart**
- [ ] **Step 2: 提取操作按钮行 → daily_card_actions.dart**
- [ ] **Step 3: 提取 CardSwiper 配置 → daily_card_swiper.dart**
- [ ] **Step 4: 主文件调用拆分后的组件**
- [ ] **Step 5: 运行 flutter analyze 验证**
### Task P4.2: 拆分 appbar_character_sprite.dart (1430行)
**Files:**
- Create: `lib/shared/widgets/animation/sprite_painters/sprite_head_painter.dart`
- Create: `lib/shared/widgets/animation/sprite_painters/sprite_body_painter.dart`
- Create: `lib/shared/widgets/animation/sprite_painters/sprite_eyes_painter.dart`
- Create: `lib/shared/widgets/animation/sprite_painters/sprite_accessories_painter.dart`
- Create: `lib/shared/widgets/animation/sprite_animation_controller.dart`
- Modify: `lib/shared/widgets/animation/appbar_character_sprite.dart`
- [ ] **Step 1: 提取动画控制器逻辑 → sprite_animation_controller.dart**
- [ ] **Step 2: 拆分 _AppBarCharacterPainter 的绘制方法到各子 painter**
- [ ] **Step 3: 主文件组合各子组件**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P4.3: 拆分 learning_center_page.dart (1680行)
**Files:**
- Create: `lib/features/mine/user_center/presentation/widgets/dashboard_section.dart`
- Create: `lib/features/mine/user_center/presentation/widgets/daily_recommend_section.dart`
- Create: `lib/features/mine/user_center/presentation/widgets/learning_overview_section.dart`
- Modify: `lib/features/mine/user_center/presentation/learning_center_page.dart`
- [ ] **Step 1: 提取仪表盘区域 → dashboard_section.dart**
- [ ] **Step 2: 提取每日推荐区域 → daily_recommend_section.dart**
- [ ] **Step 3: 提取学习概览区域 → learning_overview_section.dart**
- [ ] **Step 4: 主文件组合各区域组件**
- [ ] **Step 5: 运行 flutter analyze 验证**
### Task P4.4: 拆分 home_page.dart (1153行)
**Files:**
- Create: `lib/features/home/presentation/widgets/home_appbar_section.dart`
- Create: `lib/features/home/presentation/widgets/home_feed_section.dart`
- Modify: `lib/features/home/presentation/home_page.dart`
- [ ] **Step 1: 提取 AppBar 区域 → home_appbar_section.dart**
- [ ] **Step 2: 提取 Feed 列表区域 → home_feed_section.dart**
- [ ] **Step 3: 主文件组合各区域**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P4.5: 提交 P4 阶段代码
- [ ] **Step 1: 全量 flutter analyze**
- [ ] **Step 2: 更新 CHANGELOG.md**
---
## P5: 下拉手势 + 空状态优化
### Task P5.1: 简化下拉手势为一段式
**Files:**
- Modify: `lib/features/home/presentation/home_refresh_indicator.dart`
- [ ] **Step 1: 移除二段式逻辑,改为:下拉即刷新+弹出面板**
当前0-50% 松手刷新50%+ 松手打开面板
改为:下拉松手后同时触发刷新+弹出面板,无需精确控制距离
- [ ] **Step 2: 简化进度显示 — 只显示一个进度条**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P5.2: 精灵角色下拉互动对话
**Files:**
- Modify: `lib/features/home/presentation/home_refresh_indicator.dart`
- [ ] **Step 1: 下拉时精灵说不同的话**
```dart
const _pullDialogs = [
'想找什么?🤔',
'往下拉~',
'松手看看~',
'马上就好!',
];
```
- [ ] **Step 2: 对话气泡动画 — 从精灵头顶弹出1.5秒后消失**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P5.3: 空状态提示优化
**Files:**
- Modify: `lib/features/home/presentation/home_tool_center.dart`
- [ ] **Step 1: "待使用" → "打开任意页面后自动记录"**
- [ ] **Step 2: 空自定义按钮提示 → "长按设置常用工具"**
- [ ] **Step 3: 运行 flutter analyze 验证**
---
## P6: 最近打开面板增强
### Task P6.1: 面板内滑动查看更多最近页面
**Files:**
- Modify: `lib/features/home/presentation/home_tool_center.dart`
- Modify: `lib/core/services/navigation/recent_route_service.dart`
- [ ] **Step 1: 最近路由上限从3增加到10**
- [ ] **Step 2: 面板布局改为4个固定按钮行 + 可滚动的更多最近页面行**
- [ ] **Step 3: 更多行使用水平滚动的 ListView**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P6.2: 按使用频率排序
**Files:**
- Modify: `lib/core/services/navigation/recent_route_service.dart`
- [ ] **Step 1: 存储结构增加访问次数**
```dart
class RouteRecord {
final String route;
final int accessCount;
final DateTime lastAccessed;
}
```
- [ ] **Step 2: 新增 getFrequentRoutes() 方法 — 按 accessCount 降序**
- [ ] **Step 3: 面板增加排序切换按钮(最近/最常用)**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P6.3: 智能推荐 — 根据时间段推荐
**Files:**
- Create: `lib/core/services/navigation/smart_recommend_service.dart`
- Modify: `lib/features/home/presentation/home_tool_center.dart`
- [ ] **Step 1: 创建 SmartRecommendService**
```dart
class SmartRecommendService {
static String? getRecommendedRoute() {
final hour = DateTime.now().hour;
if (hour >= 6 && hour < 9) return AppRoutes.weather;
if (hour >= 21 || hour < 1) return AppRoutes.nightRead;
if (hour >= 12 && hour < 14) return AppRoutes.pomodoro;
return null;
}
}
```
- [ ] **Step 2: 面板中显示推荐按钮(带✨标识)**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P6.4: 面板内搜索页面
**Files:**
- Modify: `lib/features/home/presentation/home_tool_center.dart`
- [ ] **Step 1: 面板顶部增加搜索栏**
- [ ] **Step 2: 搜索结果从 PageRegistry 中匹配**
- [ ] **Step 3: 点击搜索结果跳转对应页面**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P6.5: 拖拽排序自定义按钮
**Files:**
- Modify: `lib/features/home/presentation/home_tool_center.dart`
- [ ] **Step 1: 自定义按钮区域支持长按拖拽排序**
- [ ] **Step 2: 拖拽排序结果持久化到 KvStorage**
- [ ] **Step 3: 运行 flutter analyze 验证**
---
## P7: 标签/精灵/引导页增强
### Task P7.1: 句子广场标签 — 频道订阅/取消
**Files:**
- Create: `lib/features/home/providers/channel_subscription_provider.dart`
- Modify: `lib/features/home/presentation/home_type_chip.dart`
- Modify: `lib/features/home/presentation/home_square_header.dart`
- [ ] **Step 1: 创建频道订阅 Provider — 管理用户订阅的频道列表**
- [ ] **Step 2: 标签栏只显示已订阅频道 + "管理"按钮**
- [ ] **Step 3: 管理页面支持订阅/取消频道**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P7.2: 句子广场标签 — 自定义频道排序
**Files:**
- Modify: `lib/features/home/presentation/home_type_chip.dart`
- [ ] **Step 1: 长按标签进入排序模式**
- [ ] **Step 2: 使用 ReorderableListView 实现拖拽排序**
- [ ] **Step 3: 排序结果持久化**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P7.3: 拾光精灵 — 情绪系统升级
**Files:**
- Modify: `lib/features/home/providers/character_mood_provider.dart`
- [ ] **Step 1: 情绪计算增加阅读时长/频率因子**
```dart
CharacterMood calculateMood({
required int readingMinutesToday,
required int streakDays,
required int sentencesReadToday,
})
```
- [ ] **Step 2: 情绪随时间自然衰减(长时间不阅读→无聊→困倦)**
- [ ] **Step 3: 运行 flutter analyze 验证**
### Task P7.4: 拾光精灵 — 对话气泡
**Files:**
- Create: `lib/shared/widgets/animation/sprite_dialog_bubble.dart`
- Modify: `lib/features/home/presentation/home_refresh_indicator.dart`
- [ ] **Step 1: 创建 SpriteDialogBubble 组件 — 毛玻璃气泡+文字+自动消失**
- [ ] **Step 2: 下拉时在精灵上方显示对话气泡**
- [ ] **Step 3: 对话内容根据下拉进度变化**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P7.5: 引导页 — 渐进式引导
**Files:**
- Create: `lib/features/onboarding/providers/progressive_guide_provider.dart`
- Create: `lib/shared/widgets/feedback/feature_guide_overlay.dart`
- [ ] **Step 1: 创建 ProgressiveGuideProvider — 追踪用户已看过的功能引导**
- [ ] **Step 2: 创建 FeatureGuideOverlay — 高亮某功能区域+说明文字**
- [ ] **Step 3: 首次使用某功能时弹出引导**
- [ ] **Step 4: 运行 flutter analyze 验证**
### Task P7.6: 提交 P7 阶段代码 + 更新 CHANGELOG
- [ ] **Step 1: 全量 flutter analyze**
- [ ] **Step 2: 更新 CHANGELOG.md**
- [ ] **Step 3: 清理 spec 文档**
---
## 执行顺序建议
```
P1 (类型安全) → P2 (状态管理) → P3 (主题适配) → P4 (组件拆分)
P5 (下拉手势) → P6 (最近面板) → P7 (标签/精灵/引导页)
```
P1-P4 是架构基础必须先完成。P5-P7 是功能增强,依赖 P1-P4 的基础。