最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Flutter web with firebase notifications - subscribeToTopic - Stack Overflow

programmeradmin2浏览0评论

I would like to receive firebase notifications in my flutter web app. I know that the firebase_messaging package is not available for web. But I've already managed configure my app to get a token, receive and display a message when the web app is in the backgroud and to receive (but not yet display a message) when the app is in the foreground.

I did so by creating JavaScripts (and service workers) as described here:

/@rody.davis.jr/how-to-send-push-notifications-on-flutter-web-fcm-b3e64f1e2b76

The problem is that so far I've only managed to sent the messages to 'a specific token' or 'to everyone' and I need to send messages to a 'specific topic'.

The documentation for cloud messages to specic topics with JS contiues here:

But the problem is that in this part the codes are no longer placed in the index.html file as before. (It's either node.js, java, python, Go or C#)

And I do not know how to implement that in my flutter web app. Is it even possible?

This is the part that I would like to add to my flutter web app:

I would like to receive firebase notifications in my flutter web app. I know that the firebase_messaging package is not available for web. But I've already managed configure my app to get a token, receive and display a message when the web app is in the backgroud and to receive (but not yet display a message) when the app is in the foreground.

I did so by creating JavaScripts (and service workers) as described here:

https://medium./@rody.davis.jr/how-to-send-push-notifications-on-flutter-web-fcm-b3e64f1e2b76

https://firebase.google./docs/cloud-messaging/js/client

https://firebase.google./docs/cloud-messaging/js/receive

The problem is that so far I've only managed to sent the messages to 'a specific token' or 'to everyone' and I need to send messages to a 'specific topic'.

The documentation for cloud messages to specic topics with JS contiues here: https://firebase.google./docs/cloud-messaging/js/topic-messaging

But the problem is that in this part the codes are no longer placed in the index.html file as before. (It's either node.js, java, python, Go or C#)

And I do not know how to implement that in my flutter web app. Is it even possible?

This is the part that I would like to add to my flutter web app:

Share Improve this question asked Nov 10, 2020 at 12:19 Daniel Cardoso IsharaDaniel Cardoso Ishara 731 silver badge4 bronze badges 1
  • On an initial analysis, the flutterfire site mentions there is no cloud messaging support for flutter web yet. Check here – Abhilash Chandran Commented Nov 10, 2020 at 12:48
Add a ment  | 

2 Answers 2

Reset to default 8

The JavaScript SDK for Firebase Cloud Messaging does not support subscribing to topics, which unfortunately that Flutter for web also doesn't/won't have it.

This means that a web app cannot subscribe itself to topics, like Android and iOS apps can. Instead, for web apps, you will have to use a server-side SDK to subscribe to a topic.

So you'll need to:

  1. Create a custom server-side API that uses one of the Admin SDKs, or the REST API, to subscribe a specific FCM device token to a specific topic. This code needs to run on a trusted environment, such as your development machine, a server that you control, or Cloud Functions.
  2. You then call this custom API from within your Flutter application.

Also see:

  • How to subscribe to topics with web browser using Firebase Cloud Messaging
  • Web Firebase Cloud Messaging - How to subscribe to a topic from client side?

While an answer has been given, I would like to point out that when using Flutter, use the flutter firebase package rather than the javascript SDK. The flutter package allows you to register and unregister the user from a topic directly from Flutter, rather than dealing with the server side SDK

发布评论

评论列表(0)

  1. 暂无评论