搜索插件、代码仓与 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

源码仓库

使用此插件的项目

暂无相关数据。