ChromeNotifications class
class ChromeNotifications extends ChromeApi { static final JsObject _notifications = chrome['notifications']; ChromeNotifications._(); bool get available => _notifications != null; /** * Creates and displays a notification. * [notificationId]: Identifier of the notification. If it is empty, this * method generates an id. If it matches an existing notification, this method * first clears that notification before proceeding with the create operation. * [options]: Contents of the notification. * [callback]: Returns the notification id (either supplied or generated) that * represents the created notification. */ Future<String> create(String notificationId, NotificationOptions options) { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<String>.oneArg(); _notifications.callMethod('create', [notificationId, jsify(options), completer.callback]); return completer.future; } /** * Updates an existing notification. * [notificationId]: The id of the notification to be updated. This is * returned by [notifications.create] method. * [options]: Contents of the notification to update to. * [callback]: Called to indicate whether a matching notification existed. */ Future<bool> update(String notificationId, NotificationOptions options) { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _notifications.callMethod('update', [notificationId, jsify(options), completer.callback]); return completer.future; } /** * Clears the specified notification. * [notificationId]: The id of the notification to be cleared. This is * returned by [notifications.create] method. * [callback]: Called to indicate whether a matching notification existed. */ Future<bool> clear(String notificationId) { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _notifications.callMethod('clear', [notificationId, completer.callback]); return completer.future; } /** * Retrieves all the notifications. * [callback]: Returns the set of notification_ids currently in the system. */ Future<dynamic> getAll() { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<dynamic>.oneArg(); _notifications.callMethod('getAll', [completer.callback]); return completer.future; } /** * Retrieves whether the user has enabled notifications from this app or * extension. * [callback]: Returns the current permission level. */ Future<PermissionLevel> getPermissionLevel() { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<PermissionLevel>.oneArg(_createPermissionLevel); _notifications.callMethod('getPermissionLevel', [completer.callback]); return completer.future; } Stream<OnClosedEvent> get onClosed => _onClosed.stream; final ChromeStreamController<OnClosedEvent> _onClosed = new ChromeStreamController<OnClosedEvent>.twoArgs(_notifications, 'onClosed', _createOnClosedEvent); Stream<String> get onClicked => _onClicked.stream; final ChromeStreamController<String> _onClicked = new ChromeStreamController<String>.oneArg(_notifications, 'onClicked', selfConverter); Stream<OnButtonClickedEvent> get onButtonClicked => _onButtonClicked.stream; final ChromeStreamController<OnButtonClickedEvent> _onButtonClicked = new ChromeStreamController<OnButtonClickedEvent>.twoArgs(_notifications, 'onButtonClicked', _createOnButtonClickedEvent); Stream<PermissionLevel> get onPermissionLevelChanged => _onPermissionLevelChanged.stream; final ChromeStreamController<PermissionLevel> _onPermissionLevelChanged = new ChromeStreamController<PermissionLevel>.oneArg(_notifications, 'onPermissionLevelChanged', _createPermissionLevel); void _throwNotAvailable() { throw new UnsupportedError("'chrome.notifications' is not available"); } }
Extends
ChromeApi > ChromeNotifications
Properties
final bool available #
Returns true if the API is available. The common causes of an API not being avilable are:
- a permission is missing in the application's manifest.json file
- the API is defined on a newer version of Chrome then the current runtime
bool get available => _notifications != null;
final Stream<OnButtonClickedEvent> onButtonClicked #
Stream<OnButtonClickedEvent> get onButtonClicked => _onButtonClicked.stream;
final Stream<String> onClicked #
Stream<String> get onClicked => _onClicked.stream;
final Stream<OnClosedEvent> onClosed #
Stream<OnClosedEvent> get onClosed => _onClosed.stream;
final Stream<PermissionLevel> onPermissionLevelChanged #
Stream<PermissionLevel> get onPermissionLevelChanged => _onPermissionLevelChanged.stream;
Methods
Future<bool> clear(String notificationId) #
Clears the specified notification.
notificationId: The id of the notification to be cleared. This is
returned by notifications.create
method.
callback
: Called to indicate whether a matching notification existed.
Future<bool> clear(String notificationId) { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _notifications.callMethod('clear', [notificationId, completer.callback]); return completer.future; }
Future<String> create(String notificationId, NotificationOptions options) #
Creates and displays a notification.
notificationId: Identifier of the notification. If it is empty, this
method generates an id. If it matches an existing notification, this method
first clears that notification before proceeding with the create operation.
options: Contents of the notification.
callback
: Returns the notification id (either supplied or generated) that
represents the created notification.
Future<String> create(String notificationId, NotificationOptions options) { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<String>.oneArg(); _notifications.callMethod('create', [notificationId, jsify(options), completer.callback]); return completer.future; }
Future<dynamic> getAll() #
Retrieves all the notifications.
callback
: Returns the set of notification_ids currently in the system.
Future<dynamic> getAll() { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<dynamic>.oneArg(); _notifications.callMethod('getAll', [completer.callback]); return completer.future; }
Future<PermissionLevel> getPermissionLevel() #
Retrieves whether the user has enabled notifications from this app or
extension.
callback
: Returns the current permission level.
Future<PermissionLevel> getPermissionLevel() { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<PermissionLevel>.oneArg(_createPermissionLevel); _notifications.callMethod('getPermissionLevel', [completer.callback]); return completer.future; }
Future<bool> update(String notificationId, NotificationOptions options) #
Updates an existing notification.
notificationId: The id of the notification to be updated. This is
returned by notifications.create
method.
options: Contents of the notification to update to.
callback
: Called to indicate whether a matching notification existed.
Future<bool> update(String notificationId, NotificationOptions options) { if (_notifications == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _notifications.callMethod('update', [notificationId, jsify(options), completer.callback]); return completer.future; }