DART lang上的通知-Chrome打包的应用 [英] Notification at DART lang - Chrome Packaged App

查看:66
本文介绍了DART lang上的通知-Chrome打包的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在DART构建的Chrome打包应用中使用通知。

I want to use notification in Chrome Packaged app, built by DART.

我的pubspec.yaml是:

my pubspec.yaml is:

dependencies:
    browser: any
    chrome: any
transformers:
    - chrome

我的main.dart是:

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'));
....
}

它给了我一个问题:未定义class'NotificationOptions'

it gave me a problem: "Undefined class 'NotificationOptions'"

如果我在导入程序包的行中删除了 as chrome,则chrome.notifications.create(。 ..)尚未定义 chrome。

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.

我在这里犯了什么错误,以及为chrome通知定义选项的正确方法是什么!

what mistake I made here, and what is the correct way to define the options for chrome notifications!

推荐答案

如果在导入中使用作为chrome ,则必须在引用中添加对标识符的前缀此程序包带有 chrome

If you use as chrome in the import you have to prefix references to identifiers in this package with chrome.

这不是有效的Dart语法

This is not valid Dart syntax

 NotificationOptions notOptions = {
   'message':  'this is a notification message'

 };

也许应该是

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'));
  ....
}

manifiedt.json还应包含权限,例如:

also the manifiest.json should include permission, as:

  "permissions": ["notifications"],

这篇关于DART lang上的通知-Chrome打包的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆