How to show local push notifications when app is closed on terminated in Flutter

66 Views Asked by At

I want to show local push Notification in app and its working when app is open and if we close or terminate the app then notification is not showing.

I want to continue this process in background an showing the notification always.

Please suggest me some idea to solve this issue.

I am using this flutter plugin:-

flutter_local_notifications: 

And here is the code:-

class NotificationManager {
  final FlutterLocalNotificationsPlugin notificationsPlugin =
  FlutterLocalNotificationsPlugin();

  Future<void> initNotification() async {
    AndroidInitializationSettings initializationSettingsAndroid =
    const AndroidInitializationSettings('profile_logo');

    DarwinInitializationSettings initializationIos =
    DarwinInitializationSettings(
      requestAlertPermission: true,
      requestBadgePermission: true,
      requestSoundPermission: true,
      onDidReceiveLocalNotification: (id, title, body, payload) {},
    );
    InitializationSettings initializationSettings = InitializationSettings(
        android: initializationSettingsAndroid, iOS: initializationIos);
    await notificationsPlugin.initialize(
      initializationSettings,
      onDidReceiveNotificationResponse: (details) {},
    );
  }

  Future<void> simpleNotificationShow(String? title, String? body ) async {
    AndroidNotificationDetails androidNotificationDetails =
    const AndroidNotificationDetails('Channel_id', 'Channel_title',
        priority: Priority.high,
        importance: Importance.max,
        icon: 'profile_logo',
        channelShowBadge: true,
        largeIcon: DrawableResourceAndroidBitmap('profile_logo'));

    NotificationDetails notificationDetails =
    NotificationDetails(android: androidNotificationDetails);
    await notificationsPlugin.show(
        0, title , body, notificationDetails);
  }

}

Function calling :-

NotificationManager().simpleNotificationShow("Assign", _notArr![0].msgTxt.toString());
0

There are 0 best solutions below