问题
I want to use notification in Chrome Packaged app, built by DART.
my pubspec.yaml is:
dependencies:
browser: any
chrome: any
transformers:
- chrome
my main.dart is:
import 'dart:html';
import 'package:chrome/chrome_app.dart' as chrome;
void main() {
....
NotificationOptions notOptions = {
'message': 'this is a notification message'
};
chrome.notifications.create('id1', notOptions).then((id) => print('notification created'));
....
}
it gave me a problem: "Undefined class 'NotificationOptions'"
if I removed the "as chrome" in the line importing the package, then I'm getting an error at chrome.notifications.create(...) tilling that 'chrome' is undefined.
what mistake I made here, and what is the correct way to define the options for chrome notifications!
回答1:
If you use as chrome
in the import you have to prefix references to identifiers in this package with chrome
.
This is not valid Dart syntax
NotificationOptions notOptions = {
'message': 'this is a notification message'
};
maybe it should be something like
import 'dart:html';
import 'package:chrome/chrome_app.dart' as chrome;
void main() {
.....
chrome.NotificationOptions notOptions = new chrome.NotificationOptions(type: chrome.TemplateType.BASIC,
iconUrl:'/icon.png',title:'notification title', message: 'this is a notification message');
chrome.notifications.create('id1', notOptions).then((id) => print('notification created'));
....
}
also the manifiest.json should include permission, as:
"permissions": ["notifications"],
来源:https://stackoverflow.com/questions/25596250/notification-at-dart-lang-chrome-packaged-app