callOnce function

void callOnce(
  1. void init(
    1. BuildContext context
    ), {
  2. void dispose()?,
})

If you want to execute a function only on the first built (even in in a StatelessWidget), you can use the callOnce function anywhere in your build function. It has an optional dispose handler which will be called when the widget is disposed.

Implementation

void callOnce(void Function(BuildContext context) init,
    {void Function()? dispose}) {
  assert(_activeWatchItState != null,
      'callOnce can only be called inside a build function within a WatchingWidget or a widget using the WatchItMixin');
  _activeWatchItState!.callOnce(init, dispose: dispose);
}