firebase_cloud_messaging_backend 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new61

Send messages with Firebase Cloud Messaging from your dart backend!

Created using the HTTPv1 API of Firebase Cloud Messaging - you can find more on their website.

Not affiliated in any way with the official Firebase team or Google.

Usage #

Acquire required informations for the JWTClaim: Firebase > Project > Settings > Copy your project-id then go on: Settings > Service Accounts > Generate new key > Copy important informations directly from the created file or load it with JWTClaim.from(jsonFile)

A simple usage example:

import 'package:firebase_cloud_messaging_backend/firebase_cloud_messaging_backend.dart';

main() async{
  var server = FirebaseCloudMessagingServer(
      JWTClaim(
          client_email:
              "$clientEmail",
          client_id: "$clientId",
          private_key: authKey,
          private_key_id: "$privateKeyId"),
      "$projectId");

  var result = await server.send(Send(
      validate_only: false,
      message: Message(
          notification: Notification(
              title: "New content:", body: "John added something new!"),
          android: AndroidConfig(
              notification: AndroidNotification(
                  icon: "ic_notification", color: "#009999")),
          token: token)));
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.1 #

  • Changed readme
  • ran dartfmt on all files
  • No other code changes.

1.0.0 #

  • Initial version, minor things missing

example/firebase_cloud_messaging_backend_example.dart

import 'package:firebase_cloud_messaging_backend/firebase_cloud_messaging_backend.dart';

class Example {
  String clientEmail = "The email address of the service account";
  String clientId = "The id of the client";
  String authKey =
      "Your private key - warning: confidential. Use the complete .pem like content";
  String privateKeyId = "Your private key id";
  String projectId = "Your project id";
  String token = "The token of the device/user you want to send a message to";

  void main() async {
    var server = FirebaseCloudMessagingServer(
        JWTClaim(
            client_email: "$clientEmail",
            client_id: "$clientId",
            private_key: authKey,
            private_key_id: "$privateKeyId"),
        "$projectId");

    var result = await server.send(Send(
        validate_only: false,
        message: Message(
            notification: Notification(
                title: "New content:", body: "John added something new!"),
            android: AndroidConfig(
                notification: AndroidNotification(
                    icon: "ic_notification", color: "#009999")),
            token: token)));
    print(result.successful);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  firebase_cloud_messaging_backend: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:firebase_cloud_messaging_backend/firebase_cloud_messaging_backend.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
25
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
93
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:firebase_cloud_messaging_backend/firebase_cloud_messaging_backend.dart with components: io.

Health suggestions

Fix lib/src/FirebaseCloudMessagingServer.dart. (-0.50 points)

Analysis of lib/src/FirebaseCloudMessagingServer.dart reported 1 hint:

line 21 col 22: Use = to separate a named parameter from its default value.

Fix lib/src/logic/Send.dart. (-0.50 points)

Analysis of lib/src/logic/Send.dart reported 1 hint:

line 16 col 27: Use = to separate a named parameter from its default value.

Maintenance suggestions

The package description is too short. (-7 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
googleapis_auth ^0.2.10 0.2.10
http ^0.12.0+2 0.12.0+2
json_annotation ^3.0.0 3.0.0
json_serializable ^3.2.2 3.2.3
Transitive dependencies
analyzer 0.38.5
args 1.5.2
async 2.4.0
build 1.2.0
build_config 0.4.1+1
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.1
front_end 0.1.27
glob 1.1.7
html 0.14.0+3
http_parser 3.1.3
kernel 0.3.27
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
path 1.6.4
pub_semver 1.4.2
pubspec_parse 0.1.5
source_gen 0.9.4+5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner ^1.7.1
pedantic ^1.7.0 1.8.0+1
test ^1.6.0