Home > Mobile >  How to get the device token in flutter
How to get the device token in flutter

Time:06-23

I'm trying to get the device token, for this i'm using FirebaseMessaging. here is my code to get the token.

@override
  void initState()  {
 FirebaseMessaging? _firebaseMessaging;
 _firebaseMessaging?.getToken().then((token){
      print("token is $token");
});
}


but it print nothing. Please help how to do this.

CodePudding user response:

You have to create the FirebaseMessaging instance. Change to:

@override
  void initState()  {
    FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance; // Change here
    _firebaseMessaging.getToken().then((token){
      print("token is $token");
  });
}
  • Related