onBuild function

void onBuild(
  1. void callback(
    1. BuildContext
    )
)

Registers a callback to be called on every build.

The callback is called when the builder function executes, which happens on every reactive update.

This is useful for composables that need to react to BuildContext changes, such as TickerMode tracking.

Note: This is an internal API primarily used by composables like useSingleTickerProvider. Most users should not need to call this directly.

Must be called within the setup() method of CompositionWidget or CompositionBuilder.

Implementation

void onBuild(void Function(BuildContext) callback) {
  final context = getCurrentSetupContext();

  assert(
    context != null,
    'onBuild must be called within setup() of CompositionWidget or '
    'CompositionBuilder',
  );

  context?.addBuildCallback(callback);
}