Skip to content

Instantly share code, notes, and snippets.

@Monik09
Created Aug 24, 2021
Embed
What would you like to do?
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import '../notification_handler.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
NotificationHandler? _notificationHandler = NotificationHandler();
try {
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
} catch (e) {
print(e);
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
log("${message.data}");
if (message.data != null) {
log("hey");
_notificationHandler.firebaseMessagingForegroundHandler(message);
}
});
runApp(MyApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment