updateFcmToken static method
- String token
Update FCM token in Firestore This method updates the user's FCM token in Firestore @param token The FCM token to update @return void
Implementation
static void updateFcmToken(String token) {
try {
final userId = Get.find<AuthenticationRepository>().getUserID;
if (userId.isNotEmpty) {
final doc = FirebaseFirestore.instance.collection('users').doc(userId);
doc.set({
'fcmToken': token,
'tokenUpdatedAt': FieldValue.serverTimestamp(),
'platform': Platform.isIOS ? 'ios' : 'android',
}, SetOptions(merge: true));
if (kDebugMode) {
print("FCM token updated successfully for user: $userId");
}
} else {
if (kDebugMode) {
print("User ID is empty. Cannot update FCM token.");
}
}
} catch (e) {
if (kDebugMode) {
print("Error updating FCM token: $e");
}
}
}