subscribe method
Subscribes to changes in the beacon returns a function that can be called to unsubscribe
If startNow is true, the callback will be called immediately
with the current value of the beacon.
Implementation
VoidCallback subscribe(
void Function(T) callback, {
bool startNow = true,
}) {
assert(!_isDisposed, 'Cannot subscribe to a disposed beacon.');
if (_isDerived) {
final sub = DerivedSubscription<T>(
this as DerivedBeacon<T>,
callback,
startNow: startNow,
);
_observers.add(sub);
return sub.dispose;
}
final sub = Subscription<T>(
this,
callback,
startNow: startNow,
);
_observers.add(sub);
return sub.dispose;
}