added support for multiple accounts, guardian login bugfixes, ui changes
This commit is contained in:
@@ -4,12 +4,38 @@ import 'account_event.dart';
|
||||
import 'account_state.dart';
|
||||
|
||||
class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
AccountBloc({AccountStatus initialStatus = AccountStatus.undefined})
|
||||
: super(AccountState(status: initialStatus)) {
|
||||
AccountBloc({
|
||||
AccountStatus initialStatus = AccountStatus.undefined,
|
||||
String? accountId,
|
||||
}) : super(AccountState(status: initialStatus, accountId: accountId)) {
|
||||
on<AccountStatusChanged>(
|
||||
(event, emit) => emit(state.copyWith(status: event.status)),
|
||||
(event, emit) => emit(
|
||||
AccountState(
|
||||
status: event.status,
|
||||
accountId: event.status == AccountStatus.loggedOut
|
||||
? null
|
||||
: state.accountId,
|
||||
),
|
||||
),
|
||||
);
|
||||
on<AccountActivated>(
|
||||
(event, emit) => emit(
|
||||
AccountState(
|
||||
status: AccountStatus.loggedIn,
|
||||
accountId: event.accountId,
|
||||
freshLogin: event.freshLogin,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void setStatus(AccountStatus status) => add(AccountStatusChanged(status));
|
||||
|
||||
/// [accountId] became the active account (login, switch or takeover after a
|
||||
/// sign-out); null means no account is left.
|
||||
void activated(String? accountId, {bool freshLogin = false}) => add(
|
||||
accountId == null
|
||||
? const AccountStatusChanged(AccountStatus.loggedOut)
|
||||
: AccountActivated(accountId, freshLogin: freshLogin),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user