launchWhenLifecycleStateDestroyed<T> method
Future<T>
launchWhenLifecycleStateDestroyed<
T>({ - bool runWithDelayed = false,
- Cancellable? cancellable,
- required FutureOr<T> block(
- Cancellable cancellable
),
})
Implementation
Future<T> launchWhenLifecycleStateDestroyed<T>(
{bool runWithDelayed = false,
Cancellable? cancellable,
required FutureOr<T> Function(Cancellable cancellable) block}) {
Completer<T> completer = Completer.sync();
addLifecycleObserver(LifecycleObserver.stateChange((state) {
if (state == LifecycleState.destroyed &&
!completer.isCompleted &&
cancellable?.isUnavailable != true) {
completer.complete(block(cancellable ?? Cancellable()));
}
}));
return completer.future;
}