mitchhymel / local_notifications

No longer in development -Flutter plugin for creating notifications
BSD 2-Clause "Simplified" License
108 stars 14 forks source link

Showing notification when app is open but when app is terminated not showing notifications #32

Open benyaminbeyzaie opened 3 years ago

benyaminbeyzaie commented 3 years ago

Here is my code:

  static const AndroidNotificationChannel channel =
      const AndroidNotificationChannel(
          id: 'ben',
          name: 'Default',
          description: 'Grant this app the ability to show notifications',
          importance: AndroidNotificationChannelImportance.HIGH);
//...

FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  static Future<void> _firebaseMessagingBackgroundHandler(
      RemoteMessage message) async {
        await LocalNotifications.createNotification(
        title: "Basic",
        content: "Notification",
        id: 0,
        actions: [
          NotificationAction(
            actionText: 'accept',
            callback: callBack,
            payload: 'accept',
            launchesApp: true,
          ),
          NotificationAction(
            actionText: 'reject',
            callback: callBack,
            payload: 'reject',
            launchesApp: false,
          ),
        ],
        androidSettings: new AndroidSettings(channel: channel));

    static callBack(String payload) {
    FlutterRingtonePlayer.stop();
  }

  }

I can't see the local notification when app is terminated or is in background!