onMount method

  1. @override
  2. @mustCallSuper
void onMount()

Called after the component has successfully run onLoad and before the component is added to its new parent.

Whenever onMount returns something, the parent will wait for the Future to be resolved before adding it. If null is returned, the class is added right away.

This can be overwritten to add custom logic to the component's mounting.

Example:

@override
void onMount() {
  position = parent!.size / 2;
}

Implementation

@override
@mustCallSuper
void onMount() {
  assert(
    sprite != null,
    'You have to set the sprite in either the constructor or in onLoad',
  );
}