showNotification static method
Shows a notification via "Notification API" of the browser.
Implementation
static Future<void> showNotification(
String title, {
String? dir,
String? body,
String? lang,
String? tag,
String? icon,
}) async {
final options = web.NotificationOptions();
if (dir != null) {
options.dir = dir;
}
if (body != null) {
options.body = body;
}
if (lang != null) {
options.lang = lang;
}
if (tag != null) {
options.tag = tag;
}
if (icon != null) {
options.icon = icon;
}
// TODO: `onSelectNotification` was used in `onclick` event in
// `Notification` body, however since now notifications are created
// by `ServiceWorker`, we have no control over it, so should implement
// a way to handle the click in `ServiceWorker`.
final web.ServiceWorkerRegistration registration =
await web.window.navigator.serviceWorker.ready.toDart;
await registration.showNotification(title, options).toDart;
}