- Add firebase_core + firebase_messaging to pubspec.yaml - Initialize Firebase in main.dart before runApp - NotificationBloc: request permission, get FCM token, register with backend (PATCH /users/me/fcm-token), show local notification on foreground messages, refresh token on rotation - app_view.dart: call initializePushNotifications() on authenticated state Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
2.3 KiB
Dart
62 lines
2.3 KiB
Dart
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:injector/injector.dart';
|
|
import 'package:prosappco/app_view.dart';
|
|
import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart';
|
|
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
|
import 'package:prosappco/blocs/notification_bloc/notification_bloc.dart';
|
|
import 'package:prosappco/blocs/professional_bloc/professional_bloc.dart';
|
|
import 'package:prosappco/blocs/professional_profile_bloc/professional_profile_bloc.dart';
|
|
import 'package:prosappco/blocs/profile_bloc/profile_bloc.dart';
|
|
import 'package:prosappco/dependency/app_di.dart';
|
|
import 'package:prosappco/local_notifications/local_notifications.dart';
|
|
import 'simple_bloc_observer.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp();
|
|
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
|
|
|
|
// Inicializacion de notificaciones locales
|
|
await LocalNotifications.initializeLocalNotifications();
|
|
|
|
Bloc.observer = SimpleBlocObserver();
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
|
AppDI().register();
|
|
|
|
runApp(
|
|
MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider<AuthenticationBloc>(
|
|
create: (context) => Injector.appInstance.get<AuthenticationBloc>(),
|
|
),
|
|
BlocProvider<MyUserBloc>(
|
|
create: (context) => Injector.appInstance.get<MyUserBloc>(),
|
|
),
|
|
BlocProvider<ProfileBloc>(
|
|
create: (context) => Injector.appInstance.get<ProfileBloc>(),
|
|
),
|
|
BlocProvider<ProfessionalBloc>(
|
|
create: (context) => Injector.appInstance.get<ProfessionalBloc>(),
|
|
),
|
|
BlocProvider<ProfessionalProfileBloc>(
|
|
create: (context) =>
|
|
Injector.appInstance.get<ProfessionalProfileBloc>(),
|
|
),
|
|
BlocProvider<NotificationBloc>(
|
|
create: (context) => Injector.appInstance.get<NotificationBloc>(),
|
|
)
|
|
],
|
|
child: BlocBuilder<MyUserBloc, MyUserState>(
|
|
builder: (context, state) {
|
|
return const SafeArea(child: MyAppView());
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|