Files
blinds_flutter/lib/BlindMasterResources/fcm_service.dart

19 lines
786 B
Dart
Raw Normal View History

import 'package:blind_master/BlindMasterResources/secure_transmissions.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
class FcmService {
/// Request permission, fetch the FCM token, and register it with the server.
/// Safe to call on every login/session-restore — the server just upserts the value.
static Future<void> register() async {
try {
final messaging = FirebaseMessaging.instance;
await messaging.requestPermission(alert: true, badge: true, sound: true);
final token = await messaging.getToken();
if (token == null) return;
await securePost({'token': token}, 'register_fcm_token');
} catch (_) {
// Non-fatal — push notifications simply won't work until the next successful registration.
}
}
}