once<T> method

void once<T>(
  1. RxInterface<T> rx,
  2. void callback(
    1. T
    )
)

Calls callback only the first time rx changes, then cancels.

once(isLoggedIn, (val) => analytics.trackFirstLogin());

Implementation

void once<T>(RxInterface<T> rx, void Function(T) callback) {
  late StreamSubscription<T> sub;
  sub = rx.listen((val) {
    callback(val);
    sub.cancel();
    _workers.remove(sub);
  });
  _workers.add(sub);
}