Skip to content

Instantly share code, notes, and snippets.

@Monik09
Created August 24, 2021 13:22
Show Gist options
  • Save Monik09/b57104c243bd4b6f89138461bb62b2f0 to your computer and use it in GitHub Desktop.
Save Monik09/b57104c243bd4b6f89138461bb62b2f0 to your computer and use it in GitHub Desktop.
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