wait for account data population and set initial AccountBloc status
This commit is contained in:
+11
-2
@@ -43,7 +43,7 @@ Future<void> main() async {
|
||||
|
||||
final initialisationTasks = [
|
||||
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')),
|
||||
PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem').then(addCertificateAsTrusted),
|
||||
PlatformAssetBundle().load('assets/ca/lets-encrypt-r10.pem').then(addCertificateAsTrusted),
|
||||
@@ -54,12 +54,19 @@ Future<void> main() async {
|
||||
);
|
||||
HydratedBloc.storage = storage;
|
||||
}),
|
||||
AccountData().waitForPopulation(),
|
||||
];
|
||||
|
||||
log('starting app initialisation...');
|
||||
await Future.wait(initialisationTasks);
|
||||
log('app initialisation done!');
|
||||
|
||||
unawaited(
|
||||
FirebaseMessaging.instance.getToken().then(
|
||||
(token) => log('Firebase token: ${token ?? "Error: no Firebase token!"}'),
|
||||
),
|
||||
);
|
||||
|
||||
if (kReleaseMode) {
|
||||
ErrorWidget.builder = (error) => PlaceholderView(
|
||||
icon: Icons.phonelink_erase_rounded,
|
||||
@@ -83,7 +90,9 @@ Future<void> main() async {
|
||||
MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider<SettingsCubit>(create: (_) => SettingsCubit()),
|
||||
BlocProvider<AccountBloc>(create: (_) => AccountBloc()),
|
||||
BlocProvider<AccountBloc>(create: (_) => AccountBloc(
|
||||
initialStatus: AccountData().isPopulated() ? AccountStatus.loggedIn : AccountStatus.loggedOut,
|
||||
)),
|
||||
BlocProvider<BreakerBloc>(create: (_) => BreakerBloc()),
|
||||
BlocProvider<ChatListBloc>(create: (_) => ChatListBloc()),
|
||||
BlocProvider<ChatBloc>(create: (_) => ChatBloc()),
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'account_event.dart';
|
||||
import 'account_state.dart';
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user