showNotification static method
Future<void>
showNotification({
- required String title,
- required String message,
- String? subtitle,
- bool silent = false,
- VoidCallback? onClick,
- VoidCallback? onShow,
- dynamic onClose()?,
Show a simple notification on any platform
Parameters:
title: Notification title (required)message: Notification message/body (required)subtitle: Notification subtitle (optional, macOS only)silent: Whether notification should be silent (default: false)onClick: Callback when notification is clicked (desktop only)onShow: Callback when notification is shown (desktop only)onClose: Callback when notification is closed (desktop only)
Example:
await UnifiedNotificationService.showNotification(
title: 'New Message',
message: 'You have a new message from John',
onClick: () => print('Notification clicked'),
);
Implementation
static Future<void> showNotification({
required String title,
required String message,
String? subtitle,
bool silent = false,
VoidCallback? onClick,
VoidCallback? onShow,
Function(String)? onClose,
}) async {
if (!_isInitialized) {
if (kDebugMode) {
print(
'UnifiedNotificationService: Not initialized. Call initialize() first.',
);
}
return;
}
try {
if (_isDesktopPlatform()) {
// Use local_notifier for desktop
await _showDesktopNotification(
title: title,
body: message,
subtitle: subtitle,
silent: silent,
onClick: onClick,
onShow: onShow,
onClose: onClose,
);
} else {
// Use notification_master for mobile/web
await _notificationMaster.showNotification(
title: title,
message: message,
);
}
} catch (e) {
if (kDebugMode) {
print('UnifiedNotificationService: Failed to show notification: $e');
}
}
}