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 = [
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user