import 'package:freezed_annotation/freezed_annotation.dart'; import '../../../domain/entities/user.dart'; part 'login_state.freezed.dart'; /// 登录页面状态(@freezed 自动生成 copyWith / == / toString) /// /// ViewModel 通过 `state = state.copyWith(...)` 更新状态, /// View 通过 `ref.watch(loginViewModelProvider)` 自动响应变化。 /// /// ## 状态流转 /// /// ``` /// 初始 → LoginState() isLoading: false, user: null, error: null /// 点击登录 → state.copyWith(isLoading: true) isLoading: true /// 登录成功 → state.copyWith(user: user) isLoading: false, user: User /// 格式错误 → state.copyWith(error: '邮箱格式不正确') isLoading: false, error: String /// 网络错误 → state.copyWith(error: '网络错误') isLoading: false, error: String /// ``` @freezed sealed class LoginState with _$LoginState { const factory LoginState({ /// 登录成功后的用户信息(null = 未登录) User? user, /// 是否正在请求中(控制 loading 状态 / 按钮禁用) @Default(false) bool isLoading, /// 错误信息(null = 无错误) String? error, }) = _LoginState; }