Skip to content

Latest commit

 

History

History
132 lines (96 loc) · 3.77 KB

README-ZH.md

File metadata and controls

132 lines (96 loc) · 3.77 KB

local_notifier

pub version

这个插件允许 Flutter 桌面 应用显示本地通知。


English | 简体中文


平台支持

Linux macOS Windows
✔️ ✔️ ✔️

截图

macOS Linux Windows
image

快速开始

安装

将此添加到你的软件包的 pubspec.yaml 文件:

dependencies:
  local_notifier: ^0.1.6

dependencies:
  local_notifier:
    git:
      url: https://github.com/leanflutter/local_notifier.git
      ref: main

Linux requirements

  • libnotify

运行以下命令

sudo apt-get install libnotify-dev

用法

// 在 main 方法中添加。
await localNotifier.setup(
  appName: 'local_notifier_example',
  // 参数 shortcutPolicy 仅适用于 Windows
  shortcutPolicy: ShortcutPolicy.requireCreate,
);

LocalNotification notification = LocalNotification(
  title: "local_notifier_example",
  body: "hello flutter!",
);
notification.onShow = () {
  print('onShow ${notification.identifier}');
};
notification.onClose = (closeReason) {
  // 只支持在windows,其他平台 closeReason 始终为 unknown。
  switch (closeReason) {
    case LocalNotificationCloseReason.userCanceled:
      // do something
      break;
    case LocalNotificationCloseReason.timedOut:
      // do something
      break;
    default:
  }
  print('onClose ${_exampleNotification?.identifier} - $closeReason');
};
notification.onClick = () {
  print('onClick ${notification.identifier}');
};
notification?.onClickAction = (actionIndex) {
  print('onClickAction ${notification?.identifier} - $actionIndex');
};

notification.show();

请看这个插件的示例应用,以了解完整的例子。

谁在用使用它?

相关链接

许可证

MIT