30 lines
1.2 KiB
Dart
30 lines
1.2 KiB
Dart
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class NotificationController extends GetxController {
|
|
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
|
FlutterLocalNotificationsPlugin();
|
|
|
|
// Initializes the local notifications plugin
|
|
Future<void> initNotifications() async {
|
|
const AndroidInitializationSettings android =
|
|
AndroidInitializationSettings('@mipmap/launcher_icon');
|
|
const InitializationSettings initializationSettings =
|
|
InitializationSettings(android: android);
|
|
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
|
}
|
|
|
|
// Displays a notification with the given title and message
|
|
void showNotification(String title, String message, String tone) async {
|
|
AndroidNotificationDetails android = AndroidNotificationDetails(
|
|
'high_importance_channel', 'High Importance Notifications',
|
|
importance: Importance.max,
|
|
priority: Priority.high,
|
|
showWhen: false,
|
|
sound: RawResourceAndroidNotificationSound(tone));
|
|
|
|
NotificationDetails details = NotificationDetails(android: android);
|
|
await _flutterLocalNotificationsPlugin.show(0, title, message, details);
|
|
}
|
|
}
|