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.

57 lines
2.0 KiB

2 months ago
  1. import 'package:firebase_messaging/firebase_messaging.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_local_notifications/flutter_local_notifications.dart';
  4. import '../Screens/Settings/settings_screen.dart';
  5. class LocalNotificationService{
  6. static final FlutterLocalNotificationsPlugin _notificationsPlugin = FlutterLocalNotificationsPlugin();
  7. static void initialize() {
  8. // initializationSettings for Android
  9. const InitializationSettings initializationSettings = InitializationSettings(
  10. android: AndroidInitializationSettings("@mipmap/ic_launcher"),
  11. );
  12. _notificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse: (details) {
  13. print("onSelectNotification");
  14. var context;
  15. Navigator.push(context as BuildContext, MaterialPageRoute(
  16. builder: (context) => SettingsScreen()));
  17. },
  18. );
  19. _notificationsPlugin.initialize(initializationSettings, onDidReceiveBackgroundNotificationResponse: (details) {
  20. print("onSelectNotification-Background");
  21. var context;
  22. Navigator.push(context as BuildContext, MaterialPageRoute(
  23. builder: (context) => SettingsScreen()));
  24. },);
  25. }
  26. static void createanddisplaynotification(RemoteMessage message) async {
  27. try {
  28. final id = DateTime.now().millisecondsSinceEpoch ~/ 1000;
  29. const NotificationDetails notificationDetails = NotificationDetails(
  30. android: AndroidNotificationDetails(
  31. "pushnotificationapp",
  32. "pushnotificationappchannel",
  33. //icon: "@mipmap/ic_launcher",
  34. largeIcon: DrawableResourceAndroidBitmap('assets/images/sindi_icon.png'),
  35. enableVibration: true,
  36. importance: Importance.max,
  37. priority: Priority.high,
  38. ),
  39. );
  40. await _notificationsPlugin.show(
  41. id,
  42. message.notification!.title,
  43. message.notification!.body,
  44. notificationDetails,
  45. payload: message.data['_id'],
  46. );
  47. } on Exception catch (e) {
  48. print(e);
  49. }
  50. }
  51. }