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

Firebase Cloud Messaging (FCM) HTTP v1 API client for Dart with secure service account impersonation. Send notifications to devices, topics, and conditions without managing private keys.

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
130
points
40
downloads

Publisher

unverified uploader

Weekly Downloads

Firebase Cloud Messaging (FCM) HTTP v1 API client for Dart with secure service account impersonation. Send notifications to devices, topics, and conditions without managing private keys.

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

ds_standard_features, googleapis_auth, json_annotation

More

Packages that depend on firebase_fcm_client