runBuild method

  1. @$mustCallSuper
  2. @override
WhenComplete? runBuild()
inherited

Executes Notifier.build.

This is called by Riverpod, and should not be called manually. The purpose of this method is to allow mixins to perform logic before/after the build method of a notifier.

For example, you could implement a mixin that logs state changes:

mixin LoggingMixin<T> on AnyNotifier<T> {
  @override
  void runBuild() {
    print('Will build $this');
    super.runBuild();
    print('Did build $this');
  }
}

The benefit of this method is that it applies on all notifiers, regardless of whether they use arguments or not.

Implementation

@$mustCallSuper
@override
WhenComplete runBuild() {
  final ref =
      this.ref
          as $Ref<AsyncValue<EntityListSnapshot<T>>, EntityListSnapshot<T>>;
  final element =
      ref.element
          as $ClassProviderElement<
            AnyNotifier<
              AsyncValue<EntityListSnapshot<T>>,
              EntityListSnapshot<T>
            >,
            AsyncValue<EntityListSnapshot<T>>,
            Object?,
            Object?
          >;
  return element.handleCreate(
    ref,
    () => build(
      type: _$args.type,
      queryKey: _$args.queryKey,
      fromGraph: _$args.fromGraph,
      toGraph: _$args.toGraph,
      query: _$args.query,
      completeness: _$args.completeness,
      enabled: _$args.enabled,
      subscribe: _$args.subscribe,
    ),
  );
}