firebase_fcm_client 0.1.1 copy "firebase_fcm_client: ^0.1.1" to clipboard
firebase_fcm_client: ^0.1.1 copied to clipboard

Server-side Firebase Cloud Messaging (FCM) HTTP v1 client for Dart with keyless runtime credentials and optional service account impersonation.

example/main.dart

import 'package:firebase_fcm_client/firebase_fcm_client.dart';

Future<void> main() async {
  print('🔔 FCM Notification Example\n');

  try {
    // Initialize with impersonation
    final auth = await ServiceAccountAuth.fromImpersonation(
      serviceAccountEmail: 'fcm-sa@YOUR_PROJECT.iam.gserviceaccount.com',
      projectId: 'YOUR_PROJECT_ID',
    );
    print('✅ Authenticated\n');

    final fcm = FCMClient(auth: auth, projectId: 'YOUR_PROJECT_ID');

    // Example 1: Send to device
    print('📤 Sending to device...');
    final result = await fcm.sendToToken(
      'YOUR_DEVICE_TOKEN',
      title: '🎉 Hello',
      body: 'This is a test notification',
      data: {
        'action': 'open_app',
        'timestamp': DateTime.now().toIso8601String(),
      },
    );
    print('✅ Sent: $result\n');

    // Example 2: Send to topic
    print('📤 Sending to topic...');
    final topicResult = await fcm.sendToTopic(
      'news',
      title: '📢 News Update',
      body: 'Important announcement',
    );
    print('✅ Sent: $topicResult\n');

    await auth.close();
    print('✨ Examples completed!');
  } catch (e) {
    print('❌ Error: $e');
  }
}
0
likes
160
points
1.04k
downloads

Documentation

API reference

Publisher

verified publisheraortem.io

Weekly Downloads

Server-side Firebase Cloud Messaging (FCM) HTTP v1 client for Dart with keyless runtime credentials and optional service account impersonation.

Repository (GitLab)
View/report issues

License

BSD-3-Clause (license)

Dependencies

ds_standard_features, googleapis_auth, json_annotation

More

Packages that depend on firebase_fcm_client