updateFCMToken method
Updates the user's FCM (Firebase Cloud Messaging) token.
This is used to enable push notifications for the user. It updates the token on the server and locally in the user object.
fcmToken
The new FCM token.
blockId
Optional block ID to associate with the FCM token.
Implementation
Future<bool> updateFCMToken(String fcmToken, {int? blockId}) async {
try {
await _apiService.updateFCMToken(fcmToken, blockId);
if (_user != null) {
_user = _user!.copyWith(
fcmToken: fcmToken,
fcmTokenUpdatedAt: DateTime.now(),
currentBlockId: blockId ?? _user!.currentBlockId,
);
await _saveUserData(_user!);
notifyListeners();
}
return true;
} catch (e) {
_setError(parseApiError(e.toString()));
return false;
}
}