FCM Token Sync

A widget which keeps your FCM token in sync with your backend

style: very good analysis Gitmoji Pub Version GitHub GitHub Workflow Status Coverage Status

✨ Features

  • Keeps your user's FCM tokens in sync with your backend
  • Automatically handles permission requests
  • 100% test coverage
  • Null-safety

🚀 Installation

Install from pub.dev:

fcm_token_sync: ^1.0.4

✅ Prerequisites

You should already have Firebase Cloud Messaging set up in your project. Go here for setup instructions.

Additionally, you will need to have built a way to send FCM tokens to your backend service.

🔨 Usage

This package contains a FcmTokenSync widget, which you can wrap around any widget in your project.

Some recommendations for usage:

  • Add this widget to your tree wherever you want to ask your user for notification permissions.
  • This will probably be after the user has registered and/or signed in.

Example

class HomePage extends StatelessWidget {
    const HomePage({Key? key}) : super(key: key);

    @override
    Widget build(BuildContext context) {
        return FcmTokenSync(
            firebaseMessaging: FirebaseMessaging.instance,
            onToken: _updateFcmToken,
            child: Scaffold(), // Widget to display here
        );
    }

    Future<void> _updateFcmToken(String token) async {
        // Send the updated token to your backend here.
    }
}

👨🏻‍💻 Authors

Libraries

fcm_token_sync