z_notification 0.0.5 copy "z_notification: ^0.0.5" to clipboard
z_notification: ^0.0.5 copied to clipboard

A general package for data communication and interaction in flutter. The method of use is similar to NSNotificationCenter in iOS. It is easy to use, but pay attention to releasing resources.

简介 #

一个用于 flutter 中进行数据通信和交互的通用的包。使用方法类似于 iOS 中的 NSNotificationCenter,使用方便,但是注意释放资源。

使用 #

使用步骤,同 iOS 中的通知消息:

  1. 添加观察器
  2. 发送通知
  3. 销毁时,释放观察器
    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');
0
likes
100
pub points
3%
popularity

Publisher

unverified uploader

A general package for data communication and interaction in flutter. The method of use is similar to NSNotificationCenter in iOS. It is easy to use, but pay attention to releasing resources.

Homepage

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

flutter, logging

More

Packages that depend on z_notification