z_notification

Creator: coderz1093

Last updated:

0 purchases

z_notification Image
z_notification Images
Add to Cart

Description:

z notification

简介 #
一个用于 flutter 中进行数据通信和交互的通用的包。使用方法类似于 iOS 中的 NSNotificationCenter,使用方便,但是注意释放资源。
使用 #
使用步骤,同 iOS 中的通知消息:

添加观察器
发送通知
销毁时,释放观察器

NotificationCenter.instance.addObserver(object1, key: 'key1', callback: (message) {
print('message object1 = $message');
curMessage = message;
});

NotificationCenter.instance.addObserver(object2, key: 'key2', callback: (message) {
print('message object2 = $message');
curMessage = message;
});

NotificationCenter.instance.post(key: 'key1', data: 'post data1');
expect(curMessage, 'post data1');
NotificationCenter.instance.post(key: 'key2', data: 'post data2');
expect(curMessage, 'post data2');

NotificationCenter.instance.removeObserver(object1);
NotificationCenter.instance.post(key: 'key1', data: 'post data1');
expect(curMessage, 'post data2');

NotificationCenter.instance.post(key: 'key2', data: 'post data3');
expect(curMessage, 'post data3');
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.