wait for account data population and set initial AccountBloc status

This commit is contained in:
2026-05-05 22:08:10 +02:00
parent 9b5a70b285
commit 54ba04a7bd
2 changed files with 12 additions and 3 deletions
+11 -2
View File
@@ -43,7 +43,7 @@ Future<void> main() async {
final initialisationTasks = [ final initialisationTasks = [
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform) Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform)
.then((_) async => log('Firebase token: ${await FirebaseMessaging.instance.getToken() ?? "Error: no Firebase token!"}')) .then<void>((_) {})
.onError((error, _) => log('Error initializing Firebase: $error')), .onError((error, _) => log('Error initializing Firebase: $error')),
PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem').then(addCertificateAsTrusted), PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem').then(addCertificateAsTrusted),
PlatformAssetBundle().load('assets/ca/lets-encrypt-r10.pem').then(addCertificateAsTrusted), PlatformAssetBundle().load('assets/ca/lets-encrypt-r10.pem').then(addCertificateAsTrusted),
@@ -54,12 +54,19 @@ Future<void> main() async {
); );
HydratedBloc.storage = storage; HydratedBloc.storage = storage;
}), }),
AccountData().waitForPopulation(),
]; ];
log('starting app initialisation...'); log('starting app initialisation...');
await Future.wait(initialisationTasks); await Future.wait(initialisationTasks);
log('app initialisation done!'); log('app initialisation done!');
unawaited(
FirebaseMessaging.instance.getToken().then(
(token) => log('Firebase token: ${token ?? "Error: no Firebase token!"}'),
),
);
if (kReleaseMode) { if (kReleaseMode) {
ErrorWidget.builder = (error) => PlaceholderView( ErrorWidget.builder = (error) => PlaceholderView(
icon: Icons.phonelink_erase_rounded, icon: Icons.phonelink_erase_rounded,
@@ -83,7 +90,9 @@ Future<void> main() async {
MultiBlocProvider( MultiBlocProvider(
providers: [ providers: [
BlocProvider<SettingsCubit>(create: (_) => SettingsCubit()), BlocProvider<SettingsCubit>(create: (_) => SettingsCubit()),
BlocProvider<AccountBloc>(create: (_) => AccountBloc()), BlocProvider<AccountBloc>(create: (_) => AccountBloc(
initialStatus: AccountData().isPopulated() ? AccountStatus.loggedIn : AccountStatus.loggedOut,
)),
BlocProvider<BreakerBloc>(create: (_) => BreakerBloc()), BlocProvider<BreakerBloc>(create: (_) => BreakerBloc()),
BlocProvider<ChatListBloc>(create: (_) => ChatListBloc()), BlocProvider<ChatListBloc>(create: (_) => ChatListBloc()),
BlocProvider<ChatBloc>(create: (_) => ChatBloc()), BlocProvider<ChatBloc>(create: (_) => ChatBloc()),
@@ -4,7 +4,7 @@ import 'account_event.dart';
import 'account_state.dart'; import 'account_state.dart';
class AccountBloc extends Bloc<AccountEvent, AccountState> { class AccountBloc extends Bloc<AccountEvent, AccountState> {
AccountBloc() : super(const AccountState()) { AccountBloc({AccountStatus initialStatus = AccountStatus.undefined}) : super(AccountState(status: initialStatus)) {
on<AccountStatusChanged>((event, emit) => emit(state.copyWith(status: event.status))); on<AccountStatusChanged>((event, emit) => emit(state.copyWith(status: event.status)));
} }