You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void _handleMessageOpenedApp(Map<String, dynamic> message) {
debugPrint('App opened from Azure notification: $message');
// Handle app open from notification here
}
@OverRide
Future registerDevice() async {
try {
// First remove any existing tags to prevent duplicates
await unregisterDevice();
// Then add the tag
await AzureNotificationHub.instance.addTags(<String>[_allUsersTag]);
debugPrint('Successfully registered device with Azure Notification Hub');
} catch (e) {
debugPrint('Error registering Azure device: $e');
}
/// Local notification handler for displaying notifications
final class LocalNotificationHandler {
static LocalNotificationHandler? _instance;
static LocalNotificationHandler get instance => instance ??= LocalNotificationHandler.();
LocalNotificationHandler._();
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
const iosDetails = DarwinNotificationDetails(
presentAlert: true,
presentBadge: true,
presentSound: true,
);
const notificationDetails = NotificationDetails(
android: androidDetails,
iOS: iosDetails,
);
final String title = message['aps']?['alert']?['title'] ?? // iOS format
message['notification']?['title'] ?? // FCM notification payload
message['title'] ?? // Direct data payload
'New Notification';
final String body = message['aps']?['alert']?['body'] ?? // iOS format
message['notification']?['body'] ?? // FCM notification payload
message['body'] ?? // Direct data payload
'';
await _flutterLocalNotificationsPlugin.show(
DateTime.now().millisecond,
title,
body,
notificationDetails,
);
} catch (e) {
debugPrint('Error showing local notification: $e');
}
}
void _onLocalNotificationTapped(NotificationResponse details) {
debugPrint('Local notification tapped: ${details.payload}');
// Handle notification tap here
}
}
/// Main notification service that orchestrates all handlers
final class NotificationService {
static NotificationService? _instance;
static NotificationService get instance => instance ??= NotificationService.();
NotificationService._();
final _azureHandler = AzureNotificationHandler.instance;
final _localHandler = LocalNotificationHandler.instance;
Future initialize() async {
// Initialize handlers in sequence to ensure proper order
await _localHandler.initialize();
// await _firebaseHandler.initialize();
await _azureHandler.initialize();
// Register Azure device after initialization
await _azureHandler.registerDevice();
/// Azure Notification Hub implementation
final class AzureNotificationHandler implements NotificationHandler {
static AzureNotificationHandler? _instance;
static AzureNotificationHandler get instance => instance ??= AzureNotificationHandler.();
AzureNotificationHandler._();
final LocalNotificationHandler _localNotificationHandler = LocalNotificationHandler.instance;
static const String _allUsersTag = 'allUsers';
@OverRide
Future initialize() async {
try {
await AzureNotificationHub.instance.registerBackgroundMessageHandler(_azureBackgroundMessageHandler);
await AzureNotificationHub.instance.start();
}
void _handleMessage(Map<String, dynamic> message) {
debugPrint('Received Azure message: $message');
}
void _handleMessageOpenedApp(Map<String, dynamic> message) {
debugPrint('App opened from Azure notification: $message');
// Handle app open from notification here
}
@OverRide
Future registerDevice() async {
try {
// First remove any existing tags to prevent duplicates
await unregisterDevice();
}
@OverRide
Future unregisterDevice() async {
try {
await AzureNotificationHub.instance.removeTags([_allUsersTag]);
debugPrint('Successfully unregistered device from Azure Notification Hub');
} catch (e) {
debugPrint('Error unregistering Azure device: $e');
}
}
}
/// Local notification handler for displaying notifications
final class LocalNotificationHandler {
static LocalNotificationHandler? _instance;
static LocalNotificationHandler get instance => instance ??= LocalNotificationHandler.();
LocalNotificationHandler._();
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
Future initialize() async {
try {
const initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher');
const initializationSettingsIOS = DarwinInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
);
const initializationSettings = InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,
);
}
Future _requestIOSPermissions() async {
await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation()
?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
}
Future showNotification(Map<String, dynamic> message) async {
try {
const androidDetails = AndroidNotificationDetails(
'default_channel',
'Default Channel',
channelDescription: 'Default notification channel',
importance: Importance.max,
priority: Priority.high,
showWhen: true,
);
}
void _onLocalNotificationTapped(NotificationResponse details) {
debugPrint('Local notification tapped: ${details.payload}');
// Handle notification tap here
}
}
/// Main notification service that orchestrates all handlers
final class NotificationService {
static NotificationService? _instance;
static NotificationService get instance => instance ??= NotificationService.();
NotificationService._();
final _azureHandler = AzureNotificationHandler.instance;
final _localHandler = LocalNotificationHandler.instance;
Future initialize() async {
// Initialize handlers in sequence to ensure proper order
await _localHandler.initialize();
// await _firebaseHandler.initialize();
await _azureHandler.initialize();
}
Future unregisterDevice() async {
await Future.wait([
_firebaseHandler.unregisterDevice(),
_azureHandler.unregisterDevice(),
]);
}
}
@pragma('vm:entry-point')
Future _azureBackgroundMessageHandler(Map<String, dynamic> message) async {
log('Handling an Azure background message: $message');
// Add your Azure background message handling logic here
}
After I receive my function my local notifications burst out with tons of notifications why is this happening
The text was updated successfully, but these errors were encountered: