dart - DART lang上的通知-Chrome打包的应用

标签 dart google-chrome-app

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

我的pubspec.yaml是:

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

我的main.dart是:

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

它给了我一个问题:“未定义的类'NotificationOptions'”

如果我在导入包的行中删除了“as chrome”,那么我在chrome.notifications.create(...)处报错,直到未定义“chrome”。

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

最佳答案

如果在导入中使用as chrome,则必须在该包中以chrome前缀引用标识符。

这是无效的Dart语法

 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也应该包含许可,例如:

  "permissions": ["notifications"],

关于dart - DART lang上的通知-Chrome打包的应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25596250/

相关文章:

firebase - 无法安装 FlutterFire CLI

javascript - 如何以编程方式更改 Chrome 应用程序的标题栏颜色?

javascript - Chrome 应用启动 tcp 服务器

javascript - 从 Chrome 应用中的剪贴板获取当前文本

HTML5 <datalist> 在打包的应用程序中不起作用

flutter - 如何让多个图标转到不同的网址

ruby - Flutter pod 安装问题 - #<Dir :0x00007fa6f7e2ec80> 的未定义方法 `each_child'

android - 是日志 drom dart :developer are visible in release mode of flutter app?

flutter - 为什么有时上下文被替换为下划线或 "_"?

javascript - 检查是否安装了扩展,如果用户删除扩展则关闭选项卡