搜尋套件、儲存庫與 APP 分類

套件詳情v3.2.0

flutter_notification_channel

一個用於在 Android 上設定通知頻道的外掛程式

AndroidiOS
近 30 天下載
3900
喜歡數
33
Pub 分數
120

安裝套件

flutter pub add flutter_notification_channel

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

flutter_notification_channel 套件讓開發者能夠輕鬆地在 Flutter 應用中設定與管理 Android 裝置的通知渠道。它提供一個簡單的 API,可建立、更新及自訂通知渠道,確保通知能依 Android 的通知渠道需求正確分類與顯示。此套件支援 Android 與 iOS 平台,但其主要功能聚焦於 Android 的渠道式通知系統。透過允許對通知行為(例如聲音、震動與重要性層級)進行細微控制,該套件有助於提升使用者體驗。

適用情境

  • 設定自訂通知通道
  • 管理通知重要性等級
  • 自訂通知聲音和震動
  • 確保符合 Android 8.0+ 通知要求
  • 透過有組織的通知改善使用者體驗

主要特色

  • 用於建立通知頻道的簡單 API
  • 支援 Android 8.0+ 通訊埠需求
  • 跨平台相容性(Android 與 iOS)
  • 可設定的頻道屬性,例如重要性和聲音
  • 與現有通知系統的輕鬆整合

適合對象

  • 需要結構化通知管理的應用程式
  • 面向 Android 8.0+ 設備的開發者
  • 需要可自定義通知行為的專案
  • 建構具有多種通知類型的 App 的團隊
  • 使用推播通知的Flutter應用

使用建議

  • 主要功能僅限於 Android
  • iOS 支援有限(無法建立頻道)
  • 需要手動處理平台特定的邏輯
  • 在較舊的 Android 版本上,基本通知不需要此功能
  • 最好與其他通知外掛程式搭配使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_notification_channel

https://pub.dev/packages/flutter_notification_channel

This plugin is made to register notification channels with custom configurations on Android. For more details read this https://developer.android.com/training/notify-user/channels Why is it necessary? E.g. firebase_messaging version 7.0.3 (current) and lower do not allow to set up a notification channel, thus notifications don't play any sounds or do not display on locked screen, or don't bubble and so on. This plugin is made merely for the purpose of creation a notification channel with custom configurations on Android. The channels then can be used along with firebase_messaging.

How to use

Simply call it like this

var result = await FlutterNotificationChannel().registerNotificationChannel(
    description: 'Your channel description',
    id: 'your_channel_id',
    importance: NotificationImportance.IMPORTANCE_HIGH,
    name: 'Your channel name',
    visibility: NotificationVisibility.VISIBILITY_PUBLIC,
    allowBubbles: true,
    enableVibration: true,
    enableSound: true,
    showBadge: true,
);
print(result);

Importance Levels

The plugin supports the following notification importance levels:

  • NotificationImportance.IMPORTANCE_MIN (1): Minimal importance, might not be shown
  • NotificationImportance.IMPORTANCE_LOW (2): Low importance, shows in shade and potentially status bar but not audibly intrusive
  • NotificationImportance.IMPORTANCE_DEFAULT (3): Default importance, shows everywhere and makes noise but doesn't visually intrude
  • NotificationImportance.IMPORTANCE_HIGH (4): Higher importance, shows everywhere, makes noise and peeks, may use full screen intents
  • NotificationImportance.IMPORTANCE_MAX (5): Maximum importance, most intrusive level, should be used sparingly for critical notifications only
Example with Maximum Importance

For critical notifications that require immediate user attention:

var result = await FlutterNotificationChannel().registerNotificationChannel(
    description: 'Critical system alerts',
    id: 'critical_channel_id',
    importance: NotificationImportance.IMPORTANCE_MAX,
    name: 'Critical Alerts',
    visibility: NotificationVisibility.VISIBILITY_PUBLIC,
    allowBubbles: true,
    enableVibration: true,
    enableSound: true,
    showBadge: true,
);

Then, when you send a message to firebase like this, specify your android_channel_id and sound: "default" in order to play a default sound if you set "enableSound" in plugin. If you don't do this, the sound wont play at all on android 9 (I have no idea why)

{
  "notification": {
    "title": "Your message title",
    "body": "Your message body",
    "android_channel_id": "your_channel_id",
    "sound": "default"
  },
  "data": {
    "click_action" : "FLUTTER_NOTIFICATION_CLICK",
  },
  "priority": "high",
  "content_available": true,
  "to": "YOUR_FIREBASE_PUSH_TOKEN_GOES_HERE"
}

所屬分類

依賴

依賴清單 1 項

  • plugin_platform_interface^2.1.8

原始碼儲存庫

使用此套件的專案

暫無相關資料。