Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx_notification_center
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx_notification_center
Commits
be8429f8
提交
be8429f8
authored
6月 16, 2025
作者:
MrQi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
first submit
上级
f12b5b00
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
34 行删除
+48
-34
README.md
README.md
+33
-31
clx_notification_center.dart
lib/notification_center/clx_notification_center.dart
+15
-3
没有找到文件。
README.md
浏览文件 @
be8429f8
<!--
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.
lib/notification_center/clx_notification_center.dart
浏览文件 @
be8429f8
...
...
@@ -16,7 +16,7 @@ final class _CLXNotificationCenter {
final
Set
<
CLXNotificationBody
>
_notificationItems
=
{};
/// 注册消息监听
void
register
Listener
(
void
register
Notification
(
{
required
String
name
,
required
CLXNotificationChannel
callback
})
{
_notificationItems
.
firstWhere
((
element
)
=>
element
.
name
.
isEqual
(
name
),
orElse:
()
{
...
...
@@ -28,15 +28,27 @@ final class _CLXNotificationCenter {
}
/// 移除消息监听
void
remove
Listener
(
void
remove
Notification
(
{
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
>
post
Notification
(
Future
<
bool
>
send
Notification
(
{
required
String
name
,
dynamic
object
,
Duration
delay
=
Duration
.
zero
})
async
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论