laravel_notify_fcm 3.2.0
laravel_notify_fcm: ^3.2.0 copied to clipboard
Laravel Notify for Firebase Cloud Messaging (FCM) - Send push notifications to your Flutter app from Laravel.
Laravel Notify Fcm #
Laravel Notify Fcm is a package for sending notifications to your Flutter app using Laravel FCM.
Getting started #
Installation #
Add the following to your pubspec.yaml file:
dependencies:
laravel_notify_fcm: ^3.2.0
or with Dart:
dart pub add laravel_notify_fcm
Requirements #
Usage #
import 'package:laravel_notify_fcm/laravel_notify_fcm.dart';
Adding a device to the database #
First, call init to initialize the package.
Parameters:
url- The URL to your Laravel app where the package will send the device token.debugMode- Whether to enable debug mode. The default isfalse.
await LaravelNotifyFcm.instance.init(
url: 'https://example.com/api/fcm',
);
Then, call storeFcmDevice to register the device with your Laravel backend.
Parameters:
fcmToken- The FCM token fromFirebaseMessaging.instance.getToken().sanctumToken- A valid Laravel Sanctum token for the authenticated user.
String? fcmToken = await FirebaseMessaging.instance.getToken();
await LaravelNotifyFcm.storeFcmDevice(
fcmToken,
sanctumToken: 'from your Laravel user',
);
This will send the device token and metadata to your Laravel backend via a PUT /device request.
View our docs on Laravel FCM Channel to start sending notifications.
Try the example app to see how it works.
Accessing device metadata #
After init, you can read the current device metadata either as a typed object or as a JSON map.
// Typed DeviceMeta object — direct field access
DeviceMeta meta = LaravelNotifyFcm.instance.getDeviceMeta();
print(meta.uuid);
print(meta.model);
// Or as a plain Map<String, dynamic>
Map<String, dynamic> metaJson = LaravelNotifyFcm.instance.getDeviceMetaJson();
Both throw LaravelNotifyFcmNotInitializedException if called before init.
Changelog #
Please see CHANGELOG for more information what has changed recently.
Social #
Licence #
The MIT License (MIT). Please view the License File for more information.