2-10/3/1
This commit is contained in:
@@ -15,7 +15,7 @@ import '../home/captin/home_captain_controller.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');
|
||||
@@ -26,14 +26,13 @@ class NotificationController extends GetxController {
|
||||
await _flutterLocalNotificationsPlugin.initialize(
|
||||
initializationSettings,
|
||||
onDidReceiveNotificationResponse: onDidReceiveNotificationResponse,
|
||||
onDidReceiveBackgroundNotificationResponse:
|
||||
onDidReceiveBackgroundNotificationResponse,
|
||||
onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
|
||||
);
|
||||
|
||||
// Create a notification channel
|
||||
const AndroidNotificationChannel channel = AndroidNotificationChannel(
|
||||
'your channel id',
|
||||
'your channel name',
|
||||
'high_importance_channel', // Use the same ID as in strings.xml
|
||||
'High Importance Notifications',
|
||||
description: 'This channel is used for important notifications.',
|
||||
importance: Importance.high,
|
||||
);
|
||||
@@ -56,7 +55,8 @@ class NotificationController extends GetxController {
|
||||
);
|
||||
|
||||
AndroidNotificationDetails android = AndroidNotificationDetails(
|
||||
'high_importance_channel', 'High Importance Notifications',
|
||||
'high_importance_channel', // Use the same ID as before
|
||||
'High Importance Notifications',
|
||||
importance: Importance.high,
|
||||
priority: Priority.high,
|
||||
styleInformation: bigTextStyleInformation,
|
||||
@@ -94,17 +94,17 @@ class NotificationController extends GetxController {
|
||||
|
||||
// Callback when the notification is tapped
|
||||
void onDidReceiveNotificationResponse(NotificationResponse response) {
|
||||
_handleNotificationResponse(response);
|
||||
handleNotificationResponse(response);
|
||||
}
|
||||
|
||||
// Callback when the notification is tapped while the app is in the background
|
||||
void onDidReceiveBackgroundNotificationResponse(
|
||||
NotificationResponse response) {
|
||||
_handleNotificationResponse(response);
|
||||
handleNotificationResponse(response);
|
||||
}
|
||||
|
||||
// Handle notification response for both foreground and background
|
||||
void _handleNotificationResponse(NotificationResponse response) {
|
||||
void handleNotificationResponse(NotificationResponse response) {
|
||||
print('Notification tapped!');
|
||||
Log.print('response.payload: ${response.payload}');
|
||||
if (response.payload != null) {
|
||||
|
||||
Reference in New Issue
Block a user