Dart API Referencedart:htmlNotification

Notification class

Mobile Only in Gecko 2.0

Available only in Firefox Mobile as of Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

Non-standard

The notification object, which you create using the navigator.mozNotification  object's createNotification() method, is used to configure and display desktop notifications to the user.

@DomName('Notification')
class Notification extends EventTarget native "Notification" {

 factory Notification(String title, {String titleDir: null, String body: null, 
     String bodyDir: null, String tag: null, String iconUrl: null}) {

   var parsedOptions = {};
   if (titleDir != null) parsedOptions['titleDir'] = titleDir;
   if (body != null) parsedOptions['body'] = body;
   if (bodyDir != null) parsedOptions['bodyDir'] = bodyDir;
   if (tag != null) parsedOptions['tag'] = tag;
   if (iconUrl != null) parsedOptions['iconUrl'] = iconUrl;

   return Notification._factoryNotification(title, parsedOptions);
 }

 @DomName('Notification.clickEvent')
 @DocsEditable
 static const EventStreamProvider<Event> clickEvent = const EventStreamProvider<Event>('click');

 @DomName('Notification.closeEvent')
 @DocsEditable
 static const EventStreamProvider<Event> closeEvent = const EventStreamProvider<Event>('close');

 @DomName('Notification.displayEvent')
 @DocsEditable
 static const EventStreamProvider<Event> displayEvent = const EventStreamProvider<Event>('display');

 @DomName('Notification.errorEvent')
 @DocsEditable
 static const EventStreamProvider<Event> errorEvent = const EventStreamProvider<Event>('error');

 @DomName('Notification.showEvent')
 @DocsEditable
 static const EventStreamProvider<Event> showEvent = const EventStreamProvider<Event>('show');

 @DomName('Notification.Notification')
 @DocsEditable
 static Notification _factoryNotification(String title, [Map options]) {
   if (?options) {
     return Notification._create_1(title, options);
   }
   return Notification._create_2(title);
 }
 static Notification _create_1(title, options) => JS('Notification', 'new Notification(#,#)', title, options);
 static Notification _create_2(title) => JS('Notification', 'new Notification(#)', title);

 @DomName('Notification.dir')
 @DocsEditable
 String dir;

 @DomName('Notification.permission')
 @DocsEditable
 final String permission;

 @DomName('Notification.replaceId')
 @DocsEditable
 String replaceId;

 @DomName('Notification.tag')
 @DocsEditable
 String tag;

 @JSName('addEventListener')
 @DomName('Notification.addEventListener')
 @DocsEditable
 void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) native;

 @DomName('Notification.cancel')
 @DocsEditable
 void cancel() native;

 @DomName('Notification.close')
 @DocsEditable
 void close() native;

 @DomName('Notification.dispatchEvent')
 @DocsEditable
 bool dispatchEvent(Event evt) native;

 @JSName('removeEventListener')
 @DomName('Notification.removeEventListener')
 @DocsEditable
 void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) native;

 @JSName('requestPermission')
 @DomName('Notification.requestPermission')
 @DocsEditable
 static void _requestPermission([_NotificationPermissionCallback callback]) native;

 @JSName('requestPermission')
 @DomName('Notification.requestPermission')
 @DocsEditable
 static Future<String> requestPermission() {
   var completer = new Completer<String>();
   _requestPermission(
       (value) { completer.complete(value); });
   return completer.future;
 }

 @DomName('Notification.show')
 @DocsEditable
 void show() native;

 @DomName('Notification.onclick')
 @DocsEditable
 Stream<Event> get onClick => clickEvent.forTarget(this);

 @DomName('Notification.onclose')
 @DocsEditable
 Stream<Event> get onClose => closeEvent.forTarget(this);

 @DomName('Notification.ondisplay')
 @DocsEditable
 Stream<Event> get onDisplay => displayEvent.forTarget(this);

 @DomName('Notification.onerror')
 @DocsEditable
 Stream<Event> get onError => errorEvent.forTarget(this);

 @DomName('Notification.onshow')
 @DocsEditable
 Stream<Event> get onShow => showEvent.forTarget(this);

}

Extends

Interceptor > EventTarget > Notification

Static Properties

const EventStreamProvider<Event> clickEvent #

static const EventStreamProvider<Event> clickEvent = const EventStreamProvider<Event>('click')

const EventStreamProvider<Event> closeEvent #

static const EventStreamProvider<Event> closeEvent = const EventStreamProvider<Event>('close')

const EventStreamProvider<Event> displayEvent #

static const EventStreamProvider<Event> displayEvent = const EventStreamProvider<Event>('display')

const EventStreamProvider<Event> errorEvent #

static const EventStreamProvider<Event> errorEvent = const EventStreamProvider<Event>('error')

const EventStreamProvider<Event> showEvent #

static const EventStreamProvider<Event> showEvent = const EventStreamProvider<Event>('show')

Static Methods

Future<String> requestPermission() #

@JSName('requestPermission')
@DomName('Notification.requestPermission')
@DocsEditable
static Future<String> requestPermission() {
 var completer = new Completer<String>();
 _requestPermission(
     (value) { completer.complete(value); });
 return completer.future;
}

Constructors

factory Notification(String title, {String titleDir: null, String body: null, String bodyDir: null, String tag: null, String iconUrl: null}) #

factory Notification(String title, {String titleDir: null, String body: null, 
   String bodyDir: null, String tag: null, String iconUrl: null}) {

 var parsedOptions = {};
 if (titleDir != null) parsedOptions['titleDir'] = titleDir;
 if (body != null) parsedOptions['body'] = body;
 if (bodyDir != null) parsedOptions['bodyDir'] = bodyDir;
 if (tag != null) parsedOptions['tag'] = tag;
 if (iconUrl != null) parsedOptions['iconUrl'] = iconUrl;

 return Notification._factoryNotification(title, parsedOptions);
}

Properties

String dir #

String dir

final int hashCode #

inherited from Interceptor

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

docs inherited from Object
int get hashCode => Primitives.objectHashCode(this);

final Events on #

inherited from EventTarget

This is an ease-of-use accessor for event streams which should only be used when an explicit accessor is not available.

Events get on => new Events(this);

final Stream<Event> onClick #

 A function to call when the notification is clicked.
@DomName('Notification.onclick')
@DocsEditable
Stream<Event> get onClick => clickEvent.forTarget(this);

final Stream<Event> onClose #

 A function to call when the notification is dismissed.
@DomName('Notification.onclose')
@DocsEditable
Stream<Event> get onClose => closeEvent.forTarget(this);

final Stream<Event> onDisplay #

@DomName('Notification.ondisplay')
@DocsEditable
Stream<Event> get onDisplay => displayEvent.forTarget(this);

final Stream<Event> onError #

@DomName('Notification.onerror')
@DocsEditable
Stream<Event> get onError => errorEvent.forTarget(this);

final Stream<Event> onShow #

@DomName('Notification.onshow')
@DocsEditable
Stream<Event> get onShow => showEvent.forTarget(this);

final String permission #

final String permission

String replaceId #

String replaceId

final Type runtimeType #

inherited from Interceptor

A representation of the runtime type of the object.

docs inherited from Object
Type get runtimeType => getRuntimeType(this);

String tag #

String tag

Operators

bool operator ==(other) #

inherited from Interceptor

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

docs inherited from Object
bool operator ==(other) => identical(this, other);

Methods

void cancel() #

@DomName('Notification.cancel')
@DocsEditable
void cancel() native;

void close() #

@DomName('Notification.close')
@DocsEditable
void close() native;

bool dispatchEvent(Event evt) #

@DomName('Notification.dispatchEvent')
@DocsEditable
bool dispatchEvent(Event evt) native;

dynamic noSuchMethod(Invocation invocation) #

inherited from Interceptor

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod in an Invocation. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

docs inherited from Object
dynamic noSuchMethod(Invocation invocation) {
 throw new NoSuchMethodError(
     this,
     _symbolToString(invocation.memberName),
     invocation.positionalArguments,
     _symbolMapToStringMap(invocation.namedArguments));
}

void show() #

Displays the notification.
@DomName('Notification.show')
@DocsEditable
void show() native;

String toString() #

inherited from Interceptor

Returns a string representation of this object.

docs inherited from Object
String toString() => Primitives.objectToString(this);

void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) #

@JSName('addEventListener')
@DomName('Notification.addEventListener')
@DocsEditable
void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) native;

void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) #

@JSName('removeEventListener')
@DomName('Notification.removeEventListener')
@DocsEditable
void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) native;

This page includes content from the Mozilla Foundation that is graciously licensed under a Creative Commons: Attribution-Sharealike license. Mozilla has no other association with Dart or dartlang.org. We encourage you to improve the web by contributing to The Mozilla Developer Network.