fix:登录退出页
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
import '../models/models.dart';
|
||||
|
||||
class AuthState {
|
||||
const AuthState({this.loggedIn = false, this.pendingAction});
|
||||
const AuthState({
|
||||
this.loggedIn = false,
|
||||
this.pendingAction,
|
||||
this.phone,
|
||||
this.loginMethod,
|
||||
});
|
||||
|
||||
final bool loggedIn;
|
||||
final PendingLoginAction? pendingAction;
|
||||
final String? phone;
|
||||
final LoginMethod? loginMethod;
|
||||
|
||||
AuthState copyWith({bool? loggedIn, Object? pendingAction = _sentinel}) {
|
||||
AuthState copyWith({
|
||||
bool? loggedIn,
|
||||
Object? pendingAction = _sentinel,
|
||||
Object? phone = _sentinel,
|
||||
Object? loginMethod = _sentinel,
|
||||
}) {
|
||||
return AuthState(
|
||||
loggedIn: loggedIn ?? this.loggedIn,
|
||||
pendingAction: identical(pendingAction, _sentinel)
|
||||
? this.pendingAction
|
||||
: pendingAction as PendingLoginAction?,
|
||||
phone: identical(phone, _sentinel) ? this.phone : phone as String?,
|
||||
loginMethod: identical(loginMethod, _sentinel)
|
||||
? this.loginMethod
|
||||
: loginMethod as LoginMethod?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,11 @@ class AuthController extends StateNotifier<AuthState> {
|
||||
final UserStateRepository _repository;
|
||||
|
||||
Future<void> _load() async {
|
||||
state = state.copyWith(loggedIn: await _repository.isLoggedIn());
|
||||
state = state.copyWith(
|
||||
loggedIn: await _repository.isLoggedIn(),
|
||||
phone: await _repository.getPhone(),
|
||||
loginMethod: await _repository.getLoginMethod(),
|
||||
);
|
||||
}
|
||||
|
||||
void requireLogin(PendingLoginAction action) {
|
||||
@@ -57,10 +61,14 @@ class AuthController extends StateNotifier<AuthState> {
|
||||
state = state.copyWith(pendingAction: action);
|
||||
}
|
||||
|
||||
Future<PendingLoginAction?> login(LoginMethod method) async {
|
||||
Future<PendingLoginAction?> login(LoginMethod method, {String? phone}) async {
|
||||
final pending = state.pendingAction;
|
||||
await _repository.login(method);
|
||||
state = const AuthState(loggedIn: true);
|
||||
await _repository.login(method, phone: phone);
|
||||
state = AuthState(
|
||||
loggedIn: true,
|
||||
phone: phone ?? await _repository.getPhone(),
|
||||
loginMethod: method,
|
||||
);
|
||||
return pending;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user