Awesome Notifications for Flutter - 技术文档

Awesome Notifications for Flutter - 技术文档

awesome_notifications A complete solution to create Local Notifications and Push Notifications, throught Firebase or another services, using Flutter. awesome_notifications 项目地址: https://gitcode.com/gh_mirrors/aw/awesome_notifications

1. 安装指南

1.1 添加依赖

pubspec.yaml 文件中添加 awesome_notifications 依赖:

dependencies:
  flutter:
    sdk: flutter
  awesome_notifications: ^latest_version

1.2 安装依赖

运行以下命令安装依赖:

flutter pub get

1.3 配置平台

1.3.1 Android 配置

android/app/src/main/AndroidManifest.xml 文件中添加以下权限:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
1.3.2 iOS 配置

ios/Runner/Info.plist 文件中添加以下权限:

<key>UIBackgroundModes</key>
<array>
    <string>remote-notification</string>
</array>

2. 项目的使用说明

2.1 初始化

main.dart 文件中初始化 awesome_notifications

import 'package:awesome_notifications/awesome_notifications.dart';

void main() {
  AwesomeNotifications().initialize(
    'resource://drawable/res_app_icon', // 应用图标
    [
      NotificationChannel(
        channelKey: 'basic_channel',
        channelName: 'Basic notifications',
        channelDescription: 'Notification channel for basic tests',
      )
    ]
  );

  runApp(MyApp());
}

2.2 创建通知

使用 AwesomeNotifications 创建通知:

AwesomeNotifications().createNotification(
  content: NotificationContent(
    id: 10,
    channelKey: 'basic_channel',
    title: 'Simple Notification',
    body: 'This is a simple notification',
  )
);

2.3 处理通知事件

监听通知事件:

AwesomeNotifications().actionStream.listen((receivedNotification) {
  print('Notification received: $receivedNotification');
});

3. 项目API使用文档

3.1 初始化

AwesomeNotifications().initialize(
  String appIcon,
  List<NotificationChannel> channels,
);
  • appIcon: 应用图标路径。
  • channels: 通知通道列表。

3.2 创建通知

AwesomeNotifications().createNotification(
  NotificationContent content,
  NotificationSchedule schedule,
  List<NotificationActionButton> actionButtons,
);
  • content: 通知内容。
  • schedule: 通知调度。
  • actionButtons: 通知动作按钮。

3.3 监听通知事件

AwesomeNotifications().actionStream.listen((receivedNotification) {
  // 处理通知事件
});

4. 项目安装方式

4.1 通过 pub.dev 安装

pubspec.yaml 文件中添加依赖并运行 flutter pub get 命令。

4.2 手动安装

从 GitHub 下载项目源码,并将 awesome_notifications 文件夹复制到你的项目中。

git clone https://github.com/rafaelsetragni/awesome_notifications.git

4.3 更新依赖

运行以下命令更新依赖:

flutter pub upgrade

通过以上步骤,你可以成功安装并使用 awesome_notifications 插件,创建和管理自定义通知。

awesome_notifications A complete solution to create Local Notifications and Push Notifications, throught Firebase or another services, using Flutter. awesome_notifications 项目地址: https://gitcode.com/gh_mirrors/aw/awesome_notifications

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明洵柳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值