提交 be8429f8 authored 作者: MrQi's avatar MrQi

first submit

上级 f12b5b00
<!-- 组件通行或者全局通信的消息组件
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package. ## 使用
1、引入组件到```pubspec.yaml```文件中
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages). ```yaml
dependencies:
For general information about developing packages, see the Dart guide for flutter:
[creating packages](https://dart.dev/guides/libraries/create-library-packages) sdk: flutter
and the Flutter guide for clx_notification_center:
[developing packages and plugins](https://flutter.dev/developing-packages). git:
--> url: https://t.clxkj.cn/openSourceLibrary/clx_notification_center.git
```
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features 2、在需要使用的```Widget```中引入```clx_notification_center```组件
TODO: List what your package can do. Maybe include images, gifs, or videos. ```dart
import 'package:clx_notification_center/clx_notification_center.dart';
```
## Getting started 3、使用```defaultNotificationCenter```的几个方法
```dart
// 注册监听
defaultNotificationCenter.registerNotification(name: 'test', callback: (data) {
print('收到消息:$data');
});
TODO: List prerequisites and provide or point to information on how to // 发送消息
start using the package. defaultNotificationCenter.sendNotification(name: 'test', data: 'hello world');
## Usage // 移除监听
defaultNotificationCenter.removeNotification(name: 'test', callback: (data) {
print('收到消息:$data');
});
TODO: Include short and useful examples for package users. Add longer examples // 移除事件监听
to `/example` folder. defaultNotificationCenter.removeNotificationServer(name: 'test');
```dart // 移除所有监听
const like = 'sample'; defaultNotificationCenter.removeAllNotification();
``` ```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
...@@ -16,7 +16,7 @@ final class _CLXNotificationCenter { ...@@ -16,7 +16,7 @@ final class _CLXNotificationCenter {
final Set<CLXNotificationBody> _notificationItems = {}; final Set<CLXNotificationBody> _notificationItems = {};
/// 注册消息监听 /// 注册消息监听
void registerListener( void registerNotification(
{required String name, required CLXNotificationChannel callback}) { {required String name, required CLXNotificationChannel callback}) {
_notificationItems.firstWhere((element) => element.name.isEqual(name), _notificationItems.firstWhere((element) => element.name.isEqual(name),
orElse: () { orElse: () {
...@@ -28,15 +28,27 @@ final class _CLXNotificationCenter { ...@@ -28,15 +28,27 @@ final class _CLXNotificationCenter {
} }
/// 移除消息监听 /// 移除消息监听
void removeListener( void removeNotification(
{required String name, required CLXNotificationChannel callback}) { {required String name, required CLXNotificationChannel callback}) {
_notificationItems _notificationItems
.firstWhere((element) => element.name.isEqual(name)) .firstWhere((element) => element.name.isEqual(name))
.removeListen(callback); .removeListen(callback);
} }
/// 移除所有消息监听
void removeNotificationServer({required String name}) {
final notif =
_notificationItems.firstWhere((element) => element.name.isEqual(name));
_notificationItems.remove(notif);
}
/// 移除所有消息监听
void removeAllNotification() {
_notificationItems.clear();
}
/// 发送消息 /// 发送消息
Future<bool> postNotification( Future<bool> sendNotification(
{required String name, {required String name,
dynamic object, dynamic object,
Duration delay = Duration.zero}) async { Duration delay = Duration.zero}) async {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论