flutter_comms 1.0.0 copy "flutter_comms: ^1.0.0" to clipboard
flutter_comms: ^1.0.0 copied to clipboard

outdated

Simple communication pattern abstraction on streams, created for communication between blocs and or widgets.

flutter_comms #

codestyle

flutter_comms builds on top of comms, making it easier to implement comms pattern in Flutter projects.

For use in dart only projects, use comms.

Installation #

$ flutter pub add flutter_comms

Basic usage #

You can mix in Listener and Sender mixins to widgets but for more convenience helper widgets have been prepared.

MessageListener #

A MessageListener works exactly like Listener but calls listen and cancel functions for you, enabling it to receive messages from any Sendersharing the same message type.

MessageListener<MessageA>(
  onMessage: (message) {
    // handle received messages
  },
  onIntialMessage: (message) {
    // handle initial message
  },
  child: Widget(),
)

MultiMessageListener #

Merges multiple MessageListener widgets, improving the readability of nested MessageListeners.

MultiMessageListener(
  listeners: [
    MessageListener<MessageA>(
      onMessage: (message) {},
    ),
    MessageListener<MessageB>(
      onMessage: (message) {},
    ),
  ],
  child: Widget(),
)

useMessageListener #

useMessageListener hook calls onMessage everytime a message of type Message is received. Works similarly to Listener but handles starting message receiving and cleaning up itself.

This hook will receive messages only when HookWidget using it is built.

Widget build(BuildContext context) {
  useMessageListener<MessageA>(
    (message) {
      // handle received messages
    },
    onInitialMessage: (message) {
      // handle initial message
    }
  );
}
25
likes
0
points
500
downloads

Publisher

verified publisherleancode.co

Weekly Downloads

Simple communication pattern abstraction on streams, created for communication between blocs and or widgets.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

comms, flutter, flutter_hooks, logging, meta, nested

More

Packages that depend on flutter_comms