Signal<T> class
final
Something that happens, for whoever wants to hear it, with a value of
type T: final died = Signal<void>();, then died.emit() where
it happens, and on(health.died, (_) => score.value++) in the object
or behaviour that cares. Plain Dart: it needs no world, and works in
tests and in Flutter code too.
Listeners hear it at once, in emit, in the order they started listening. A listener added while it emits hears the next one; one cancelled while it emits, before its turn, doesn't hear this one.
Constructors
- Signal()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether anything listens, with listen,
onor stream.no setter -
next
→ Future<
T> -
The next value emitted. In a routine it's one of the routine's waits:
the code after it runs in the routines step (in the frame after the
one it started waiting in, at the earliest), it holds while the
routine is paused, and stopping the routine unwinds it from here,
through its
finallyblocks.race([died.next, wait(5)])waits for at most 5 seconds. Outside a routine it's a plain future that listens until the next emit; asked again before then, it's the same future, so asking each frame keeps one listener, not one a frame.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
stream
→ Stream<
T> -
The values emitted from now on, as a broadcast Stream, for code
outside the game such as a Flutter widget:
StreamBuilder(stream: game.over.stream, ...), orgame.over.stream.listen(...)to show a dialog. Unlike listen's handlers, which hear a value in emit, a stream's listeners hear it a moment later, as Dart's streams do.no setter
Methods
-
emit(
[T? value]) → void -
Tells every listener
value, one after the other. A listener added withonthat throws has its error go to World.errors, with its object, and the rest still hear it, as when an object's update throws. One added with listen that throws doesn't stop the rest either: once they have all heard it, this throws the first such error. -
listen(
void handler(T value)) → SignalSubscription< T> -
Calls
handlerwith each value emitted from now on, until the subscription is cancelled. In an object or behaviour, use itsoninstead, which ends by itself when it's destroyed. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited