US Office

1176 Shadeville Rd, Crawfordville Florida 32327, USA

 +1 (850) 780-1313

India Office

Office No 405, Kabir Shilp, Opp. Kansar Hotel, Opp. Landmark, Kudasan, Gandhinagar, Gujarat 382421

[email protected]

How to Get Firebase Token In Flutter??

How to Get Firebase Token In Flutter

How to Get Firebase Token In Flutter??

When users trying to send a notification from Rest Api using Firebase Admin SDK to the Flutter Application and it seems it requires a device token to send a notification. So in this article, we will go through How to Get Firebase Token In Flutter.

Are you ready for the same?

Let’s Drive through the same.

How to Get Firebase Token In Flutter??

Add this to your package’s pubspec.yaml file as shown here:

dependencies:
  firebase_messaging: ^6.0.16

You can install packages from the command line:

with Flutter like the below:

flutter pub get

Now in your file import package like the below:

import 'package:firebase_messaging/firebase_messaging.dart';

Implementation would be as the below snippet:

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
_firebaseMessaging.configure(
    onLaunch: (Map<String, dynamic> message) {
      print('onLaunch called');
    },
    onResume: (Map<String, dynamic> message) {
      print('onResume called');
    },
    onMessage: (Map<String, dynamic> message) {
      print('onMessage called');
    },
  );
  _firebaseMessaging.subscribeToTopic('all');
  _firebaseMessaging.requestNotificationPermissions(IosNotificationSettings(
    sound: true,
    badge: true,
    alert: true,
  ));
  _firebaseMessaging.onIosSettingsRegistered
      .listen((IosNotificationSettings settings) {
    print('Hello');
  });
  _firebaseMessaging.getToken().then((token) {
    print(token); // Print the Token in Console
  });
}

you can refer here, to know more about how to Integrate Push Notification For iOS In Flutter.

Conclusion:

So in this article, we have been through How to Get Firebase Token In Flutter.

Thanks for Reading !!! we hope you have learned well 🙂

Keep Learning !!! Keep Fluttering !!!

Do let us know if you need any assistance with Flutter Development. Don’t forget to drop your valuable feedback in the comments, It keeps us moving!

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

Comments
Post a Comment