mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-12-26 08:09:37 -05:00
9bb20f4dd2
refactor splash screen to process initialization in a better way more async tools for async cubit constructors greatly improved StateMapFollower class
36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:bloc/bloc.dart';
|
|
import 'package:veilid_support/veilid_support.dart';
|
|
|
|
import '../repository/account_repository/account_repository.dart';
|
|
|
|
class ActiveLocalAccountCubit extends Cubit<TypedKey?> {
|
|
ActiveLocalAccountCubit(AccountRepository accountRepository)
|
|
: _accountRepository = accountRepository,
|
|
super(accountRepository.getActiveLocalAccount()) {
|
|
// Subscribe to streams
|
|
_accountRepositorySubscription = _accountRepository.stream.listen((change) {
|
|
switch (change) {
|
|
case AccountRepositoryChange.activeLocalAccount:
|
|
emit(_accountRepository.getActiveLocalAccount());
|
|
break;
|
|
// Ignore these
|
|
case AccountRepositoryChange.localAccounts:
|
|
case AccountRepositoryChange.userLogins:
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Future<void> close() async {
|
|
await super.close();
|
|
await _accountRepositorySubscription.cancel();
|
|
}
|
|
|
|
final AccountRepository _accountRepository;
|
|
late final StreamSubscription<AccountRepositoryChange>
|
|
_accountRepositorySubscription;
|
|
}
|