showNotificationWithActions static method
Show notification with action buttons
Parameters:
title: Notification title (required)message: Notification message/body (required)actions: List of action button labels (required)onActionClick: Callback with action index when button is clickedonClick: Callback when notification body is clicked
Example:
await UnifiedNotificationService.showNotificationWithActions(
title: 'Confirm Action',
message: 'Do you want to continue?',
actions: ['Yes', 'No', 'Later'],
onActionClick: (index) {
if (index == 0) print('User clicked Yes');
else if (index == 1) print('User clicked No');
else print('User clicked Later');
},
);
Implementation
static Future<void> showNotificationWithActions({
required String title,
required String message,
required List<String> actions,
Function(int)? onActionClick,
VoidCallback? onClick,
}) async {
if (!_isInitialized) {
if (kDebugMode) {
print(
'UnifiedNotificationService: Not initialized. Call initialize() first.',
);
}
return;
}
try {
if (_isDesktopPlatform()) {
// Use local_notifier for desktop
// Uncomment when local_notifier is added
// LocalNotification notification = LocalNotification(
// title: title,
// body: message,
// actions: actions.map((action) =>
// LocalNotificationAction(text: action)
// ).toList(),
// );
//
// if (onClick != null) {
// notification.onClick = onClick;
// }
//
// if (onActionClick != null) {
// notification.onClickAction = onActionClick;
// }
//
// await notification.show();
if (kDebugMode) {
print(
'UnifiedNotificationService: Desktop notification with actions - $title',
);
}
} else {
// Use notification_master for mobile/web
await _notificationMaster.showNotificationWithActions(
title: title,
message: message,
actions: actions
.asMap()
.entries
.map(
(entry) => {
'title': entry.value,
'route': '/action_${entry.key}',
},
)
.toList(),
);
}
} catch (e) {
if (kDebugMode) {
print('UnifiedNotificationService: Failed to show notification: $e');
}
}
}