feat(auth): 添加登录/注册页面及令牌恢复流程
- 新增 SplashPage(启动页)和 LoginPage(登录页),支持路由跳转 - 扩展 AuthState,增加 submitting/alert/busy 状态及消费机制 - AuthController 增加 checkLoginState/register/showAlert 等方法 - 删除旧模型文件(binding_item, token_response, verify_response) - 删除旧版 LoginPage,迁移至 features/auth 目录 - 更新本地化字符串,增加注册相关文案 - 调整默认 API 地址为本地开发环境
This commit is contained in:
@@ -3,12 +3,22 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
part 'auth_state.freezed.dart';
|
||||
|
||||
/// 登录状态。
|
||||
///
|
||||
/// [alert] 为一次性提示(登录失效、注册成功等),UI 展示后须调用
|
||||
/// `AuthController.consumeAlert()` 消费,避免重建时重复弹出。
|
||||
@freezed
|
||||
class AuthState with _$AuthState {
|
||||
const AuthState._();
|
||||
|
||||
const factory AuthState({
|
||||
@Default(false) bool loggedIn,
|
||||
@Default(false) bool restoring,
|
||||
@Default(false) bool submitting,
|
||||
String? username,
|
||||
String? error,
|
||||
String? alert,
|
||||
}) = _AuthState;
|
||||
|
||||
/// 是否应禁用输入与提交按钮。
|
||||
bool get busy => submitting || restoring;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ final _privateConstructorUsedError = UnsupportedError(
|
||||
mixin _$AuthState {
|
||||
bool get loggedIn => throw _privateConstructorUsedError;
|
||||
bool get restoring => throw _privateConstructorUsedError;
|
||||
bool get submitting => throw _privateConstructorUsedError;
|
||||
String? get username => throw _privateConstructorUsedError;
|
||||
String? get error => throw _privateConstructorUsedError;
|
||||
String? get alert => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of AuthState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -34,7 +36,14 @@ abstract class $AuthStateCopyWith<$Res> {
|
||||
factory $AuthStateCopyWith(AuthState value, $Res Function(AuthState) then) =
|
||||
_$AuthStateCopyWithImpl<$Res, AuthState>;
|
||||
@useResult
|
||||
$Res call({bool loggedIn, bool restoring, String? username, String? error});
|
||||
$Res call({
|
||||
bool loggedIn,
|
||||
bool restoring,
|
||||
bool submitting,
|
||||
String? username,
|
||||
String? error,
|
||||
String? alert,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -54,8 +63,10 @@ class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
|
||||
$Res call({
|
||||
Object? loggedIn = null,
|
||||
Object? restoring = null,
|
||||
Object? submitting = null,
|
||||
Object? username = freezed,
|
||||
Object? error = freezed,
|
||||
Object? alert = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
@@ -67,6 +78,10 @@ class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
|
||||
? _value.restoring
|
||||
: restoring // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
submitting: null == submitting
|
||||
? _value.submitting
|
||||
: submitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
username: freezed == username
|
||||
? _value.username
|
||||
: username // ignore: cast_nullable_to_non_nullable
|
||||
@@ -75,6 +90,10 @@ class _$AuthStateCopyWithImpl<$Res, $Val extends AuthState>
|
||||
? _value.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
alert: freezed == alert
|
||||
? _value.alert
|
||||
: alert // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
@@ -90,7 +109,14 @@ abstract class _$$AuthStateImplCopyWith<$Res>
|
||||
) = __$$AuthStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({bool loggedIn, bool restoring, String? username, String? error});
|
||||
$Res call({
|
||||
bool loggedIn,
|
||||
bool restoring,
|
||||
bool submitting,
|
||||
String? username,
|
||||
String? error,
|
||||
String? alert,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -109,8 +135,10 @@ class __$$AuthStateImplCopyWithImpl<$Res>
|
||||
$Res call({
|
||||
Object? loggedIn = null,
|
||||
Object? restoring = null,
|
||||
Object? submitting = null,
|
||||
Object? username = freezed,
|
||||
Object? error = freezed,
|
||||
Object? alert = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_$AuthStateImpl(
|
||||
@@ -122,6 +150,10 @@ class __$$AuthStateImplCopyWithImpl<$Res>
|
||||
? _value.restoring
|
||||
: restoring // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
submitting: null == submitting
|
||||
? _value.submitting
|
||||
: submitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
username: freezed == username
|
||||
? _value.username
|
||||
: username // ignore: cast_nullable_to_non_nullable
|
||||
@@ -130,6 +162,10 @@ class __$$AuthStateImplCopyWithImpl<$Res>
|
||||
? _value.error
|
||||
: error // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
alert: freezed == alert
|
||||
? _value.alert
|
||||
: alert // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -137,13 +173,15 @@ class __$$AuthStateImplCopyWithImpl<$Res>
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$AuthStateImpl implements _AuthState {
|
||||
class _$AuthStateImpl extends _AuthState {
|
||||
const _$AuthStateImpl({
|
||||
this.loggedIn = false,
|
||||
this.restoring = false,
|
||||
this.submitting = false,
|
||||
this.username,
|
||||
this.error,
|
||||
});
|
||||
this.alert,
|
||||
}) : super._();
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
@@ -152,13 +190,18 @@ class _$AuthStateImpl implements _AuthState {
|
||||
@JsonKey()
|
||||
final bool restoring;
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool submitting;
|
||||
@override
|
||||
final String? username;
|
||||
@override
|
||||
final String? error;
|
||||
@override
|
||||
final String? alert;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AuthState(loggedIn: $loggedIn, restoring: $restoring, username: $username, error: $error)';
|
||||
return 'AuthState(loggedIn: $loggedIn, restoring: $restoring, submitting: $submitting, username: $username, error: $error, alert: $alert)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -170,14 +213,24 @@ class _$AuthStateImpl implements _AuthState {
|
||||
other.loggedIn == loggedIn) &&
|
||||
(identical(other.restoring, restoring) ||
|
||||
other.restoring == restoring) &&
|
||||
(identical(other.submitting, submitting) ||
|
||||
other.submitting == submitting) &&
|
||||
(identical(other.username, username) ||
|
||||
other.username == username) &&
|
||||
(identical(other.error, error) || other.error == error));
|
||||
(identical(other.error, error) || other.error == error) &&
|
||||
(identical(other.alert, alert) || other.alert == alert));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, loggedIn, restoring, username, error);
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
loggedIn,
|
||||
restoring,
|
||||
submitting,
|
||||
username,
|
||||
error,
|
||||
alert,
|
||||
);
|
||||
|
||||
/// Create a copy of AuthState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -188,22 +241,29 @@ class _$AuthStateImpl implements _AuthState {
|
||||
__$$AuthStateImplCopyWithImpl<_$AuthStateImpl>(this, _$identity);
|
||||
}
|
||||
|
||||
abstract class _AuthState implements AuthState {
|
||||
abstract class _AuthState extends AuthState {
|
||||
const factory _AuthState({
|
||||
final bool loggedIn,
|
||||
final bool restoring,
|
||||
final bool submitting,
|
||||
final String? username,
|
||||
final String? error,
|
||||
final String? alert,
|
||||
}) = _$AuthStateImpl;
|
||||
const _AuthState._() : super._();
|
||||
|
||||
@override
|
||||
bool get loggedIn;
|
||||
@override
|
||||
bool get restoring;
|
||||
@override
|
||||
bool get submitting;
|
||||
@override
|
||||
String? get username;
|
||||
@override
|
||||
String? get error;
|
||||
@override
|
||||
String? get alert;
|
||||
|
||||
/// Create a copy of AuthState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
|
||||
Reference in New Issue
Block a user