d2d_notifications 1.0.1+1 copy "d2d_notifications: ^1.0.1+1" to clipboard
d2d_notifications: ^1.0.1+1 copied to clipboard

Send Firebase Notification to any device, let it be any FCM Token or Topic Subscription

D2D Notifications #

Using Firebase Cloud for entire application and no Custom Server? Ever wanted to send a notification from client side (user app)? D2D Notification is a one stop solution to trigger / send FCM Push Notification, from one device to another device (D2D), without any server.

Platform Support #

This plugin is only used to trigger / send a notification request over HTTP. It does not handle any actions regarding the Firebase Messaging (receiving push notification).

Android iOS MacOS Web Linux Windows
Send from ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

Usage #

To use this plugin, add d2d_notifications as a dependency in your pubspec.yaml file.

Initialise the d2d_notification service by providing serverKey.

void main() {
	WidgetsFlutterBinding.ensureInitialized();
	D2DNotification(serverKey: "YOUR_SERVER_KEY"); // Add this line in main().
	runApp(const MyApp());
}

Generate request parameters for notification.

Parameter "to" can include either a TOPIC or FCM TOKEN

Firebase provides us a concept of Topics. Every subscriber of that particular topic, will be able to receive notification send for that particular topic.

Topic Example Consider a user is subscribed to a topic named "dogs"

D2DNotificationRequest request = D2DNotificationRequest(  
  to: "dogs",
  title: "This is title",
  subtitle: "This is subtitle",
  body: "This is body",
  imageUrl: "https://picsum.photos/200/300",
  data: {
    "key 1" : value1,
    ...
    "key 2" : "value2"
  },
);  
// Send notification request & receive response.
D2DNotificationTopicResponse? response = await D2DNotification.instance.sendNotificationToTopic(request);  
if(response != null) {  
  print("Notification sent successfully. ${response.messageId}");  
}

On every fresh install of your application, firebase generates a FCM token that is specific to that particular instance of app in user's device. To target a single user, you may use this. You will need the FCM Token for that user's application instance.

Token Example Consider a user has FCM token as "xyz"

D2DNotificationRequest request = D2DNotificationRequest(  
  to: "xyz",
  title: "This is title",
  subtitle: "This is subtitle",
  body: "This is body",
  imageUrl: "https://picsum.photos/200/300",
  data: {
    "key 1" : value1,
    ...
    "key 2" : "value2"
  },
);  
// Send notification request & receive response.
D2DNotificationTokenResponse? response = await D2DNotification.instance.sendNotificationToToken(request);  
if(response != null) {  
  print("Notification sent successfully. ${response.results}");  
}

Additional information #

This package is developed and maintained by AveoSoft Pvt Ltd. For any issues & improvements you can create an issue in Github Issues.

5
likes
100
pub points
41%
popularity

Publisher

unverified uploader

Send Firebase Notification to any device, let it be any FCM Token or Topic Subscription

Repository (GitLab)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, http

More

Packages that depend on d2d_notifications