I am creating a flutter app which is in link with a woocommerce wordpress site. I want to get a push notification whenever new products are added

Viewed 22

I have tried using firebase notification scheduling like this and its not working.This is the function code I used for sending a custom notification and even this is not working.Is there any errors or is there any alternative ways

  void sendNotification()async{
        await Firebase.initializeApp();
        String? fcmToken = await FirebaseMessaging.instance.getToken();
        print(fcmToken);
        final FirebaseNotificationScheduler firebaseNotificationScheduler =
        FirebaseNotificationScheduler(
            authenticationKey: 'NTQ5YzA0MjYtZGRjMS00NTliLTllYjYtMDk4YzZhNzliOTgwOktJMDZMTEVpSGNRWjB2Qlk2RXJaazNKclpRZC9IOUc=',
            rapidApiKey: '4e30d77a63msh5302f3fec95c880p1548e5jsn43509ee88c2d');
        final String _payload = {
          "to": fcmToken,
          "notification": {
            "title": "Title of Your Notification",
            "body": "Body of Your Notification"
          },
          "data": {"key_1": "Value for key_1", "key_2": "Value forkey_2"}
        }.toString();
        final DateTime _now = DateTime.now().toUtc();
        final DateTime _dateTimeInUtc = _now.add(const Duration(minutes: 1));
        final response = await firebaseNotificationScheduler.scheduleNotification(
            payload: _payload, dateTimeInUtc: _dateTimeInUtc);
        print("response = $response");
      }
0 Answers
Related