-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter Web support #481
Comments
Not likely at this stage. I looked at how the notifications API works on the web and every callback is tied to each instance of a notification so the model is quite different. It looked like the only thing that can be done is to show a notification immediately i.e. there's no way to schedule a notification. As such a developers would most likely need to put a guard in their code when running if web support was provided in the plugin. This leads me to think there isn't much value in providing web support through this plugin as you could use the notifications API directly via Dart with full functionality and in a similar manner if the plugin were to support. Could be I missed seeing a use case for adding it the plugin so happy to be persuaded but note that web support would need contributions from others. |
Thanks for the response. Admittedly, I have not looked into what it would take. I can think of a few "clever" things that could be done (such as using I think having at least partial support for notifications in web would be worthwhile - especially the instant notifications. The most fundamental use case I can think of is communication systems where the app may notify a user whenever they receive new communication. Having a guard in place for detecting whether or not certain features are in place is not uncommon in the web, anyway. Feature detection is kind of a fact of life when running on many platforms. In fact, this library already has some Android-only and iOS-only things that need to be addressed by the user, so I do not think that is going to be a huge concern. The added benefit, however, is a consistent API for the features that are available across multiple platforms. There would just need to be solid documentation for what is available on which platforms. As for getting it done, I have never written a Flutter plugin before, and I am admittedly new to Flutter and the ecosystem in general. However, since it is likely I will have to find a way to support web notifications for my project anyway (it is for work, so if it is a requirement then I have no choice) I figure I might as well do it in a way others can benefit from, as well. |
I am using this in web it works fine...is there any enhancement needed in this ? @MaikuB |
@hiashutoshsingh i'm not sure how you are using this plugin on the web when it doesn't support it to begin with. |
Regarding the scheduling just use hive with a timer |
Any updates? |
It is definitely not working on web, getting this error |
Even if you dont intend to support web, could you make sure the package does not break the app if it is compiled to web? https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html |
It´s really strange, because this new verions of firebase cloud messaging uses this plugin and it´s tagged to work with 'web': |
Can you try taking the PWA and “Add to homescreen “ so that it runs in the OS webview. It’s available in all browsers on desktop and mobile. It will elevate the privileges to allow it to work perhaps. also seen it do the opposite too with some things like MediaScreen for Video capture. depend on OS your using for desktop and mobile too. |
Can you link all the way down to show it being imported ? |
|
Yes, I am doing the same in the app code, howerver, the issue seems to be coming from how flutter_local_notifications checks for the platform as per
Flutter web does not yet support Platform, so kIsWeb should be checked first until dart / Flutter gets this right I guess :) (as per https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html |
At least fix the flutter web crash, it's been months. |
PLease fix this issue by using https://pub.dev/packages/universal_platform instead of dart.io for Platform.operatingSystem |
Hey everyone, i've also been doing some work with native browser notifications for a flutter web app and here's how i solved it. Dart provides via the notification class of dart:html a direct implementation of the notification api which is normally called by javascript (https://api.dart.dev/stable/2.16.1/dart-html/Notification-class.html). So I check in the code if the app is currently running in a browser and if so I use For me this works great and I thought maybe this can help some of you when you want to display notifications in the browser. |
@morzan1001 Nice find! didn't know Dart has support for this. I believe this would make a web implementation easier though if it's going to map to the APIs that the plugin supports, it looks like a web implementation should only cover scenarios when a notification needs to be shown instantly. Having said that, I believe the web spec for notifications has more functionality that isn't available. For example, being able to specify the vibration pattern via the constructor seems to be missing but a read-only property exists |
@MaikuB I'm curious, as of today does this package still break a web build during compilation - even if the API's are not explicitly called in a web build? I would like to include this for my iOS and Android builds, but since we want to also (at least partially) support the web - it would be nice to know this doesn't break things completely. |
@mikhael28 I am using this and web compiles fine. Didn't do anything special myself. That might have been fixed already. @morzan1001 thanks for sharing! Any chance you explored scheduling notifications? Not sure web supports it, but if there's a way to use ServiceWorkers in flutter, one might be able to use that along the Notifications API to implement scheduling. Maybe. Anyhow, I'd love to see a snippet of how you implemented web notifications alongside using |
@mikhael28 this was fixed a while back |
@MaikuB alright great, thank you! |
Any update on the Web support implementation? |
@loic-hamdi if you read the thread, you will see there is some basic support - it looks like you need to request notification permissions first. |
having support for Web (PWA) would be great. also looks like there is some good notifiication support in PWA https://stackoverflow.com/a/56435090/5525799 |
duo xie maiku |
Any updates on this? |
Any updates or progress ? Thank you |
I have submitted a feature request regarding Service Worker. I believe we can move this issue forward once the feature is added. |
@MaikuB I'm curious about this now as I've picked up some more Flutter web projects. As far as I can tell, we can support:
Of course, let flutter_sw = await navigator.serviceWorker.getRegistration();
if (flutter_sw != null) flutter_sw.unregister();
let plugin_sw = await navigator.serviceWorker.register("/flutter_local_notifications_sw.js"); Where our custom service worker can start off as simple as function _handleNotif(event) {
console.log(`Clicked: ${event}`);
clients.openWindow("/you-clicked-on-a-notification");
}
self.addEventListener("notificationclick", _handleNotif); Where of course we'd add more to pass the details of the notification into the Flutter app, and let the plugin pull the data. What do you think? |
From more research, it seems this is a viable option. I'm not guaranteeing I have time now, but since I'm interested, I started a branch to get some testing going. So far, I've managed to:
I'll keep making progress using the approach I described above, and I've started a draft PR at #2466 for anyone to follow and subscribe to. The branch may change at any time, but if you'd like to play around or try it out, feel free to do so. |
Are there plans to support Flutter Web at any point? There is a Notification API in JavaScript, so I imagine it is possible.
The text was updated successfully, but these errors were encountered: