lifecycleEventsProcessed property

Future<void> get lifecycleEventsProcessed
inherited

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. This action also cannot be awaited with something like await world.add(something) since that future completes before the lifecycle events are processed.

Example usage:

player.inventory.addAll(enemy.inventory.children);
await game.lifecycleEventsProcessed;
updateUi(player.inventory);

Implementation

Future<void> get lifecycleEventsProcessed {
  return !hasLifecycleEvents
      ? Future.value()
      : (_lifecycleEventsCompleter ??= Completer<void>()).future;
}