Update: 2026-07-23 22:14:10
This commit is contained in:
@@ -66,6 +66,27 @@ class NotificationController extends GetxController {
|
||||
id: 0, title: title, body: message, notificationDetails: details);
|
||||
Log.print('Notification shown: $title - $message');
|
||||
}
|
||||
|
||||
// 🆕 Static method for background isolates where GetX might not be initialized
|
||||
static Future<void> showBackgroundNotification(String title, String message, String tone) async {
|
||||
final FlutterLocalNotificationsPlugin plugin = FlutterLocalNotificationsPlugin();
|
||||
const AndroidInitializationSettings android = AndroidInitializationSettings('@mipmap/launcher_icon');
|
||||
const DarwinInitializationSettings ios = DarwinInitializationSettings();
|
||||
await plugin.initialize(settings: const InitializationSettings(android: android, iOS: ios));
|
||||
|
||||
final AndroidNotificationDetails androidDetails = AndroidNotificationDetails(
|
||||
'high_importance_channel',
|
||||
'High Importance Notifications',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
showWhen: false,
|
||||
sound: RawResourceAndroidNotificationSound(tone),
|
||||
);
|
||||
const DarwinNotificationDetails iosDetails = DarwinNotificationDetails(sound: 'default');
|
||||
|
||||
await plugin.show(id: 0, title: title, body: message, notificationDetails: NotificationDetails(android: androidDetails, iOS: iosDetails));
|
||||
Log.print('Background notification shown: $title - $message');
|
||||
}
|
||||
// /Users/hamzaaleghwairyeen/development/App/ride 2/lib/controller/firebase/local_notification.dart
|
||||
|
||||
// Assume _flutterLocalNotificationsPlugin is initialized somewhere in your code
|
||||
|
||||
Reference in New Issue
Block a user