js_notifications 0.0.1 copy "js_notifications: ^0.0.1" to clipboard
js_notifications: ^0.0.1 copied to clipboard

An extended NotificationsAPI for Dart Web notifications.

js_notifications #

An extended NotificationsAPI for Dart Web notifications.

Inspiration #

The Dart Web package is limited in showing notifications, one can only show a title, body, and icon. This package extends the NotificationsAPI to allow for more customization.

Setup #

Imports #

Add the following to your pubspec.yaml file:

dependencies:
  js_notifications: ^0.0.1

Copy service worker #

Copy the service worker file named js_notifications-sw.js from the example directory to your web directory. The name is very important, so make sure to have the file named js_notifications-sw.js.

Usage #

import the package #

import 'package:js_notifications/js_notifications.dart';

Grab instance #

final _jsNotificationsPlugin = JsNotificationsPlatform.instance;

Requesting permission #

_jsNotificationsPlugin.requestPermission().then((permission) {
  print(permission);
});

Creating a notification #

_jsNotificationsPlugin.showNotification('Title', {
    body: 'Body',
    icon: 'icon.png',
    badge: 'badge.png',
    image: 'image.png',
    tag: 'tag',
    data: {
      'key': 'value'
    },
  }
);

Handling notification click or close events #

_jsNotificationsPlugin.actionStream.listen((event) {
  print(event);
});

_jsNotificationsPlugin.dismissStream.listen((event) {
  print(event);
});
0
likes
0
points
233
downloads

Publisher

verified publisherearthbase.io

Weekly Downloads

An extended NotificationsAPI for Dart Web notifications.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on js_notifications