lifecycleEventsProcessed property
A future that will complete once all lifecycle events have been processed.
If there are no lifecycle events to be processed (hasLifecycleEvents
is false), then this future returns immediately.
This is useful when you modify the component tree (by adding, moving or removing a component) and you want to make sure you react to the changed state, not the current one. Remember, methods like Component.add don't act immediately and instead enqueue their action. They are synchronous and return nothing, so the action cannot be awaited directly. To wait for a specific component, await its Component.loaded, Component.mounted or Component.removed future; to wait for the whole queue to drain, await this future.
Don't await this from inside a component's Component.onLoad: that component's own mount is part of the queue, and it can only be processed after Component.onLoad has completed, so the wait would deadlock. Await the child's Component.loaded future there instead.
Example usage:
player.inventory.addAll(enemy.inventory.children);
await game.lifecycleEventsProcessed;
updateUi(player.inventory);
Implementation
Future<void> get lifecycleEventsProcessed {
return !hasLifecycleEvents ? Future.value() : _lifecycleEventsSignal.future;
}