++++++++++++++++getFcm.dart+++++++++++++ Future<String?> getFcmToken() async { if(Platform.isIOS){ String? fcmKey = await FirebaseMessaging.instance.getToken(); return fcmKey; } String? fcmKey = await FirebaseMessaging.instance.getToken(); return fcmKey; } ++++++++++++++++++++++++++++++++++++++++ final CollectionReference _tokensCollection = FirebaseFirestore.instance.collection('users'); Future<void> saveFCMTokenToFirestore() async { // Get the FCM token String? fcmToken = await getFcmToken(); if (fcmToken != null) { // Create a document with the FCM token in Firestore await _tokensCollection.doc(globals.email).set({ 'token': fcmToken, 'tokenCreatedAt': FieldValue.serverTimestamp(), }); } else { print('Failed to retrieve FCM token'); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter