提交 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.
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).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
组件通行或者全局通信的消息组件
## 使用
1、引入组件到```pubspec.yaml```文件中
```yaml
dependencies:
flutter:
sdk: flutter
clx_notification_center:
git:
url: https://t.clxkj.cn/openSourceLibrary/clx_notification_center.git
```
## 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 {
final Set<CLXNotificationBody> _notificationItems = {};
/// 注册消息监听
void registerListener(
void registerNotification(
{required String name, required CLXNotificationChannel callback}) {
_notificationItems.firstWhere((element) => element.name.isEqual(name),
orElse: () {
......@@ -28,15 +28,27 @@ final class _CLXNotificationCenter {
}
/// 移除消息监听
void removeListener(
void removeNotification(
{required String name, required CLXNotificationChannel callback}) {
_notificationItems
.firstWhere((element) => element.name.isEqual(name))
.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,
dynamic object,
Duration delay = Duration.zero}) async {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论