// import 'package:firebase_messaging/firebase_messaging.dart';

// class FirebaseApi {
//   final _firebaseMessaging = FirebaseMessaging.instance;

//   Future<void> initNotification() async {
//     await _firebaseMessaging.requestPermission();
//     final fcmToken = await _firebaseMessaging.getToken();
//     print('Token Firebase: $fcmToken');
//   }
// }
import 'package:firebase_messaging/firebase_messaging.dart';

class NotificationHandler {
  final FirebaseMessaging _fcm = FirebaseMessaging.instance;

  Future<void> init() async {
    // Request izin untuk menerima notifikasi (opsional)
    await _fcm.requestPermission();

    // Listen untuk menerima notifikasi ketika aplikasi berjalan
    FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
      await _fcm.requestPermission();
      final fcmToken = await _fcm.getToken();
      print("Token Firebase: $fcmToken");
      print("Received message: ${message.notification?.title}");
      print("Received message body: ${message.notification?.body}");
    });
  }
}
