MessagesModel class

A single model to consolidate all messages.

Messages can arrive from serial devices or UDP devices, and any device can be unexpectedly disconnected at any time. To simplify the logic of subscribing for new messages, this model holds a stream of WrappedMessages that anyone can subscribe to. When a message arrives, simply call addMessage to ensure it will be added to the stream.

Note that having this model forward stream to the serial and UDP streams would not work, as those streams can be closed when devices are disconnected, and new streams are created when devices are connected for the first time. In that case, anyone who subscribes to the stream before a device is connected (eg, in Model.init) won't get messages received afterwards. To get around this issue, this model uses the same StreamController the entire time.

Inheritance
  • Object
  • Model
  • MessagesModel

Constructors

MessagesModel()

Properties

hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
stream → Stream<WrappedMessage>
The stream of messages. Use WrappedMessageStream.onMessage to subscribe to messages.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
addMessage(WrappedMessage message) → void
Adds a message to the stream.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
init() → Future<void>
Initializes any data needed by this model.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
sendMessage(Message message, {bool checkVersion = true}) → void
Sends a command over the network or over Serial.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited