// 认证状态 — AuthBloc 输出的 UI 状态 part of 'auth_bloc.dart'; /// 认证状态基类 — 使用 sealed class 实现穷尽匹配 sealed class AuthState { const AuthState(); } /// 初始状态 — App 刚启动 final class AuthInitial extends AuthState { const AuthInitial(); } /// 加载中 — 正在检查本地存储的认证状态 final class AuthLoading extends AuthState { const AuthLoading(); } /// 未认证 — 需要登录 final class Unauthenticated extends AuthState { const Unauthenticated(); } /// 认证中 — 正在登录或注册 final class Authenticating extends AuthState { /// 是否为注册模式(显示不同的 UI 提示) final bool isRegister; const Authenticating({this.isRegister = false}); } /// 已认证 — 用户已登录 final class Authenticated extends AuthState { final User user; /// 是否需要角色选择(新注册用户还没有角色) final bool needsRoleSelection; /// 是否需要班级码加入(学生/家长角色) final bool needsClassCode; /// 是否正在加载(班级码验证中) final bool isLoading; /// 班级码验证错误信息 final String? classCodeError; const Authenticated({ required this.user, this.needsRoleSelection = false, this.needsClassCode = false, this.isLoading = false, this.classCodeError, }); Authenticated copyWith({ User? user, bool? needsRoleSelection, bool? needsClassCode, bool? isLoading, String? classCodeError, }) => Authenticated( user: user ?? this.user, needsRoleSelection: needsRoleSelection ?? this.needsRoleSelection, needsClassCode: needsClassCode ?? this.needsClassCode, isLoading: isLoading ?? this.isLoading, classCodeError: classCodeError, ); } /// 认证错误 — 登录/注册失败 final class AuthError extends AuthState { final String message; /// 是否可以重试 final bool retryable; const AuthError(this.message, {this.retryable = true}); } /// 需要家长授权 — 未满 14 岁用户需要家长确认 final class ParentAuthRequired extends AuthState { final User user; const ParentAuthRequired(this.user); }