0

I want to show notification based on a condition. I tried with flutter local notification package but I was only getting the foreground and background notification. if I close the app i was not having any notification from app.

example:

app is fetching the data from real-time-database firebase and data base is getting the frequency value from hardware, if frequency is greater than 50 then show notification.

if there is any another way to implement, you can also suggest me that

part of the code:

NotificationService notificationsServices = NotificationService();

 void initState(){
    super.initState();
    notificationsServices.intializeNotification();
}

if(_displayTemp>135 || _displayVib>135)
 {
       notificationsServices.sendN("Alert", _displayMsg);
}

class NotificationService {

  final FlutterLocalNotificationsPlugin flutterNotificationsPlugin = FlutterLocalNotificationsPlugin();

  final AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('shield');

  void intializeNotification() async {
    InitializationSettings initializationSettings= InitializationSettings(
      android: initializationSettingsAndroid
    );

    await flutterNotificationsPlugin.initialize(initializationSettings);

  }

  void sendN(String title,String body) async {

    AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails(
        'channelId 2',
        'channelName',
        importance: Importance.max,
        priority: Priority.high,
        playSound: true,
        //ongoing: true
    );

    NotificationDetails notificationDetails = NotificationDetails(
      android: androidNotificationDetails,
    );

    await flutterNotificationsPlugin.show(
        0,
        title,
        body,
        notificationDetails
    );
  }
}
James Z
  • 12,209
  • 10
  • 24
  • 44
Jam es
  • 9
  • 3
  • Does this answer your question? [Firebase push notifications callback doesn't work when app is terminated](https://stackoverflow.com/questions/66982532/firebase-push-notifications-callback-doesnt-work-when-app-is-terminated) – Shashank Gb Sep 30 '22 at 17:27

0 Answers0