initFirebase static method
dynamic
initFirebase({
- FirebaseOptions? options,
- dynamic onMessage(
- RemoteMessage message
- dynamic onMessageOpenedApp(
- RemoteMessage message
Implementation
static initFirebase({
FirebaseOptions? options,
Function(RemoteMessage message)? onMessage,
Function(RemoteMessage message)? onMessageOpenedApp,
}) async {
await Firebase.initializeApp(
options: options,
);
FirebaseMessaging messaging = FirebaseMessaging.instance;
await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
handleNotification(message);
if (onMessage != null) {
onMessage(message);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
if (onMessageOpenedApp != null) {
onMessageOpenedApp(message);
}
});
}