GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 lines
2.0 KiB

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import '../Screens/Settings/settings_screen.dart';
class LocalNotificationService{
static final FlutterLocalNotificationsPlugin _notificationsPlugin = FlutterLocalNotificationsPlugin();
static void initialize() {
// initializationSettings for Android
const InitializationSettings initializationSettings = InitializationSettings(
android: AndroidInitializationSettings("@mipmap/ic_launcher"),
);
_notificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse: (details) {
print("onSelectNotification");
var context;
Navigator.push(context as BuildContext, MaterialPageRoute(
builder: (context) => SettingsScreen()));
},
);
_notificationsPlugin.initialize(initializationSettings, onDidReceiveBackgroundNotificationResponse: (details) {
print("onSelectNotification-Background");
var context;
Navigator.push(context as BuildContext, MaterialPageRoute(
builder: (context) => SettingsScreen()));
},);
}
static void createanddisplaynotification(RemoteMessage message) async {
try {
final id = DateTime.now().millisecondsSinceEpoch ~/ 1000;
const NotificationDetails notificationDetails = NotificationDetails(
android: AndroidNotificationDetails(
"pushnotificationapp",
"pushnotificationappchannel",
//icon: "@mipmap/ic_launcher",
largeIcon: DrawableResourceAndroidBitmap('assets/images/sindi_icon.png'),
enableVibration: true,
importance: Importance.max,
priority: Priority.high,
),
);
await _notificationsPlugin.show(
id,
message.notification!.title,
message.notification!.body,
notificationDetails,
payload: message.data['_id'],
);
} on Exception catch (e) {
print(e);
}
}
}