An object that publishes data to named channels.
This is a compatibility abstraction carried over from the upstream
TypeScript implementation. Prefer exposing Dart Streams at public API
boundaries when designing new Dart-first APIs.
Subscribers can listen on a named channel and receive data published to that channel. The on method returns an UnsubscribeFn that can be called to stop receiving further messages.
final publisher = createDataPublisher();
final unsubscribe = publisher.on('data', (message) {
print('Got message: $message');
});
publisher.publish('data', 'hello');
unsubscribe(); // stop listening
- Implementers
- Available extensions
- Annotations
-
- @Deprecated('Use Stream<T>, StreamController<T>, or ChannelStreamController instead. ' 'This compatibility API will be removed in the next major version.')
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
on(
String channelName, Subscriber< Object?> subscriber) → UnsubscribeFn -
Subscribe to data on the given
channelName. -
stream<
T> (String channelName) → Stream< T> -
Available on DataPublisher, provided by the DataPublisherStreams extension
Returns a broadcast stream of values published tochannelName. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited