Exception has occurred. _CastError (type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'String' in type cast)

Viewed 454

Am trying to get an FCM Token using

final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
const String firebaseCloudvapidKey = "MY_PUBLIC_KEY_IS_HERE";

_firebaseMessaging.getToken(vapidKey: firebaseCloudvapidKey).then((val) async {
        print('Token: ' + val);
});

This is the error i get whenever i run this flutter

Am using genymotion emulator and i don't know where the error is coming from please help me out and if you need more explanation tell me i will add to it

1 Answers

In print('Token: ' + val); the val here is a Map<dynamic, dynamic>. You need to access the key of they value you need. You can type print('Token: ' + $val); to see how it looks like.

Related