Skip to content

Instantly share code, notes, and snippets.

View k1ycee's full-sized avatar
👋
Say Hi

ThankGod Chiagozie k1ycee

👋
Say Hi
View GitHub Profile
async function sendNotification(token) {
try {
// Get custom token
const tokenResponse = await fetch('http://localhost:3000/api/send-notification', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ token })
});
const express = require('express');
const { sendNotification } = require('./firebase_admin');
const app = express();
app.use(express.json());
app.post('/api/send-notification', async (req, res) => {
try {
const { token } = req.body;
const admin = require('firebase-admin');
// Initialize Firebase Admin SDK
const serviceAccount = require('<your admin SDK path>');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
async function sendNotification(token) {
# Typically you should do this in a folder to keep it well structure
npm init -y
# Do this after you have done the initial
# This is to get the packages that will make up our backend
npm install express firebase firebase-admin
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
NotificationService.initialize();
runApp(
const MaterialApp(
home: Home(),
),
);
}
// Background message handler for Firebase Cloud Messaging (FCM)
// This function is triggered when a notification is received while the app is in the background or terminated.
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// Ensure Firebase is initialized before processing the message
await Firebase.initializeApp();
await NotificationService.setupFlutterNotifications();
// Display the notification
NotificationService.showFlutterNotification(message);
## Do this first
firbase login
## Do this and follow the prompt, it's really easy
flutterfire configure
import UIKit
import Flutter
import flutter_local_notifications
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
.....
dependencies {
@k1ycee
k1ycee / manifest.xml
Last active March 31, 2025 09:00
Notifications Manifiest
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<application
android:label="notification_test"