Files
nj/app/lib/features/auth/views/login_page.dart
iven 181bfb1f3e fix(app): 对齐 Open Design spec — 字体/Token/首页/Tab栏/路由/Discover页
针对 docs/opendesign/warm-notes-design-spec.md 全面审查的修复:

## 🔴 阻断级修复(商用合规)
- 下载真实 Quicksand/Nunito 字体文件(原 0 字节)
- 添加 OFL.txt 许可证文件,履行 SIL Open Font License 分发义务

## 🟠 设计 Token 偏差
- AppRadius: 删除非规范的 xs=8px,所有引用迁移至 sm=10px
- AppColors.moodColors: 对齐 spec §3.6
  - happy #FFD93D → secondary #81B29A
  - calm #81B29A → tertiary #F2CC8F
  - sad #7B9CC4 → #5B7DB1
  - thinking #B8A9C9(淡紫,spec 无)→ #8B7E74
- AppShadows: blurRadius/alpha 精确对齐 spec §1 (12/20/32 + 0.06/0.08/0.12)
- DesignTokens: 补 spacing40 + 新增 safe-top/safe-bottom/tab-height/touch-min 常量

## 🟠 首页 §3.4 完全重构
- 新增问候语头部(xx好,小暖 + accent 色高亮名字)
- 新增 streak-badge pill 徽章(tertiary-soft + #B8860B 暖金)
- 心情选择器卡片背景从 primaryContainer 改为 surface(spec 规定 #FFFFFF)
- 心情卡片圆角 lg(22) → md(16) 对齐 spec
- 新增 today-card 渐变卡片 + 浮动右下圆形写按钮
- 新增 quick-stats 三栏统计(本月日记/连续天数/总日记数)
- 移除 AppBar 多余的贴纸/模板按钮,搜索按钮改路由到 /search
- HomeBloc 扩展 monthCount/totalCount 字段
- 日记卡片:72×72 预览图 + 标签摘要 + 心情圆点

## 🟠 路由 §3.12 + §3.13 拆分
- 新建 DiscoverPage (features/discover/views/discover_page.dart)
  - 搜索框(跳转 /search)
  - 每日推荐渐变卡片
  - 热门话题横向 chips(前 3 个 accent 高亮)
  - 精选模板 2 列网格
  - 达人日记列表
- /discover 路由从指向 SearchPage 改为 DiscoverPage
- 新增 /search 路由(全屏无 Tab)指向 SearchPage

## 🟠 Tab 栏 §2.2 重构
- 高度从 64px 改为 56+bottomPadding(含 safe-bottom,约 90px)
- 中心按钮从 CircularNotchedRectangle 凹槽改为 margin-top:-16px 凸起
- FAB 尺寸从默认改为 48×48 spec 规格
- FAB 图标从 edit_rounded 改为 add_rounded(spec §2.2)
- 删除未使用的 _navItems 旧常量

## 🟡 登录页圆角统一
- 移除 3 处 InputBorder 显式 mdBorder(16px) 覆盖
- 全局主题 smBorder(10px) 生效,对齐 spec
- 提交按钮圆角改为 pill(spec §2.6 Primary 按钮)

## 验证
- flutter analyze: 0 errors (剩余 40 个 warning/info 全为预存)
- flutter test: 84/85 通过(widget smoke test 预存失败,与本次无关)
2026-06-02 09:11:46 +08:00

323 lines
10 KiB
Dart

// 登录页面 — 用户名密码登录 + 注册切换
//
// 设计要点:
// - 温暖治愈风格,使用珊瑚色主色调
// - 表单验证友好提示(面向小学生,语言简单)
// - 密码可切换可见性
// - 登录/注册模式平滑切换
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import '../../../core/constants/design_tokens.dart';
import '../../../core/theme/app_radius.dart';
import '../bloc/auth_bloc.dart';
/// 登录/注册页面
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMixin {
final _formKey = GlobalKey<FormState>();
final _usernameController = TextEditingController();
final _passwordController = TextEditingController();
final _displayNameController = TextEditingController();
bool _isRegister = false;
bool _obscurePassword = true;
late final AnimationController _animController;
late final Animation<double> _fadeAnim;
@override
void initState() {
super.initState();
_animController = AnimationController(
vsync: this,
duration: DesignTokens.animNormal,
);
_fadeAnim = CurvedAnimation(
parent: _animController,
curve: DesignTokens.warmCurve,
);
_animController.forward();
}
@override
void dispose() {
_usernameController.dispose();
_passwordController.dispose();
_displayNameController.dispose();
_animController.dispose();
super.dispose();
}
void _submit() {
if (!_formKey.currentState!.validate()) return;
if (_isRegister) {
context.read<AuthBloc>().add(RegisterRequested(
username: _usernameController.text.trim(),
password: _passwordController.text,
displayName: _displayNameController.text.trim().isEmpty
? null
: _displayNameController.text.trim(),
));
} else {
context.read<AuthBloc>().add(LoginRequested(
username: _usernameController.text.trim(),
password: _passwordController.text,
));
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
return BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
if (state is Authenticated) {
if (state.needsRoleSelection) {
context.go('/role-selection');
} else if (state.needsClassCode) {
context.go('/class-code');
} else {
context.go('/home');
}
}
},
child: Scaffold(
body: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(
horizontal: DesignTokens.spacing32,
),
child: FadeTransition(
opacity: _fadeAnim,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildHeader(context, colorScheme),
const SizedBox(height: DesignTokens.spacing48),
_buildForm(context, theme, colorScheme),
const SizedBox(height: DesignTokens.spacing24),
_buildSubmitButton(context, colorScheme),
const SizedBox(height: DesignTokens.spacing16),
_buildModeToggle(context, colorScheme),
const SizedBox(height: DesignTokens.spacing32),
BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
if (state is AuthError) {
return _buildErrorMessage(state.message, colorScheme);
}
return const SizedBox.shrink();
},
),
],
),
),
),
),
),
),
);
}
Widget _buildHeader(BuildContext context, ColorScheme colorScheme) {
return Column(
children: [
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
color: colorScheme.primaryContainer,
borderRadius: AppRadius.lgBorder,
),
child: Icon(
Icons.edit_note_rounded,
size: 44,
color: colorScheme.primary,
),
),
const SizedBox(height: DesignTokens.spacing16),
Text(
'暖记',
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
fontWeight: FontWeight.bold,
color: colorScheme.primary,
),
),
const SizedBox(height: DesignTokens.spacing4),
Text(
'记录温暖,书写成长',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: colorScheme.onSurface.withValues(alpha: 0.6),
),
),
],
);
}
Widget _buildForm(BuildContext context, ThemeData theme, ColorScheme colorScheme) {
return Form(
key: _formKey,
child: Column(
children: [
AnimatedSize(
duration: DesignTokens.animNormal,
curve: DesignTokens.warmCurve,
child: AnimatedSwitcher(
duration: DesignTokens.animNormal,
child: _isRegister
? Padding(
key: const ValueKey('display-name'),
padding: const EdgeInsets.only(bottom: DesignTokens.spacing16),
child: TextFormField(
controller: _displayNameController,
decoration: const InputDecoration(
labelText: '昵称',
hintText: '你想被叫什么名字?',
prefixIcon: Icon(Icons.face_rounded),
),
textInputAction: TextInputAction.next,
),
)
: const SizedBox.shrink(key: ValueKey('display-name-hide')),
),
),
TextFormField(
controller: _usernameController,
decoration: InputDecoration(
labelText: '账号',
hintText: _isRegister ? '设置一个账号名' : '输入你的账号',
prefixIcon: const Icon(Icons.person_rounded),
),
textInputAction: TextInputAction.next,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return '请输入账号';
}
if (value.trim().length < 3) {
return '账号至少需要 3 个字符';
}
return null;
},
),
const SizedBox(height: DesignTokens.spacing16),
TextFormField(
controller: _passwordController,
obscureText: _obscurePassword,
decoration: InputDecoration(
labelText: '密码',
hintText: _isRegister ? '设置一个密码' : '输入你的密码',
prefixIcon: const Icon(Icons.lock_rounded),
suffixIcon: IconButton(
icon: Icon(
_obscurePassword
? Icons.visibility_off_rounded
: Icons.visibility_rounded,
),
onPressed: () {
setState(() {
_obscurePassword = !_obscurePassword;
});
},
),
),
textInputAction: TextInputAction.done,
onFieldSubmitted: (_) => _submit(),
validator: (value) {
if (value == null || value.isEmpty) {
return '请输入密码';
}
if (value.length < 6) {
return '密码至少需要 6 个字符';
}
return null;
},
),
],
),
);
}
Widget _buildSubmitButton(BuildContext context, ColorScheme colorScheme) {
return BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
final isLoading = state is Authenticating;
return SizedBox(
width: double.infinity,
height: 52,
child: FilledButton(
onPressed: isLoading ? null : _submit,
style: FilledButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: AppRadius.pillBorder,
),
),
child: isLoading
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2.5,
color: Colors.white,
),
)
: Text(
_isRegister ? '注册' : '登录',
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
),
);
},
);
}
Widget _buildModeToggle(BuildContext context, ColorScheme colorScheme) {
return TextButton(
onPressed: () {
setState(() {
_isRegister = !_isRegister;
});
_formKey.currentState?.reset();
},
child: Text(
_isRegister ? '已有账号?去登录' : '没有账号?去注册',
style: TextStyle(color: colorScheme.primary),
),
);
}
Widget _buildErrorMessage(String message, ColorScheme colorScheme) {
return Container(
width: double.infinity,
padding: const EdgeInsets.all(DesignTokens.spacing12),
decoration: BoxDecoration(
color: colorScheme.errorContainer,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(Icons.info_outline_rounded, size: 20, color: colorScheme.onErrorContainer),
const SizedBox(width: DesignTokens.spacing8),
Expanded(
child: Text(
message,
style: TextStyle(color: colorScheme.onErrorContainer, fontSize: 14),
),
),
],
),
);
}
}