Files
pluv 22715f7247 feat: manage, account and help pages
- 管理页:单元集 / 计划 / 算法三个维度,卡片带元数据
- 账户页:资料、学习数据、竖直分组的四个功能入口
- 新增设置、文档与帮助(底部可上滑助手)、反馈、关于四个页面
- 抽出 StatBlock 与 GroupedListSection 共用组件
- 关闭 Android 预测式返回,转场改为 M3 水平滑入
2026-10-24 15:21:30 +08:00

422 lines
13 KiB
Dart

import 'package:flutter/material.dart';
import '../models/app_status.dart';
import '../models/study_plan.dart';
import '../widgets/stat_block.dart';
/// 学习首页。
///
/// 信息层级刻意保持简单,和百词斩首页同构:
/// 顶部状态标识 → 当前材料 → 今日任务(要做什么 + 要多久)→ 唯一主行动
/// → 快捷入口。
/// 但去掉它的商业化部分:没有广告位、没有课程倒计时、没有电商入口。
class StudyPage extends StatelessWidget {
const StudyPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
bottom: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
const Padding(
padding: EdgeInsets.fromLTRB(16, 12, 16, 2),
child: _StatusStrip(status: AppStatus.sample),
),
Expanded(
child: ListView(
padding: const EdgeInsets.fromLTRB(16, 10, 16, 32),
children: const <Widget>[
_DeckCard(plan: StudyPlan.sample),
SizedBox(height: 14),
_TodayPlanCard(plan: StudyPlan.sample),
SizedBox(height: 18),
_QuickActions(),
],
),
),
],
),
),
);
}
}
/// 顶部状态标识:计划接力 / 今日记忆 / 云同步,右侧是搜索与日志入口。
///
/// 状态用图形和颜色表达,文字只留给「今日记忆」这个需要被读懂的标签;
/// 完整语义("云同步: 成功" 等)放进 tooltip 与无障碍描述里。
/// 窄屏时胶囊横向滚动,右侧按钮始终可见。
class _StatusStrip extends StatelessWidget {
const _StatusStrip({required this.status});
final AppStatus status;
static const Color _streak = Color(0xFFFFB300);
static const Color _success = Color(0xFF4CAF50);
@override
Widget build(BuildContext context) {
final ColorScheme colors = Theme.of(context).colorScheme;
final (IconData syncIcon, Color syncColor) = switch (status.sync) {
SyncState.success => (Icons.cloud_done_rounded, _success),
SyncState.syncing => (Icons.cloud_sync_rounded, colors.tertiary),
SyncState.failed => (Icons.cloud_off_rounded, colors.error),
SyncState.unknown => (Icons.cloud_queue_rounded, colors.outline),
};
return Row(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
_Pill(
leading: Icon(
Icons.bolt_rounded,
size: 16,
color: _streak,
),
value: '${status.streakDays}',
tooltip: status.streakLabel,
),
const SizedBox(width: 8),
_Pill(
label: '今日记忆',
value: '${status.todayItems}',
tooltip: status.todayLabel,
),
const SizedBox(width: 8),
_Pill(
leading: Icon(syncIcon, size: 16, color: syncColor),
tooltip: status.syncLabel,
),
],
),
),
),
IconButton(
icon: const Icon(Icons.search_rounded),
tooltip: '搜索条目',
visualDensity: VisualDensity.compact,
onPressed: () => _pending(context, '搜索'),
),
IconButton(
icon: const Icon(Icons.receipt_long_outlined),
tooltip: '学习日志',
visualDensity: VisualDensity.compact,
onPressed: () => _pending(context, '学习日志'),
),
],
);
}
}
class _Pill extends StatelessWidget {
const _Pill({this.leading, this.label, this.value, this.tooltip});
final Widget? leading;
final String? label;
final String? value;
final String? tooltip;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ColorScheme colors = theme.colorScheme;
final TextTheme text = theme.textTheme;
final Widget? leading = this.leading;
final String? label = this.label;
final String? value = this.value;
final Widget pill = Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
decoration: ShapeDecoration(
color: colors.surfaceContainerHigh,
shape: const StadiumBorder(),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (leading != null) ...<Widget>[
leading,
const SizedBox(width: 6),
],
if (label != null)
Text(
label,
style: text.labelMedium?.copyWith(color: colors.onSurfaceVariant),
),
if (label != null && value != null) const SizedBox(width: 6),
if (value != null)
Text(
value,
style: text.labelLarge?.copyWith(
fontWeight: FontWeight.w700,
color: colors.onSurface,
),
),
],
),
);
final String? tooltip = this.tooltip;
return tooltip == null ? pill : Tooltip(message: tooltip, child: pill);
}
}
/// 当前单元集:名称、算法、完成度。
class _DeckCard extends StatelessWidget {
const _DeckCard({required this.plan});
final StudyPlan plan;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ColorScheme colors = theme.colorScheme;
final TextTheme text = theme.textTheme;
return _SurfaceCard(
onTap: () => _pending(context, '单元集切换'),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: colors.primaryContainer,
borderRadius: BorderRadius.circular(12),
),
child: Icon(
Icons.menu_book_rounded,
color: colors.onPrimaryContainer,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
plan.deckName,
style: text.titleMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 2),
Text(
'调度算法 ${plan.algorithm}',
style: text.bodySmall?.copyWith(
color: colors.onSurfaceVariant,
),
),
],
),
),
Icon(
Icons.unfold_more_rounded,
size: 20,
color: colors.onSurfaceVariant,
),
],
),
const SizedBox(height: 16),
ClipRRect(
borderRadius: BorderRadius.circular(6),
child: LinearProgressIndicator(
value: plan.progress,
minHeight: 8,
backgroundColor: colors.surfaceContainerHighest,
),
),
const SizedBox(height: 8),
Row(
children: <Widget>[
Text(
'${plan.activatedItems} / ${plan.totalItems}',
style: text.bodySmall?.copyWith(color: colors.onSurfaceVariant),
),
const Spacer(),
Text(
plan.progressPercent,
style: text.bodySmall?.copyWith(
color: colors.onSurfaceVariant,
fontWeight: FontWeight.w600,
),
),
],
),
],
),
);
}
}
/// 今日任务:两个数字 + 时长承诺 + 唯一主行动。
class _TodayPlanCard extends StatelessWidget {
const _TodayPlanCard({required this.plan});
final StudyPlan plan;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ColorScheme colors = theme.colorScheme;
final TextTheme text = theme.textTheme;
return _SurfaceCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('今日计划', style: text.titleMedium),
const SizedBox(height: 18),
Row(
children: <Widget>[
Expanded(
child: StatBlock(
label: '待复习',
value: '${plan.dueItems}',
unit: '条',
),
),
Expanded(
child: StatBlock(
label: '待新识',
value: '${plan.newItems}',
unit: '条',
),
),
],
),
const SizedBox(height: 16),
Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(
Icons.schedule_rounded,
size: 16,
color: colors.onSurfaceVariant,
),
const SizedBox(width: 6),
Text(
plan.estimatedLabel,
style: text.bodyMedium?.copyWith(
color: colors.onSurfaceVariant,
),
),
],
),
),
const SizedBox(height: 16),
FilledButton(
onPressed: plan.isEmpty ? null : () => _pending(context, '学习会话'),
style: FilledButton.styleFrom(
minimumSize: const Size.fromHeight(52),
textStyle: text.titleMedium,
),
child: Text(plan.isEmpty ? '今天已完成' : '开始学习'),
),
],
),
);
}
}
/// 快捷入口。都是「学习域」内的次级入口,维护类操作不放这里。
class _QuickActions extends StatelessWidget {
const _QuickActions();
static const List<(IconData, String)> _items = <(IconData, String)>[
(Icons.star_border_rounded, '收藏夹'),
(Icons.quiz_outlined, '自我测试'),
(Icons.attach_file_rounded, '附带资料'),
(Icons.tune_rounded, '计划设置'),
];
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final ColorScheme colors = theme.colorScheme;
return Row(
children: <Widget>[
for (final (int index, (IconData icon, String label)) in _items.indexed)
Expanded(
child: Padding(
padding: EdgeInsets.only(left: index == 0 ? 0 : 8),
child: Material(
color: colors.surfaceContainerLow,
borderRadius: BorderRadius.circular(16),
child: InkWell(
borderRadius: BorderRadius.circular(16),
onTap: () => _pending(context, label),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 14),
child: Column(
children: <Widget>[
Icon(icon, size: 22, color: colors.primary),
const SizedBox(height: 8),
Text(
label,
style: theme.textTheme.labelSmall?.copyWith(
color: colors.onSurfaceVariant,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
),
),
),
],
);
}
}
/// 统一的卡片外观,避免每处重复写圆角和底色。
class _SurfaceCard extends StatelessWidget {
const _SurfaceCard({required this.child, this.onTap});
final Widget child;
/// 可点击时给出水波纹反馈;为 null 时是纯展示卡片。
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final BorderRadius radius = BorderRadius.circular(20);
return Material(
color: Theme.of(context).colorScheme.surfaceContainerLow,
borderRadius: radius,
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: onTap,
borderRadius: radius,
child: Padding(padding: const EdgeInsets.all(18), child: child),
),
);
}
}
/// 尚未接入内核的入口,点击给出明确反馈而不是静默无响应。
void _pending(BuildContext context, String feature) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('$feature 尚未接入内核'),
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.fromLTRB(16, 0, 16, 88),
),
);
}